This commit is contained in:
bdnugget 2024-09-23 14:58:40 +02:00
parent dc459defc3
commit 8958c3328f

12
main.go
View File

@ -51,6 +51,7 @@ type Game struct {
garages [numGarages]Garage garages [numGarages]Garage
score int score int
gameOver bool gameOver bool
debugMsg string
} }
func NewGame() *Game { func NewGame() *Game {
@ -123,10 +124,11 @@ func (g *Game) update() {
} }
// Move car // Move car
if touchX := int(rl.GetTouchX()); touchX > 0 { if rl.IsGestureDetected(rl.GestureTap) {
g.car.lane = touchX / (screenWidth / numLanes) touchY := int(rl.GetTouchY())
// show coordinates and lane number on screen lane := touchY / (screenHeight / numLanes)
rl.DrawText(fmt.Sprintf("%d, %d", touchX, g.car.lane), 20, 50, 32, rl.Red) g.debugMsg = fmt.Sprintf("Y: %d, Lane: %d", touchY, lane)
g.car.lane = lane
} }
if rl.IsKeyPressed(rl.KeyUp) && g.car.lane > 0 { if rl.IsKeyPressed(rl.KeyUp) && g.car.lane > 0 {
@ -134,6 +136,8 @@ func (g *Game) update() {
} else if (rl.IsKeyPressed(rl.KeyDown) || rl.IsKeyPressed(rl.KeyLeft) || rl.IsKeyPressed(rl.KeyRight)) && g.car.lane < numLanes-1 { } else if (rl.IsKeyPressed(rl.KeyDown) || rl.IsKeyPressed(rl.KeyLeft) || rl.IsKeyPressed(rl.KeyRight)) && g.car.lane < numLanes-1 {
g.car.lane++ g.car.lane++
} }
rl.DrawText(g.debugMsg, 20, 100, 32, rl.Red)
} }
func main() { func main() {