Example #1
0
func (sp *CameraController) Update() {
	t := sp.GameObject().Transform()

	if input.KeyDown('A') {
		t.Translatef(float32(-sp.Speed*engine.DeltaTime()), 0)
	}
	if input.KeyDown('D') {
		t.Translatef(float32(sp.Speed*engine.DeltaTime()), 0)
	}
	if input.KeyDown('S') {
		t.Translatef(0, float32(-sp.Speed*engine.DeltaTime()))
	}
	if input.KeyDown('W') {
		t.Translatef(0, float32(sp.Speed*engine.DeltaTime()))
	}
	if input.KeyDown('E') {
		engine.CurrentCamera().SetSize(engine.CurrentCamera().Size() + float32(engine.DeltaTime()))
	}
	if input.KeyDown('Q') {
		engine.CurrentCamera().SetSize(engine.CurrentCamera().Size() - float32(engine.DeltaTime()))
	}

	if input.KeyDown('Z') {
		a := t.Angle()
		t.SetWorldRotationf(a + float32(engine.DeltaTime())*10)
	}
	if input.KeyDown('X') {
		a := t.Angle()
		t.SetWorldRotationf(a - float32(engine.DeltaTime())*10)
	}
}
Example #2
0
func (c *Chest) Update() {
	if !c.done && c.playerIn && input.KeyDown('E') {
		c.done = true
		switch c.priceType {
		case Type_money:
			Player.PlComp.AddMoney(rand.Int()%1000 + 1)
			c.GameObject().Sprite.AnimationSpeed = 5

			c.GameObject().Sprite.AnimationEndCallback = func(sprite *engine.Sprite) {
				c.GameObject().Destroy()
			}
		case Type_prices:
			r := rand.Int()%6 + 2
			for i := 0; i < r; i++ {
				it := RandomItem().Clone()

				it.Transform().SetPosition(c.Transform().Position())
				it.Transform().SetParent(c.Transform().Parent())
				it.ComponentTypeOfi((*Item).TypeOf(nil)).(*Item).Pop()
			}
			c.GameObject().Sprite.AnimationSpeed = 5
			c.GameObject().Sprite.AnimationEndCallback = func(sprite *engine.Sprite) {
				c.GameObject().Destroy()
			}
		default:
			c.done = false
		}

	}

}
func (this *PlayerController) FixedUpdate() {
	this.GameObject().Physics.Shape.Layer = chipmunk.Layer(this.Player.Map.Layer)
	t := this.JointGameObject.Transform()

	var move engine.Vector = this.Transform().WorldPosition()

	if input.KeyDown('W') {
		move.Y += 100
	}
	if input.KeyDown('S') {
		move.Y += -100
	}
	if input.KeyDown('A') {
		move.X += -100
	}
	if input.KeyDown('D') {
		move.X += 100
	}

	t.SetWorldPosition(move)
}
Example #4
0
func (sp *ShipController) Update() {
	delta := float32(engine.DeltaTime())
	r2 := sp.Transform().DirectionTransform(engine.Up)
	r3 := sp.Transform().DirectionTransform(engine.Left)
	ph := sp.GameObject().Physics
	rx, ry := r2.X*delta, r2.Y*delta
	rsx, rsy := r3.X*delta, r3.Y*delta

	jet := false
	back := false

	if input.KeyDown('W') {
		ph.Body.AddForce(sp.Speed*rx, sp.Speed*ry)
		jet = true
	}

	if input.KeyDown('S') {
		ph.Body.AddForce(-sp.Speed*rx, -sp.Speed*ry)
		jet = true
		back = true
	}

	rotSpeed := sp.RotationSpeed
	if input.KeyDown(input.KeyLshift) {
		rotSpeed = 100
	}

	if sp.UseMouse {
		v := engine.GetScene().SceneBase().Camera.MouseWorldPosition()
		v = v.Sub(sp.Transform().WorldPosition())
		v.Normalize()
		angle := float32(math.Atan2(float64(v.Y), float64(v.X))) * engine.DegreeConst

		angle = engine.LerpAngle(sp.Transform().Rotation().Z, float32(int((angle - 90))), delta*rotSpeed/50)
		sp.Transform().SetRotationf(angle)

		ph.Body.SetAngularVelocity(0)
		ph.Body.SetTorque(0)

		if input.KeyDown('D') || input.KeyDown('E') {
			ph.Body.SetAngularVelocity(0)
			ph.Body.SetTorque(0)
			ph.Body.AddForce(-sp.Speed*rsx, -sp.Speed*rsy)
			jet = true
			back = true
		}
		if input.KeyDown('A') || input.KeyDown('Q') {
			ph.Body.SetAngularVelocity(0)
			ph.Body.SetTorque(0)
			ph.Body.AddForce(sp.Speed*rsx, sp.Speed*rsy)
			jet = true
			back = true
		}
	} else {
		r := sp.Transform().Rotation()
		if input.KeyDown('D') {
			ph.Body.SetAngularVelocity(0)
			ph.Body.SetTorque(0)
			sp.Transform().SetRotationf(r.Z - rotSpeed*delta)
			jet = true
			back = true
		}
		if input.KeyDown('A') {
			ph.Body.SetAngularVelocity(0)
			ph.Body.SetTorque(0)
			sp.Transform().SetRotationf(r.Z + rotSpeed*delta)
			jet = true
			back = true
		}

		if input.KeyDown('E') {
			ph.Body.SetAngularVelocity(0)
			ph.Body.SetTorque(0)
			ph.Body.AddForce(-sp.Speed*rsx, -sp.Speed*rsy)
			jet = true
			back = true
		}
		if input.KeyDown('Q') {
			ph.Body.SetAngularVelocity(0)
			ph.Body.SetTorque(0)
			ph.Body.AddForce(sp.Speed*rsx, sp.Speed*rsy)
			jet = true
			back = true
		}
	}

	if input.MouseDown(input.MouseLeft) {
		if time.Now().After(sp.lastShoot) {
			sp.Shoot()
			sp.lastShoot = time.Now().Add(time.Millisecond * 200)
		}
	}

	if input.KeyPress('P') {
		engine.EnablePhysics = !engine.EnablePhysics
	}
	if input.KeyPress('T') {
		sp.UseMouse = !sp.UseMouse
	}

	if jet {
		for _, resize := range sp.JetFirePool {
			if back {
				resize.SetValues(0.1, 0.1, 0.2, 0.0, 0.2, 0.3)
			} else {
				resize.SetValues(0.2, 0.2, 0.3, 0.0, 0.6, 0.8)
			}
		}
		if !sp.JetFireParent.IsActive() {
			sp.JetFireParent.SetActive(true)
			for _, resize := range sp.JetFirePool {
				resize.State = 0
				if back {
					resize.SetValues(0.1, 0.1, 0.2, 0.0, 0.2, 0.3)
				} else {
					resize.SetValues(0.2, 0.2, 0.3, 0.0, 0.6, 0.8)
				}
			}
		}
	} else {
		sp.JetFireParent.SetActive(false)
	}
}
func (sp *PlayerController) Update() {
	if input.KeyPress(glfw.KeyUp) {
		if sp.Floor != nil {
			sp.Physics.Body.AddForce(0, sp.JumpSpeed)
		} else {
			sp.Shoot()
		}
	}

	tState := 0

	if input.KeyDown(glfw.KeyLeft) {
		sp.Physics.Body.AddVelocity(-sp.Speed, 0)
		if sp.state != 1 {
			sp.GameObject().Sprite.SetAnimation("walk")
		}
		s := sp.Transform().Rotation()
		s.Y = 180
		sp.Transform().SetRotation(s)
		sp.state = 1
		tState = 1
		//sp.Physics.Shape.Friction = 0
	}
	if input.KeyDown(glfw.KeyRight) {
		sp.Physics.Body.AddVelocity(sp.Speed, 0)
		if sp.state != 1 {
			sp.GameObject().Sprite.SetAnimation("walk")
		}
		s := sp.Transform().Rotation()
		s.Y = 0
		sp.Transform().SetRotation(s)
		sp.state = 1
		tState = 1
		//sp.Physics.Shape.Friction = 0
	}

	if input.KeyPress(glfw.KeySpace) {
		sp.Shoot()
	}

	if input.KeyPress('P') {

		engine.EnablePhysics = !engine.EnablePhysics
	}

	if tState != 1 {
		if sp.state != 0 {
			sp.GameObject().Sprite.SetAnimation("stand")
		}
		//sp.Physics.Shape.Friction = 0.5
		sp.state = 0
	}

	v := sp.Physics.Body.Velocity()

	if v.X > 200 {
		sp.Physics.Body.SetVelocity(200, float32(v.Y))
	} else if v.X < -200 {
		sp.Physics.Body.SetVelocity(-200, float32(v.Y))
	}

	for i := 0; i < len(sp.Fires); i++ {
		fire := sp.Fires[i]
		if fire.Transform().Rotation().Z <= -80 && fire.Physics.Body.Velocity().X >= -1 {
			fire.Destroy()
			sp.Fires = append(sp.Fires[:i], sp.Fires[i+1:]...)
			i--
		} else if fire.Transform().Rotation().Z >= 80 && fire.Physics.Body.Velocity().X <= 1 {
			fire.Destroy()
			sp.Fires = append(sp.Fires[:i], sp.Fires[i+1:]...)
			i--
		}
	}
}
Example #6
0
func (pl *Player) Update() {
	//Test
	if pl.OnGround == false {
		pl.frames++
	} else {
		pl.frames = 0
	}
	// if input.KeyPress(input.KeyEsc) {
	// 	engine.LoadScene(MenuSceneG)
	// }
	if input.KeyDown(input.KeyEsc) {
		pl.MenuScene()
	}
	ph := pl.GameObject().Physics.Body
	pl.GameObject().Sprite.SetAlign(engine.AlignTopCenter)
	if float32(math.Abs(float64(ph.Velocity().X))) > 3 {
		if pl.GameObject().Sprite.CurrentAnimation() == "player_stand" {
			pl.GameObject().Sprite.SetAnimation("player_walk")
		}
	} else if !pl.Attack && pl.pLader == nil {
		pl.GameObject().Sprite.SetAnimation("player_stand")
	}
	if pl.able {
		if input.KeyDown(input.Key_Right) {
			ph.AddForce(pl.speed, 0)
			pl.right = 1
			pl.GameObject().Transform().SetScalef(pl.width, pl.height)

		} else if input.KeyDown(input.Key_Left) {
			ph.AddForce(-pl.speed, 0)
			pl.right = -1
			pl.GameObject().Transform().SetScalef(-pl.width, pl.height)
		}
		if input.KeyPress(input.KeyLctrl) {
			pl.Attack = true

			pl.GameObject().Sprite.SetAnimation("player_attack")
			pl.GameObject().Sprite.AnimationEndCallback = func(sprite *engine.Sprite) {
				pl.Attack = false
				pl.GameObject().Sprite.SetAnimation("player_stand")
			}

		}
		if input.KeyPress(input.Key_Up) && pl.OnGround {
			pl.GameObject().Physics.Body.AddForce(0, pl.jumpPower)
			pl.OnGround = false
		}
		if input.KeyDown(input.Key_Up) {
			if pl.pLader != nil {
				ph.AddVelocity(0, 1)
			}
		}
		if input.KeyUp(input.Key_Down) {
			if pl.GameObject().Sprite.CurrentAnimation() == "player_bend" {
				pl.GameObject().Sprite.SetAnimation("player_stand")
			}
			pl.GameObject().Physics.Shape.SetFriction(0.7)
			pl.height = stand_height
			pl.GameObject().Transform().SetScalef(pl.width*pl.right, stand_height)

		} else if input.KeyDown(input.Key_Down) {
			if pl.pLader != nil {
				ph.AddVelocity(0, -1)
			} else {
				pl.GameObject().Sprite.SetAnimation("player_bend")
				pl.GameObject().Physics.Shape.SetFriction(1.2)
				pl.height = bend_height
				pl.GameObject().Transform().SetScalef(pl.width*pl.right, bend_height)
			}
		}
	}

	if pl.hit {
		pl.GameObject().Sprite.SetAnimation("player_hit")
	}
	if (pl.GameObject().Sprite.CurrentAnimation() == "player_stand" || pl.GameObject().Sprite.CurrentAnimation() == "player_walk") && !pl.OnGround && pl.frames > 15 {
		pl.GameObject().Sprite.SetAnimation("player_jump")
	}
	if pl.GameObject().Sprite.CurrentAnimation() != "player_climb" && pl.pLader != nil {
		pl.GameObject().Sprite.SetAnimation("player_climb")
	}
}