spawn an entity, no movement yet
This commit is contained in:
@@ -8,3 +8,6 @@ TILE_SIZE :: 32
|
||||
MAP_WIDTH :: 80
|
||||
MAP_HEIGHT :: 60
|
||||
|
||||
MAX_ENTITIES :: 256
|
||||
INVALID_ENTITY :: Entity(0)
|
||||
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import rl "vendor:raylib"
|
||||
|
||||
Entity :: distinct u32
|
||||
|
||||
Entity_World :: struct {
|
||||
count: int,
|
||||
active: [MAX_ENTITIES]bool,
|
||||
position: [MAX_ENTITIES]Tile_Coord,
|
||||
color: [MAX_ENTITIES]rl.Color,
|
||||
is_colonist: [MAX_ENTITIES]bool,
|
||||
}
|
||||
|
||||
entity_world_init :: proc() -> Entity_World {
|
||||
return Entity_World{}
|
||||
}
|
||||
|
||||
entity_spawn_colonist :: proc(ew: ^Entity_World, pos: Tile_Coord) -> Entity {
|
||||
for i in 0 ..< MAX_ENTITIES {
|
||||
if !ew.active[i] {
|
||||
ew.active[i] = true
|
||||
ew.position[i] = pos
|
||||
ew.color[i] = {80, 140, 220, 225}
|
||||
ew.is_colonist[i] = true
|
||||
ew.count += 1
|
||||
return Entity(u32(i + 1))
|
||||
}
|
||||
}
|
||||
|
||||
return INVALID_ENTITY
|
||||
}
|
||||
|
||||
entity_index :: proc(e: Entity) -> int {
|
||||
return int(u32(e) - 1)
|
||||
}
|
||||
|
||||
entity_draw :: proc(ew: ^Entity_World, camera: ^Camera2D) {
|
||||
for i in 0 ..< MAX_ENTITIES {
|
||||
if !ew.active[i] || !ew.is_colonist[i] {
|
||||
continue
|
||||
}
|
||||
|
||||
pos := ew.position[i]
|
||||
wx := f32(pos.x * TILE_SIZE) + f32(TILE_SIZE) * 0.5
|
||||
wy := f32(pos.y * TILE_SIZE) + f32(TILE_SIZE) * 0.5
|
||||
sx, sy := world_to_screen(camera, wx, wy)
|
||||
radius := f32(TILE_SIZE) * 0.3 * camera.zoom
|
||||
|
||||
rl.DrawCircle(i32(sx), i32(sy), radius, ew.color[i])
|
||||
rl.DrawCircleLines(i32(sx), i32(sy), radius, rl.WHITE)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ Game :: struct {
|
||||
tilemap: Tilemap,
|
||||
camera: Camera2D,
|
||||
selection: Selection,
|
||||
world: World,
|
||||
}
|
||||
|
||||
Camera2D :: struct {
|
||||
@@ -34,6 +35,9 @@ game_init :: proc() -> Game {
|
||||
}
|
||||
g.tilemap = tilemap_init()
|
||||
g.camera = camera_init()
|
||||
g.world = world_init()
|
||||
center := Tile_Coord{MAP_WIDTH / 2, MAP_HEIGHT / 2}
|
||||
entity_spawn_colonist(&g.world.entities, center)
|
||||
return g
|
||||
}
|
||||
|
||||
@@ -116,6 +120,8 @@ game_draw :: proc(g: ^Game) {
|
||||
tilemap_draw(&g.tilemap, &g.camera)
|
||||
tilemap_draw_selection(&g.tilemap, &g.camera, &g.selection)
|
||||
|
||||
world_draw(&g.world, &g.camera)
|
||||
|
||||
if g.selection.active {
|
||||
rl.DrawText(
|
||||
rl.TextFormat("Selection: (%i,%i)", g.selection.tile.x, g.selection.tile.y),
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
World :: struct {
|
||||
entities: Entity_World,
|
||||
}
|
||||
|
||||
world_init :: proc() -> World {
|
||||
w := World{}
|
||||
w.entities = entity_world_init()
|
||||
return w
|
||||
}
|
||||
|
||||
world_draw :: proc(w: ^World, camera: ^Camera2D) {
|
||||
entity_draw(&w.entities, camera)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user