예제 #1
0
파일: level.go 프로젝트: kissthink/bampf
// newLevel creates the indicated game level.
func newLevel(g *game, levelNum int) *level {
	var levelType = map[int]grid.Grid{
		0: grid.New(grid.DENSE_SKIRMISH),
		1: grid.New(grid.DENSE_SKIRMISH),
		2: grid.New(grid.SPARSE_SKIRMISH),
		3: grid.New(grid.ROOMS_SKIRMISH),
		4: grid.New(grid.ROOMS_SKIRMISH),
	}

	// initialize the scenes.
	lvl := &level{}
	lvl.fade = g.vr * 0.7
	lvl.units = 2
	lvl.colour = 1.0
	lvl.fov = 75
	lvl.root = g.mp.eng.Root().NewPov()
	lvl.view = lvl.root.NewView()
	lvl.view.SetCull(vu.NewFrontCull(g.vr))
	lvl.cam = lvl.view.Cam()
	lvl.cam.SetPerspective(lvl.fov, float64(g.ww)/float64(g.wh), 0.1, 50)

	// save everything as one game stage.
	lvl.mp = g.mp
	lvl.num = levelNum

	// create hud before player since player is drawn within hd.scene.
	s := g.mp.eng.State()
	lvl.hd = newHud(g.mp.eng, gameMuster[lvl.num], s.X, s.Y, s.W, s.H)
	lvl.player = lvl.makePlayer(lvl.hd.root, lvl.num+1)
	lvl.makeSentries(lvl.root, lvl.num)

	// create one large floor.
	lvl.floor = lvl.root.NewPov().SetLocation(0, 0.2, 0)

	// create a new layout for the stage.
	plan := levelType[lvl.num]
	levelSize := gameMapSize(lvl.num)
	plan.Generate(levelSize, levelSize)

	// build and populate the floorplan
	lvl.walls = []vu.Pov{}
	lvl.cc = newCoreControl(lvl.units, g.mp.ani)
	lvl.buildFloorPlan(lvl.root, lvl.hd, plan)
	lvl.plan = plan

	// set the intial player location.
	lvl.body = lvl.root.NewPov().SetLocation(4, 0.5, 10)

	// start sentinels at the center of the stage.
	for _, sentry := range lvl.sentries {
		sentry.setGridLocation(lvl.gcx, lvl.gcy)
	}
	lvl.player.resetEnergy()
	lvl.setVisible(false)
	return lvl
}
예제 #2
0
파일: rl.go 프로젝트: skyview059/vu
// setLevel switches to the indicated level.
func (rl *rltag) setLevel(eng vu.Eng, keyCode int) {
	if _, ok := rl.floors[keyCode]; !ok {
		var gridSizes = map[int]int{
			vu.K_1: 15,
			vu.K_2: 21,
			vu.K_3: 27,
			vu.K_4: 33,
			vu.K_5: 39,
			vu.K_6: 45,
			vu.K_7: 51,
			vu.K_8: 57,
			vu.K_9: 63,
			vu.K_0: 69,
		}
		var gridType = map[int]grid.Grid{
			vu.K_1: grid.New(grid.DENSE_SKIRMISH),
			vu.K_2: grid.New(grid.DENSE_SKIRMISH),
			vu.K_3: grid.New(grid.SPARSE_SKIRMISH),
			vu.K_4: grid.New(grid.SPARSE_SKIRMISH),
			vu.K_5: grid.New(grid.ROOMS_SKIRMISH),
			vu.K_6: grid.New(grid.ROOMS_SKIRMISH),
			vu.K_7: grid.New(grid.CAVE),
			vu.K_8: grid.New(grid.CAVE),
			vu.K_9: grid.New(grid.DUNGEON),
			vu.K_0: grid.New(grid.DUNGEON),
		}
		flr := &floor{}

		// create the scene
		flr.top = eng.Root().NewPov()
		flr.plan = flr.top.NewPov()
		flr.cam = flr.plan.NewCam()
		flr.cam.SetLocation(1, 0, -1)
		flr.cam.SetPerspective(60, float64(rl.ww)/float64(rl.wh), 0.1, 50)
		flr.cam.SetCull(vu.NewFrontCull(10))

		// create the overlay
		flr.mmap = flr.top.NewPov()
		flr.ui = flr.mmap.NewCam()
		flr.ui.SetUI()
		flr.ui.SetView(vu.XZ_XY)
		flr.ui.SetOrthographic(0, float64(rl.ww), 0, float64(rl.wh), 0, 20)
		flr.mapPart = flr.mmap.NewPov()
		flr.mapPart.SetScale(7.5, 7.5, 7.5)
		flr.mapPart.SetLocation(20, 0, -20)

		// display some rendering statistics.
		flr.modelStats = rl.newText(flr.mmap, 0)
		flr.vertexStats = rl.newText(flr.mmap, 1)
		flr.times = rl.newText(flr.mmap, 2)

		// populate the scenes
		lsize := gridSizes[keyCode]
		flr.layout = gridType[keyCode]
		flr.layout.Generate(lsize, lsize)
		width, height := flr.layout.Size()
		for x := 0; x < width; x++ {
			for y := 0; y < height; y++ {
				if flr.layout.IsOpen(x, y) {
					block := flr.mapPart.NewPov().SetLocation(float64(x), 0, float64(-y))
					block.NewModel("alpha").LoadMesh("cube").LoadMat("transparent_gray")
				} else {
					block := flr.plan.NewPov().SetLocation(float64(x), 0, float64(-y))
					block.NewModel("uv").LoadMesh("box").AddTex("tile")
				}
			}
		}
		flr.arrow = flr.mapPart.NewPov().SetLocation(flr.cam.Location())
		flr.arrow.NewModel("solid").LoadMesh("arrow").LoadMat("transparent_blue")
		rl.floors[keyCode] = flr
	}
	if rl.flr != nil {
		rl.flr.plan.SetVisible(false)
		rl.flr.mmap.SetVisible(false)
	}
	rl.flr = rl.floors[keyCode]
	rl.flr.plan.SetVisible(true)
	rl.flr.mmap.SetVisible(true)
	rl.arrow = rl.flr.arrow
}