Exemplo n.º 1
0
func main() {
	rand.Seed(time.Now().UnixNano())

	a := app.Get()
	a.PushState(screen.Intro())
	a.Run()
}
Exemplo n.º 2
0
func (gs *game) Update(timeElapsed int64) {
	if gs.query.IsGameOver() {
		app.Get().PopState()
	}

	// Convenience maps for the directional keys.

	moveKeys := map[sdl.KeySym]image.Point{
		sdl.K_e: tile.HexDirs[0],
		sdl.K_r: tile.HexDirs[1],
		sdl.K_f: tile.HexDirs[2],
		sdl.K_d: tile.HexDirs[3],
		sdl.K_s: tile.HexDirs[4],
		sdl.K_w: tile.HexDirs[5]}

	shootKeys := map[sdl.KeySym]image.Point{
		sdl.K_i: tile.HexDirs[0],
		sdl.K_o: tile.HexDirs[1],
		sdl.K_l: tile.HexDirs[2],
		sdl.K_k: tile.HexDirs[3],
		sdl.K_j: tile.HexDirs[4],
		sdl.K_u: tile.HexDirs[5]}

	pc := gs.world.Player
	select {
	case evt := <-sdl.Events:
		switch e := evt.(type) {
		case sdl.KeyEvent:
			if e.KeyDown {
				if e.Sym == sdl.K_ESCAPE {
					app.Get().PopState()
					break
				}

				if dir, ok := moveKeys[e.FixedSym()]; ok {
					gs.action.AttackMove(pc, dir)
					gs.action.EndTurn()
					break
				}

				if dir, ok := shootKeys[e.FixedSym()]; ok {
					gs.action.Shoot(pc, dir)
					gs.action.EndTurn()
					break
				}

				// Layout independent keys
				switch e.FixedSym() {
				case sdl.K_SPACE:
					gs.action.EndTurn()
				case sdl.K_b:
					gs.fx.Blast(gs.query.Loc(pc), fx.SmallExplosion)
					gs.action.Damage(gs.world.Player, 1)
				case sdl.K_n:
					gs.fx.Blast(gs.query.Loc(pc), fx.LargeExplosion)
					gs.hud.Msg("Boom!")
				}
			}
		case sdl.QuitEvent:
			app.Get().Stop()
		}
	default:
	}
}