package game import rl "vendor:raylib" import "core:math/rand" Tile :: struct #packed { tilemap_pos: Vec2i, color: rl.Color, type: TileType, interaction: InteractionType, resource: ResourceType, } TileType :: enum { NOTHING, WALL, FOLIAGE, } ResourceType :: enum { NOTHING, TREE, } InteractionType :: enum { NOTHING, RESOURCE, ENEMY, } serialize_tile :: proc(t: Tile) -> []byte { data: [dynamic]byte // Tilemap Pos (16 bytes) tilemap_pos_bytes := serialize_vec2i(t.tilemap_pos) append(&data, ..tilemap_pos_bytes[:]) // Color (4 bytes) append(&data, byte(t.color.r), byte(t.color.g), byte(t.color.b), byte(t.color.a)) // TileType (8 bytes) tile_type_bytes := serialize_int(int(t.type)) append(&data, ..tile_type_bytes[:]) // Interaction Type (8 bytes) interaction_bytes := serialize_int(int(t.interaction)) append(&data, ..interaction_bytes[:]) // Resource Type (8 bytes) resource_bytes := serialize_int(int(t.resource)) append(&data, ..resource_bytes[:]) return data[:] } deserialize_tile :: proc(data: []byte) -> Tile { t: Tile // Tilemap Pos (16 bytes) t.tilemap_pos = deserialize_vec2i(data[0:16]) // Color (4 bytes) t.color.r = u8(data[16]) t.color.g = u8(data[17]) t.color.b = u8(data[18]) t.color.a = u8(data[19]) // TileType (8 bytes) t.type = TileType(deserialize_int(data[20:28])) // Interaction Type (8 bytes) t.interaction = InteractionType(deserialize_int(data[28:36])) // Resource Type (8 bytes) t.resource = ResourceType(deserialize_int(data[36:44])) return t } // serialize_tile :: proc(t: Tile) -> []byte { // data: [dynamic]byte // // TileType // tile_type_bytes := serialize_int(int(t.type)) // append(&data, ..tile_type_bytes[:]) // // Tilemap Pos // tilemap_pos_bytes := serialize_vec2i(t.tilemap_pos) // append(&data, ..tilemap_pos_bytes[:]) // // Color // append(&data, byte(t.color.r), byte(t.color.g), byte(t.color.b), byte(t.color.a)) // // Interaction Type // interaction_bytes := serialize_int(int(t.interaction)) // append(&data, ..interaction_bytes[:]) // // Resource Type // resource_bytes := serialize_int(int(t.resource)) // append(&data, ..resource_bytes[:]) // return data[:] // } // deserialize_tile :: proc(data:[]byte) -> Tile { // t: Tile // // TileType // t.type = TileType(deserialize_int(data[0:4])) // // TilemapPos // t.tilemap_pos = deserialize_vec2i(data[4:12]) // // Color // t.color.r = u8(data[12]) // t.color.g = u8(data[13]) // t.color.b = u8(data[14]) // t.color.a = u8(data[15]) // // ResourceType // t.resource = ResourceType(deserialize_int(data[16:20])) // // InteractionType // t.interaction = InteractionType(deserialize_int(data[20:24])) // return t // } tree_tile := Tile { type = .WALL, tilemap_pos = {0,1}, color = rl.DARKGREEN, resource = .TREE, interaction = .RESOURCE, }