示例#1
0
文件: Game.go 项目: GGalizzi/rogo
//NewGame initializes a Game struct.
func NewGame() *Game {
	g := new(Game)
	g.Settings = readSettings()
	g.window = sf.NewRenderWindow(sf.VideoMode{uint(g.resW), uint(g.resH), 32}, "GoSFMLike", sf.StyleDefault, sf.DefaultContextSettings())
	g.state = PLAY

	g.area = NewArea()
	g.player = NewEntity("player", 0, 0, 3, 4, g.area)
	g.cursor = NewEntity("cursor", 0, 0, 2, 2, g.area)

	for i := 0; i < 3; i++ {
		g.mobs = append(g.mobs, NewEntityFromFile("orc", 3+i, 1, g.area))
		g.items = append(g.items, NewEntityFromFile("potion", 4, 4, g.area))
	}
	g.mobs = append(g.mobs, g.player)

	g.gameView = sf.NewView()
	g.gameView.SetCenter(g.player.PosVector())
	g.gameView.SetSize(sf.Vector2f{g.resW * 0.75, g.resH * 0.75})
	g.gameView.SetViewport(sf.FloatRect{0, 0, .75, .75})

	g.statusView = sf.NewView()
	g.statusView.SetSize(sf.Vector2f{g.resW * 0.25, g.resH})
	g.statusView.SetCenter(sf.Vector2f{(g.resW * 0.25) / 2, g.resH / 2})
	g.statusView.SetViewport(sf.FloatRect{.77, 0, .25, 1})

	g.hpText, _ = sf.NewText(Font)
	g.hpText.SetCharacterSize(12)

	g.logView = sf.NewView()

	var err error
	g.lookText, err = sf.NewText(Font)
	if err != nil {
		panic(err)
	}
	g.lookText.SetCharacterSize(12)

	g.logText, _ = sf.NewText(Font)
	g.logText.SetCharacterSize(12)

	return g
}
示例#2
0
func MockNewGame() *Game {
	g := new(Game)
	g.area = NewArea()
	g.player = NewEntity("player", 0, 0, 12, 12, g.area)
	g.cursor = NewEntity("cursor", 0, 0, 12, 12, g.area)
	g.gameView = sf.NewView()

	var err error
	g.lookText, err = sf.NewText(Font)
	if err != nil {
		panic(err)
	}
	return g
}