Exemple #1
0
func PlayState(g *game.Game) (State, *game.Game) {
	mc := g.Spawn()
loop:
	for {
		ui.Clear()
		for i := range g.Players.Players {
			if plyr := &g.Players.Players[i]; plyr.Alive {
				plyr.Update()
				ui.DrawRune(int(plyr.Pos.X), int(plyr.Pos.Y), '#')
				//ui.SetCell(int(plyr.Pos.X), int(plyr.Pos.Y), '#')
			}
		}
		ui.PrintSliceAtBottom(g.Read(8))
		ui.Update()
		switch ev := ui.GetEvent(); ev.Key {
		case ui.ESC:
			break loop
		case ui.UP:
			mc.SetVel(engine.Vec(0.0, -1.0))
		case ui.DOWN:
			mc.SetVel(engine.Vec(0.0, 1.0))
		case ui.LEFT:
			mc.SetVel(engine.Vec(-1.0, 0))
		case ui.RIGHT:
			mc.SetVel(engine.Vec(1.0, 0))
		}
	}
	return MenuState, g
}
Exemple #2
0
func (g *Game) Spawn() *Player {
	x, y := float32(rand.Intn(16)), float32(rand.Intn(16))
	plyr, err := g.Players.Spawn(engine.Vec(x, y), engine.Vec(0.2, 0.2), 0.5)
	if err != nil {
		g.Write("%s", err)
		return nil
	}
	g.Write("new spawn at %f, %f", x, y)
	return plyr
}