49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package main
|
|
|
|
import rl "github.com/gen2brain/raylib-go/raylib"
|
|
|
|
// Initialize the map with some height data
|
|
func InitMap() [][]Tile {
|
|
mapGrid := make([][]Tile, MapWidth)
|
|
for x := 0; x < MapWidth; x++ {
|
|
mapGrid[x] = make([]Tile, MapHeight)
|
|
for y := 0; y < MapHeight; y++ {
|
|
mapGrid[x][y] = Tile{
|
|
X: x,
|
|
Y: y,
|
|
Height: 1.0 + float32(x%5), // Example height
|
|
Walkable: true, // Set to false for obstacles
|
|
}
|
|
}
|
|
}
|
|
return mapGrid
|
|
}
|
|
|
|
func DrawMap() {
|
|
for x := 0; x < MapWidth; x++ {
|
|
for y := 0; y < MapHeight; y++ {
|
|
tile := mapGrid[x][y]
|
|
// Interpolate height between adjacent tiles for a smoother landscape
|
|
height := tile.Height
|
|
if x > 0 {
|
|
height += mapGrid[x-1][y].Height
|
|
}
|
|
if y > 0 {
|
|
height += mapGrid[x][y-1].Height
|
|
}
|
|
if x > 0 && y > 0 {
|
|
height += mapGrid[x-1][y-1].Height
|
|
}
|
|
height /= 4.0
|
|
// Draw each tile as a 3D cube based on its height
|
|
tilePos := rl.Vector3{
|
|
X: float32(x * TileSize), // X-axis for horizontal position
|
|
Y: height * TileHeight, // Y-axis for height (Z in 3D is Y here)
|
|
Z: float32(y * TileSize), // Z-axis for depth (Y in 3D is Z here)
|
|
}
|
|
color := rl.Color{R: uint8(height * 25), G: 100, B: 100, A: 64}
|
|
rl.DrawCube(tilePos, TileSize, TileHeight, TileSize, color) // Draw a cube representing the tile
|
|
}
|
|
}
|
|
}
|