Beispiel #1
0
func (self *GameSession) drawPlaying() {
	self.Field.Draw(self.cx, self.cy)
	self.Figure.Draw(self.cx, self.cy)

	gl.Color3ub(255, 255, 255)
	self.font.Draw(self.cx+self.Field.PixelsWidth()+50, self.cy+5, "Next:")
	self.NextFigure.Draw(self.cx+self.Field.PixelsWidth(), self.cy+50)
}
Beispiel #2
0
func drawBlock(x, y int, color TetrisBlockColor) {
	glx := gl.GLint(x)
	gly := gl.GLint(y)

	gl.Color3ub(color.R/2, color.G/2, color.B/2)
	gl.Begin(gl.QUADS)
	gl.Vertex2i(int(glx), int(gly))
	gl.Vertex2i(int(glx+blockSize), int(gly))
	gl.Vertex2i(int(glx+blockSize), int(gly+blockSize))
	gl.Vertex2i(int(glx), int(gly+blockSize))
	gl.Color3ub(color.R, color.G, color.B)
	gl.Vertex2i(int(glx+smallBlockOffset), int(gly+smallBlockOffset))
	gl.Vertex2i(int(glx+blockSize-smallBlockOffset), int(gly+smallBlockOffset))
	gl.Vertex2i(int(glx+blockSize-smallBlockOffset), int(gly+blockSize-smallBlockOffset))
	gl.Vertex2i(int(glx+smallBlockOffset), int(gly+blockSize-smallBlockOffset))
	gl.End()
}
Beispiel #3
0
func drawSelection(p1, p2 Point) {
	min, max := minMaxPoints(p1, p2)

	gl.Color3ub(255, 0, 0)
	gl.Begin(gl.LINES)
	gl.Vertex2i(int(min.X), int(min.Y))
	gl.Vertex2i(int(max.X), int(min.Y))

	gl.Vertex2i(int(min.X), int(min.Y))
	gl.Vertex2i(int(min.X), int(max.Y))

	gl.Vertex2i(int(max.X), int(max.Y))
	gl.Vertex2i(int(max.X), int(min.Y))

	gl.Vertex2i(int(max.X), int(max.Y))
	gl.Vertex2i(int(min.X), int(max.Y))
	gl.End()
	gl.Color3ub(255, 255, 255)
}
Beispiel #4
0
func drawProgress(w, h, percents, pending int) {
	switch pending {
	case None:
		gl.Color3ub(200, 0, 0)
		drawQuad(0, h-BarSize, w, BarSize, 0, 0, 1, 1)
		gl.Color3ub(255, 255, 255)
		return
	case Small:
		gl.Color3ub(200, 200, 0)
	case Big:
		gl.Color3ub(200, 200, 0)
		drawQuad(0, h-BarSize, w, BarSize, 0, 0, 1, 1)
		gl.Color3ub(200, 0, 0)
	}
	step := float32(w) / 100
	drawQuad(0, h-BarSize, int(float32(percents)*step), BarSize, 0, 0, 1, 1)
	gl.Color3ub(255, 255, 255)
}
Beispiel #5
0
func main() {
	runtime.LockOSThread()
	flag.Parse()
	sdl.Init(sdl.INIT_VIDEO)
	defer sdl.Quit()

	sdl.GL_SetAttribute(sdl.GL_SWAP_CONTROL, 1)

	if sdl.SetVideoMode(640, 480, 32, sdl.OPENGL) == nil {
		panic("sdl error")
	}

	sdl.WM_SetCaption("Gotris", "Gotris")
	sdl.EnableKeyRepeat(250, 45)

	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Viewport(0, 0, 640, 480)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, 640, 480, 0, -1, 1)

	gl.ClearColor(0, 0, 0, 0)

	//-----------------------------------------------------------------------------

	font, err := LoadFontFromFile("dejavu.font")
	if err != nil {
		panic(err)
	}

	rand.Seed(int64(sdl.GetTicks()))

	gs := NewGameSession(*initLevel, font)
	lastTime := sdl.GetTicks()

	running := true
	for running {
		for ev := sdl.PollEvent(); ev != nil; ev = sdl.PollEvent() {
			switch e := ev.(type) {
			case *sdl.QuitEvent:
				running = false
			case *sdl.KeyboardEvent:
				if e.Type == sdl.KEYDOWN {
					running = gs.HandleKey(e.Keysym.Sym)
				}
			}
		}

		now := sdl.GetTicks()
		delta := now - lastTime
		lastTime = now

		gs.Update(delta)

		gl.Clear(gl.COLOR_BUFFER_BIT)
		font.Draw(5, 5, fmt.Sprintf("Level: %d | Score: %d", gs.Level, gs.Score))
		gs.Draw()
		gl.Color3ub(255, 255, 255)
		sdl.GL_SwapBuffers()
	}
}
Beispiel #6
0
func (self *GameSession) drawGamePaused() {
	self.drawPlaying()
	gl.Color3ub(200, 200, 0)
	self.font.Draw(self.pauseCx, 5, "Game paused, press P to resume")
}
Beispiel #7
0
func (self *GameSession) drawGameOver() {
	self.drawPlaying()
	gl.Color3ub(200, 0, 0)
	self.font.Draw(self.gameOverCx, 5, "Game Over, restart? y/n")
}