From dc459defc30a6e95c9cf61ac801419ef0a5182c2 Mon Sep 17 00:00:00 2001 From: bdnugget Date: Mon, 23 Sep 2024 14:26:50 +0200 Subject: [PATCH] Touche? --- main.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index d5edd38..d873876 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,15 @@ type Car struct { xPos int } +func NewCar() Car { + return Car{ + texture: autoTexture, + lane: rand.Intn(numLanes), + color: randomColor(), + xPos: 25, + } +} + type Garage struct { lane int color rl.Color @@ -44,15 +53,6 @@ type Game struct { gameOver bool } -func NewCar() Car { - return Car{ - texture: autoTexture, - lane: rand.Intn(numLanes), - color: randomColor(), - xPos: 25, - } -} - func NewGame() *Game { game := &Game{ car: NewCar(), @@ -123,6 +123,12 @@ func (g *Game) update() { } // Move car + if touchX := int(rl.GetTouchX()); touchX > 0 { + g.car.lane = touchX / (screenWidth / numLanes) + // show coordinates and lane number on screen + rl.DrawText(fmt.Sprintf("%d, %d", touchX, g.car.lane), 20, 50, 32, rl.Red) + } + if rl.IsKeyPressed(rl.KeyUp) && g.car.lane > 0 { g.car.lane-- } else if (rl.IsKeyPressed(rl.KeyDown) || rl.IsKeyPressed(rl.KeyLeft) || rl.IsKeyPressed(rl.KeyRight)) && g.car.lane < numLanes-1 {