39 lines
958 B
Go
39 lines
958 B
Go
package game
|
|
|
|
import (
|
|
"tetris/engine/core"
|
|
"tetris/game/draw"
|
|
|
|
rl "github.com/gen2brain/raylib-go/raylib"
|
|
)
|
|
|
|
type GhostShape struct {
|
|
posY int8 // only need Y coordinate
|
|
}
|
|
|
|
func (gs *GhostShape) UpdatePos(shape *Shape, pos core.Vec2i8, grid *Grid) {
|
|
for gs.posY = pos.Y; pos.Y <= int8(grid.Height()); pos.Y++ {
|
|
if CheckShapeCollision(pos, shape, grid) {
|
|
gs.posY = pos.Y - 1
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
func (gs *GhostShape) Draw(offset rl.Vector2, shape *Shape, pos core.Vec2i8) {
|
|
draw.DrawShapeTile(offset, core.NewVec2(pos.X, gs.posY), shape, BLOCK_GHOST.Tile())
|
|
}
|
|
|
|
func UpdateGhostShapeY(shape *Shape, pos core.Vec2i8, grid *Grid) int8 {
|
|
for ; pos.Y <= int8(grid.Height()); pos.Y++ {
|
|
if CheckShapeCollision(pos, shape, grid) {
|
|
pos.Y = pos.Y - 1
|
|
break
|
|
}
|
|
}
|
|
return pos.Y
|
|
}
|
|
|
|
func DrawGhost(offset rl.Vector2, shape *Shape, pos core.Vec2i8, ghost_y int8) {
|
|
draw.DrawShapeTile(offset, core.NewVec2(pos.X, ghost_y), shape, BLOCK_GHOST.Tile())
|
|
}
|