This commit is contained in:
bdnugget 2024-09-23 14:26:50 +02:00
parent 67809d2ecd
commit dc459defc3

24
main.go
View File

@ -32,6 +32,15 @@ type Car struct {
xPos int xPos int
} }
func NewCar() Car {
return Car{
texture: autoTexture,
lane: rand.Intn(numLanes),
color: randomColor(),
xPos: 25,
}
}
type Garage struct { type Garage struct {
lane int lane int
color rl.Color color rl.Color
@ -44,15 +53,6 @@ type Game struct {
gameOver bool gameOver bool
} }
func NewCar() Car {
return Car{
texture: autoTexture,
lane: rand.Intn(numLanes),
color: randomColor(),
xPos: 25,
}
}
func NewGame() *Game { func NewGame() *Game {
game := &Game{ game := &Game{
car: NewCar(), car: NewCar(),
@ -123,6 +123,12 @@ func (g *Game) update() {
} }
// Move car // 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 { if rl.IsKeyPressed(rl.KeyUp) && g.car.lane > 0 {
g.car.lane-- g.car.lane--
} 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 {