arcadia/src/tile.odin
2024-12-31 13:27:36 +02:00

34 lines
728 B
Odin

package game
import "core:math"
import rl "vendor:raylib"
Tile :: struct {
id: int,
pos: rl.Vector2,
animation: Animation,
}
spawn_tile_under_mouse :: proc() {
tile_position := get_tile_position(world_mouse)
old_tile: bool
for e in entities {
if .Allocated not_in e.flags {continue}
if e.kind == .Tile && e.pos == tile_position {
old_tile = true
}
}
if !old_tile {
create_entity(
Entity {
pos = tile_position,
kind = .Tile,
data = TileData{has_plant = true, plant_id = 0, animation = tomato_animation},
},
)
}
}
get_tile_position :: proc(wpos: rl.Vector2) -> rl.Vector2 {
return {math.floor(wpos.x / TILE_SIZE) * TILE_SIZE, math.floor(wpos.y / TILE_SIZE) * TILE_SIZE}
}