Compare commits
8 Commits
c9d3d0c65f
...
master
Author | SHA1 | Date | |
---|---|---|---|
1e0d90040a | |||
96a9ada1a9 | |||
d55585f77b | |||
d1fc577bdb | |||
937cc5deba | |||
8958c3328f | |||
dc459defc3 | |||
67809d2ecd |
22
README.md
22
README.md
@ -1,10 +1,30 @@
|
||||
# autogo
|
||||
The silly Raylib cargame I made in C but in Go for my champ
|
||||
|
||||
## Installation
|
||||
1. Install Go on your system if you haven't already. You can download the latest version from the [official Go website](https://golang.org/dl/).
|
||||
2. Clone this repository using Git:
|
||||
```bash
|
||||
git clone https://gitea.boner.be/bdnugget/autogo.git
|
||||
```
|
||||
3. Navigate to the project directory:
|
||||
```bash
|
||||
cd autogo
|
||||
```
|
||||
4. Run the following command to download and install the required dependencies:
|
||||
```
|
||||
go mod download
|
||||
```
|
||||
5. Build and run the game using the following command:
|
||||
```
|
||||
go run main.go
|
||||
```
|
||||
This should launch the game window, and you can start playing!
|
||||
|
||||
## Screenshot
|
||||

|
||||
|
||||
|
||||
### note Garage texture
|
||||
### Note to self garage texture and other ImageMagicks
|
||||
changed saturation to 10% to make Raylib tint work well enough, using ImageMagick:
|
||||
```convert garage.png -resize 200x200! -channel A -evaluate multiply 0.5 +channel -modulate 100,25,100 garage_200px.png```
|
85
main.go
85
main.go
@ -8,20 +8,26 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
screenWidth = 1600
|
||||
screenWidth = 1300
|
||||
screenHeight = 800
|
||||
numLanes = 5
|
||||
numGarages = 5
|
||||
carSpeed = 5
|
||||
laneHeight = screenHeight / numLanes
|
||||
garageWidth = 200
|
||||
scorePosx = 10
|
||||
scorePosy = 10
|
||||
scoreFontSize = 32
|
||||
gameOverPosx = screenWidth/2 - 150
|
||||
gameOverPosy = screenHeight/2 - 20
|
||||
gameOverFontSize = 32
|
||||
)
|
||||
|
||||
var (
|
||||
garageColors = [numGarages]rl.Color{rl.Red, rl.Blue, rl.Green, rl.Yellow, rl.Purple}
|
||||
garageColors = []rl.Color{rl.Red, rl.Blue, rl.Green, rl.Yellow, rl.Purple}
|
||||
autoHappy rl.Sound
|
||||
autoSad rl.Sound
|
||||
autoTexture rl.Texture2D
|
||||
garageTexture rl.Texture2D
|
||||
asphaltTexture rl.Texture2D
|
||||
highScore int
|
||||
)
|
||||
|
||||
@ -30,6 +36,17 @@ type Car struct {
|
||||
lane int
|
||||
color rl.Color
|
||||
xPos int
|
||||
speed int
|
||||
}
|
||||
|
||||
func NewCar() Car {
|
||||
return Car{
|
||||
texture: autoTexture,
|
||||
lane: rand.Intn(numLanes),
|
||||
color: randomColor(),
|
||||
xPos: 25,
|
||||
speed: 1,
|
||||
}
|
||||
}
|
||||
|
||||
type Garage struct {
|
||||
@ -39,22 +56,14 @@ type Garage struct {
|
||||
|
||||
type Game struct {
|
||||
car Car
|
||||
garages [numGarages]Garage
|
||||
garages [numLanes]Garage
|
||||
score int
|
||||
gameOver bool
|
||||
debugMsg string
|
||||
}
|
||||
|
||||
func NewCar() Car {
|
||||
return Car{
|
||||
texture: autoTexture,
|
||||
lane: rand.Intn(numLanes),
|
||||
color: randomColor(),
|
||||
xPos: 25,
|
||||
}
|
||||
}
|
||||
|
||||
func NewGame() *Game {
|
||||
game := &Game{
|
||||
func NewGame() Game {
|
||||
game := Game{
|
||||
car: NewCar(),
|
||||
score: 0,
|
||||
gameOver: false,
|
||||
@ -70,44 +79,47 @@ func NewGame() *Game {
|
||||
|
||||
return game
|
||||
}
|
||||
|
||||
func randomColor() rl.Color {
|
||||
return garageColors[rand.Intn(len(garageColors))]
|
||||
}
|
||||
|
||||
func (g *Game) draw() {
|
||||
// Draw stripes on the road
|
||||
for i := 0; i < numLanes; i++ {
|
||||
rl.DrawRectangle(0, int32(i*laneHeight), screenWidth, 2, rl.White)
|
||||
func (g Game) draw() {
|
||||
for i := 0; i <= screenHeight/laneHeight; i++ {
|
||||
for j := 0; j < screenWidth/int(asphaltTexture.Width); j++ {
|
||||
rl.DrawTexturePro(asphaltTexture, rl.NewRectangle(0, 0, float32(asphaltTexture.Width), float32(asphaltTexture.Height)), rl.NewRectangle(float32(j)*float32(asphaltTexture.Width), float32(i*laneHeight-laneHeight/2), float32(asphaltTexture.Width), float32(asphaltTexture.Height)), rl.Vector2{}, 0, rl.White)
|
||||
}
|
||||
}
|
||||
|
||||
// Draw garages
|
||||
for _, garage := range g.garages {
|
||||
rl.DrawRectangle(int32(screenWidth-150), int32(garage.lane*laneHeight), 150, int32(laneHeight), garage.color)
|
||||
rl.DrawTexture(garageTexture, int32(screenWidth-150), int32(garage.lane*laneHeight), garage.color)
|
||||
rl.DrawTexture(garageTexture, int32(screenWidth-garageWidth), int32(garage.lane*laneHeight), garage.color)
|
||||
}
|
||||
|
||||
// Draw car
|
||||
rl.DrawTexture(g.car.texture, int32(g.car.xPos), int32(g.car.lane*laneHeight), g.car.color)
|
||||
|
||||
rl.DrawText(fmt.Sprintf("Score: %d\nHigh Score: %d", g.score, highScore), 10, 10, 32, rl.DarkGreen)
|
||||
rl.DrawText(fmt.Sprintf("Score: %d\nHigh Score: %d", g.score, highScore), scorePosx, scorePosy, scoreFontSize, rl.DarkGreen)
|
||||
if g.gameOver {
|
||||
rl.DrawText("You're not an WinRAR :(\nPress Enter to Restart", int32(screenWidth/2-150), int32(screenHeight/2-20), 32, rl.Red)
|
||||
rl.DrawText("You're not an WinRAR :(\nPress Enter to Restart", gameOverPosx, gameOverPosy, gameOverFontSize, rl.Red)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) update() {
|
||||
if rl.IsKeyPressed(rl.KeyF) {
|
||||
rl.ToggleFullscreen()
|
||||
}
|
||||
|
||||
if g.gameOver {
|
||||
if rl.IsKeyPressed(rl.KeyEnter) {
|
||||
*g = *NewGame()
|
||||
if rl.IsKeyPressed(rl.KeyEnter) || rl.IsKeyPressed(rl.KeyKpEnter) || rl.IsGestureDetected(rl.GestureTap) {
|
||||
*g = NewGame()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
g.car.xPos += carSpeed
|
||||
g.car.xPos += g.car.speed
|
||||
|
||||
// Check if the car has reached the garages
|
||||
if int32(g.car.xPos)+g.car.texture.Width >= screenWidth-100 {
|
||||
if int32(g.car.xPos)+g.car.texture.Width >= screenWidth-garageWidth {
|
||||
garage := g.garages[g.car.lane]
|
||||
if g.car.color == garage.color {
|
||||
rl.PlaySound(autoHappy)
|
||||
@ -122,14 +134,24 @@ func (g *Game) update() {
|
||||
}
|
||||
}
|
||||
|
||||
g.car.speed = 3 + g.score/5
|
||||
|
||||
// Move car
|
||||
if rl.IsGestureDetected(rl.GestureTap) {
|
||||
touchY := int(rl.GetTouchY())
|
||||
lane := touchY / (screenHeight / numLanes)
|
||||
g.debugMsg = fmt.Sprintf("Y: %d, Lane: %d", touchY, lane)
|
||||
g.car.lane = lane
|
||||
}
|
||||
|
||||
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 {
|
||||
g.car.lane++
|
||||
}
|
||||
}
|
||||
|
||||
rl.DrawText(g.debugMsg, 20, 100, 32, rl.Red)
|
||||
}
|
||||
func main() {
|
||||
rl.InitWindow(screenWidth, screenHeight, "Dikke Vette Cargame voor Milo")
|
||||
rl.InitAudioDevice()
|
||||
@ -140,7 +162,10 @@ func main() {
|
||||
autoSad = rl.LoadSound("resources/auto_sad_vob.ogg")
|
||||
autoTexture = rl.LoadTexture("resources/car_200px.png")
|
||||
garageTexture = rl.LoadTexture("resources/garage_200px.png")
|
||||
asphaltTexture = rl.LoadTexture("resources/asphalt.png")
|
||||
defer rl.UnloadTexture(autoTexture)
|
||||
defer rl.UnloadTexture(garageTexture)
|
||||
defer rl.UnloadTexture(asphaltTexture)
|
||||
defer rl.UnloadSound(autoHappy)
|
||||
defer rl.UnloadSound(autoSad)
|
||||
|
||||
|
BIN
resources/asphalt.png
Normal file
BIN
resources/asphalt.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 57 KiB |
BIN
resources/ground_asphalt_synth_12.png
Normal file
BIN
resources/ground_asphalt_synth_12.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 633 KiB |
Binary file not shown.
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 429 KiB |
Reference in New Issue
Block a user