up to building the map

This commit is contained in:
2026-06-10 02:32:01 -07:00
parent fa7a6ac176
commit 4032a5ea76
5 changed files with 93 additions and 2 deletions
+24
View File
@@ -0,0 +1,24 @@
package game
import rl "vendor:raylib"
run :: proc() {
rl.InitWindow(640, 480, "Tower Defense")
defer rl.CloseWindow()
rl.SetTargetFPS(60)
world := init_world()
for !rl.WindowShouldClose() {
dt := rl.GetFrameTime()
update_world(&world, dt)
rl.BeginDrawing()
rl.ClearBackground(rl.Color{34, 139, 34, 255})
render_world(&world)
rl.EndDrawing()
}
}
+6
View File
@@ -0,0 +1,6 @@
package game
MAP_W :: 16 // map width in tiles
MAP_H :: 12 // map height in tiles
TILE_SIZE :: 32 // size of tiles in pixels
+34
View File
@@ -0,0 +1,34 @@
package game
import rl "vendor:raylib"
Tile_Kind :: enum {
Blocked,
Path,
Build,
}
Map :: struct {
tiles: [MAP_H][MAP_W]Tile_Kind,
}
tile_color :: proc(kind: Tile_Kind) -> rl.Color {
switch kind {
case .Blocked:
return {35, 95, 35, 255}
case .Path:
return {130, 85, 45, 255}
case .Build:
return {50, 130, 50, 255}
}
return rl.MAGENTA
}
init_map :: proc(world_map: ^Map) {
for y in 0 ..< MAP_H {
for x in 0 ..< MAP_W {
world_map.tiles[y][x] = .Blocked
}
}
}
+27
View File
@@ -0,0 +1,27 @@
package game
import "core:fmt"
import rl "vendor:raylib"
World :: struct {
gold: int,
base_health: int,
}
init_world :: proc() -> World {
return World{gold = 10, base_health = 20}
}
// update world, never draw
update_world :: proc(world: ^World, dt: f32) {
_ = dt
if rl.IsKeyPressed(.G) {
world.gold += 10
}
}
render_world :: proc(world: ^World) {
rl.DrawText(fmt.caprintf("gold: %d", world.gold), 10, 10, 22, rl.BLACK)
rl.DrawText(fmt.caprintf("health: %d", world.base_health), 10, 38, 22, rl.BLACK)
}
+2 -2
View File
@@ -1,8 +1,8 @@
package main
import "core:fmt"
import game "./game"
main :: proc() {
fmt.println("hello world")
game.run()
}