raylib demo: tetris
This commit is contained in:
@@ -84,6 +84,7 @@ func rotateShape() {
|
|||||||
curShape = temp
|
curShape = temp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func clearLines() int {
|
func clearLines() int {
|
||||||
linesCleared := 0
|
linesCleared := 0
|
||||||
for y := BOARD_HEIGHT - 1; y >= 0; y-- {
|
for y := BOARD_HEIGHT - 1; y >= 0; y-- {
|
||||||
@@ -110,9 +111,12 @@ func clearLines() int {
|
|||||||
return linesCleared
|
return linesCleared
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func keyPressed(key c.Int) bool {
|
||||||
|
return raylib.IsKeyPressed(key) || raylib.IsKeyPressedRepeat(key)
|
||||||
|
}
|
||||||
|
|
||||||
raylib.InitWindow(SCREENWIDTH, SCREENHEIGHT, c.Str("Raylib DEMO"))
|
func main() {
|
||||||
|
raylib.InitWindow(SCREENWIDTH, SCREENHEIGHT, c.Str("tetris (powered by raylib + llgo)"))
|
||||||
raylib.SetTargetFPS(c.Int(60))
|
raylib.SetTargetFPS(c.Int(60))
|
||||||
genShape()
|
genShape()
|
||||||
for !raylib.WindowShouldClose() && !gameOver {
|
for !raylib.WindowShouldClose() && !gameOver {
|
||||||
@@ -132,19 +136,19 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if raylib.IsKeyPressed(raylib.KEY_LEFT) {
|
if keyPressed(raylib.KEY_LEFT) {
|
||||||
curPos.X -= 1
|
curPos.X -= 1
|
||||||
if checkCollision() {
|
if checkCollision() {
|
||||||
curPos.X += 1
|
curPos.X += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if raylib.IsKeyPressed(raylib.KEY_RIGHT) {
|
if keyPressed(raylib.KEY_RIGHT) {
|
||||||
curPos.X += 1
|
curPos.X += 1
|
||||||
if checkCollision() {
|
if checkCollision() {
|
||||||
curPos.X -= 1
|
curPos.X -= 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if raylib.IsKeyPressed(raylib.KEY_UP) || raylib.IsKeyPressed(raylib.KEY_DOWN) {
|
if keyPressed(raylib.KEY_SPACE) || keyPressed(raylib.KEY_UP) || keyPressed(raylib.KEY_DOWN) {
|
||||||
rotateShape()
|
rotateShape()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user