Exemple #1
0
func (m *MouseDebugger) Update() {
	if input.MouseDown(glfw.MouseLeft) {

		mousePosition := m.Transform().WorldPosition()

		sprite3 := engine.NewGameObject("Sprite")
		sprite3.AddComponent(engine.NewSprite(cir))
		sprite3.Transform().SetParent2(GameSceneGeneral.Layer2)
		sprite3.Transform().SetWorldPosition(mousePosition)

		sprite3.Transform().SetScale(engine.NewVector2(30, 30))

		phx := sprite3.AddComponent(engine.NewPhysicsShape(false, chipmunk.NewCircle(vect.Vect{0, 0}, 15))).(*engine.Physics)
		phx.Shape.SetFriction(0.5)
		//phx.Shape.Group = 1
		phx.Shape.SetElasticity(0.5)
	}
	if input.MouseDown(glfw.MouseRight) {

		mousePosition := m.Transform().WorldPosition()

		sprite3 := engine.NewGameObject("Sprite")
		sprite3.AddComponent(engine.NewSprite(box))
		sprite3.Transform().SetParent2(GameSceneGeneral.Layer2)
		sprite3.Transform().SetWorldPosition(mousePosition)

		sprite3.Transform().SetScale(engine.NewVector2(30, 30))
		phx := sprite3.AddComponent(engine.NewPhysics(false)).(*engine.Physics)
		phx.Shape.SetFriction(0.5)
		//phx.Shape.Group = 2
		phx.Shape.SetElasticity(0.5)
	}
}
Exemple #2
0
func (m *MouseDebugger) Update() {
	if input.MouseDown(input.MouseMiddle) {
		if queenDead {
			mousePosition := m.Transform().WorldPosition()

			c := cookie.Clone()
			//c.Tag = CookieTag
			c.Transform().SetParent2(GameSceneGeneral.Layer2)
			size := 25 + rand.Float32()*100
			c.Transform().SetPosition(mousePosition)
			c.Transform().SetScalef(size, size)
		}
	}
	if input.MouseDown(input.MouseRight) {

		mousePosition := m.Transform().WorldPosition()

		b := defender.Clone()
		/*
			phx := b.AddComponent(NewPhysics(false, 50, 50)).(*Physics)
			phx.Shape.SetFriction(0.5)
			//phx.Shape.Group = 2
			phx.Shape.SetElasticity(0.5)
		*/
		b.Transform().SetParent2(GameSceneGeneral.Layer2)
		b.Transform().SetWorldPosition(mousePosition)
		b.Transform().SetScalef(50, 50)

	}

	if input.KeyPress('R') {
		MyClient.SendRespawn()
	}

	if input.MouseWheelDelta != 0 && engine.Debug {
		engine.CurrentCamera().SetSize(engine.CurrentCamera().Size() + float32(-input.MouseWheelDelta))
	}

	if queenDead {
		if input.KeyPress(input.KeyF1) {
			PowerUpShip(HP)
		}
		if input.KeyPress(input.KeyF2) {
			PowerUpShip(Damage)
		}
		if input.KeyPress(input.KeyF3) {
			PowerUpShip(Range)
		}
		if input.KeyPress(input.KeyF4) {
			PowerUpShip(Speed)
		}
	}
}
Exemple #3
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)
	}
}