コード例 #1
0
ファイル: UIText.go プロジェクト: gulinfang/GarageEngine
func (ui *UIText) Update() {
	ui.UpdateCollider()

	/*
		s := ui.Transform().Scale()

		if s.X < 20 && speed < 0 {
			speed = -speed
		} else if s.X > 200 && speed > 0 {
			speed = -speed
		}

		s.X += speed * engine.DeltaTime()
		s.Y += speed * engine.DeltaTime()

		ui.Transform().SetScale(s)
	*/

	//Handle Tab & Backspace
	if ui.focused && ui.writeable {
		if len(ui.text) > 0 && input.KeyPress(input.KeyBackspace) {
			ui.updateText = true
			ui.text = ui.text[:len(ui.text)-1]
		}
		if input.KeyPress(input.KeyTab) {
			ui.updateText = true
			ui.text += "\t"
		}
	}
}
コード例 #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)
		}
	}
}
コード例 #3
0
ファイル: TestTextBox.go プロジェクト: banad/PirateLand
func (s *TestTextBox) Update() {
	if input.KeyPress(input.KeyF2) {
		s.able = !s.able
		s.SetFocus(s.able)
		s.SetWritable(s.able)
	}
	if s.able && input.KeyPress(input.KeyEnter) {
		s.V, _ = strconv.ParseFloat(s.String(), 64)
		s.Do(s)
	}

	s.UIText.Update()
}
コード例 #4
0
ファイル: main.go プロジェクト: gulinfang/GarageEngine
func Start() {
	defer func() {
		if p := recover(); p != nil {
			fmt.Println(p, engine.PanicPath())
		}

		engine.Terminate()
	}()
	engine.StartEngine()
	_ = game.GameSceneGeneral
	_ = networkOnline.GameSceneGeneral
	_ = login.LoginSceneGeneral
	_ = zumbies.GameSceneGeneral

	/*
		Running local server.
	*/
	go server.StartServer()

	scene := 0

	engine.LoadScene(login.LoginSceneGeneral)
	for engine.MainLoop() {
		if input.KeyPress('`') {
			scene = (scene + 1) % 3
			switch scene {
			case 0:
				engine.LoadScene(login.LoginSceneGeneral)
			case 1:
				engine.LoadScene(networkOnline.GameSceneGeneral)
			case 2:
				engine.LoadScene(zumbies.GameSceneGeneral)
			}

		}
	}
}
コード例 #5
0
ファイル: Map.go プロジェクト: gulinfang/GarageEngine
func (m *Map) Update() {
	if input.KeyPress('X') {
		m.EnableDisco = !m.EnableDisco
	}
}
コード例 #6
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)
	}
}
コード例 #7
0
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--
		}
	}
}
コード例 #8
0
ファイル: player.go プロジェクト: banad/PirateLand
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")
	}
}