Initial commit
This commit is contained in:
commit
0245a5cb43
22 changed files with 610 additions and 0 deletions
47
game/draw/grid/grid.go
Normal file
47
game/draw/grid/grid.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package grid
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
|
||||
"tetris/engine/render"
|
||||
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
// How many pixels wide and tall each cell is.
|
||||
CELL_SIZE = 32
|
||||
|
||||
// Number of pixels between each cell
|
||||
CELL_SPACING = 1
|
||||
)
|
||||
|
||||
func DrawBackground(rect rl.RectangleInt32, col color.RGBA, border_size int32, border_col color.RGBA) {
|
||||
render.DrawRectBorder(rl.RectangleInt32{
|
||||
X: int32(rect.X),
|
||||
Y: int32(rect.Y),
|
||||
Width: int32((rect.Width * (CELL_SIZE + CELL_SPACING)) + CELL_SPACING),
|
||||
Height: int32((rect.Height * (CELL_SIZE + CELL_SPACING)) + CELL_SPACING),
|
||||
}, col, border_size, border_col)
|
||||
}
|
||||
|
||||
func Draw(rect rl.RectangleInt32) {
|
||||
// offset for background.
|
||||
rect.X = rect.X + CELL_SPACING
|
||||
rect.Y = rect.Y + CELL_SPACING
|
||||
|
||||
cell := rl.Rectangle{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: float32(CELL_SIZE),
|
||||
Height: float32(CELL_SIZE),
|
||||
}
|
||||
|
||||
for y := range rect.Height {
|
||||
for x := range rect.Width {
|
||||
cell.X = float32(rect.X + (x * (CELL_SIZE + CELL_SPACING)))
|
||||
cell.Y = float32(rect.Y + (y * (CELL_SIZE + CELL_SPACING)))
|
||||
rl.DrawRectangleRec(cell, rl.Black)
|
||||
}
|
||||
}
|
||||
}
|
||||
40
game/draw/renderer.go
Normal file
40
game/draw/renderer.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package draw
|
||||
|
||||
import (
|
||||
"tetris/engine/render"
|
||||
"tetris/game/draw/grid"
|
||||
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
// Border width when drawing frames
|
||||
BORDER_WIDTH = 8
|
||||
|
||||
// Size for normal text
|
||||
TEXT_SIZE = 32
|
||||
|
||||
// Text size for header texts
|
||||
HEADER_TEXT_SIZE = 16
|
||||
)
|
||||
|
||||
type Renderer struct {
|
||||
Theme *Theme
|
||||
}
|
||||
|
||||
func (r Renderer) DrawText(x int32, y int32, text string) {
|
||||
render.DrawText(x, y, TEXT_SIZE, text, r.Theme.Text)
|
||||
}
|
||||
|
||||
func (r Renderer) DrawHeaderText(x int32, y int32, text string) {
|
||||
render.DrawText(x, y, HEADER_TEXT_SIZE, text, r.Theme.TextHeader)
|
||||
}
|
||||
|
||||
func (r Renderer) DrawFrame(rect rl.RectangleInt32) {
|
||||
render.DrawRectBorder(rect, r.Theme.FrameBG, BORDER_WIDTH, r.Theme.FrameBorder)
|
||||
}
|
||||
|
||||
func (r Renderer) DrawGrid(rect rl.RectangleInt32) {
|
||||
grid.DrawBackground(rect, r.Theme.GridBackground, BORDER_WIDTH, r.Theme.FrameBorder)
|
||||
grid.Draw(rect)
|
||||
}
|
||||
20
game/draw/theme.go
Normal file
20
game/draw/theme.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package draw
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
)
|
||||
|
||||
// Theme holds the different colors used when rendering.
|
||||
type Theme struct {
|
||||
// Frame colors
|
||||
FrameBG color.RGBA
|
||||
FrameBorder color.RGBA
|
||||
|
||||
// Text colors
|
||||
TextHeader color.RGBA
|
||||
Text color.RGBA
|
||||
|
||||
// Grid Colors
|
||||
GridBackground color.RGBA
|
||||
GridEmptyCell color.RGBA
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue