Core: match sizeof etc. syntax with C, Core RTS: Beautifying + animations

This commit is contained in:
Krzosa Karol
2023-04-19 12:50:58 +02:00
parent 891221441e
commit 87657a99a6
20 changed files with 131 additions and 56 deletions

View File

@@ -34,7 +34,7 @@ Guy :: struct
Add :: (a: *Array($T), item: T)
if a.cap == 0
a.cap = 16
a.slice.data = malloc(SizeOf(T) * a.cap)
a.slice.data = malloc(sizeof(T) * a.cap)
a.slice.data[a.slice.len++] = item
guys: Array(Guy)
@@ -89,6 +89,13 @@ MouseP: Vector2
Mode := 0
RectX :: 16
RectY :: 16
Dt: F32
ANI_SetTile :: struct
set: bool
p: V2I
t: F32
ANI_SetTiles: Array(ANI_SetTile)
main :: (): int
MAP_Init()
@@ -107,6 +114,7 @@ main :: (): int
MouseX = GetMouseX()
MouseY = GetMouseY()
MouseP = GetMousePosition()
Dt = GetFrameTime()
map := &MAP_CurrentMap
@@ -124,6 +132,9 @@ main :: (): int
BeginDrawing()
ClearBackground(RAYWHITE)
map_rectangle: Rectangle = {0, 0, map.x->F32 * RectX, map.y->F32 * RectY}
DrawRectangleRec(map_rectangle, LIGHTGRAY)
for x := 0, x < map.x, x += 1
for y := 0, y < map.y, y += 1
it := map.data + (x + y*map.x)
@@ -132,16 +143,56 @@ main :: (): int
colliding := CheckCollisionPointRec(MouseP, r)
if Mode == 0 && colliding && IsMouseButtonDown(MOUSE_BUTTON_LEFT) ;; *it = 1
if Mode == 1 && colliding && IsMouseButtonPressed(MOUSE_BUTTON_LEFT) ;; MAP_CurrentMap.actors.data[0].p = V2I{x,y}
if Mode == 0 && colliding && IsMouseButtonDown(MOUSE_BUTTON_LEFT)
Add(&ANI_SetTiles, {true, {x,y}})
if Mode == 0 && colliding && IsMouseButtonDown(MOUSE_BUTTON_RIGHT)
Add(&ANI_SetTiles, {false, {x,y}})
if Mode == 1 && colliding && IsMouseButtonPressed(MOUSE_BUTTON_LEFT) ;; MAP_ActorSetP(MAP_CurrentMap.actors.data, {x,y})
if Mode == 1 && colliding && IsMouseButtonPressed(MOUSE_BUTTON_RIGHT) ;; MAP_CurrentMap.actors.data[0].target_p = V2I{x,y}
color := GREEN
if *it == 1 ;; color = RED
if colliding == true ;; color = MAROON
color := RAYWHITE
if *it == 1 ;; color = GRAY
if colliding == true
color = MAROON
color.a = 255/2
DrawRectangleRec(r2, color)
for tile_i := 0, tile_i < ANI_SetTiles.len, tile_i += 1
tile_it := ANI_SetTiles.data + tile_i
remove := false
t := tile_it.t
if tile_it.set == false
t = 1 - t
x := tile_it.p.x->F32 * RectX + 1
y := tile_it.p.y->F32 * RectY + 1
w: F32 = (RectX - 2)
h: F32 = (RectY - 2)
wt := w * t
ht := h * t
wd := w - wt
hd := h - ht
r: Rectangle = {x + wd/2, y + hd/2, wt, ht}
DrawRectangleRec(r, GRAY)
if tile_it.t > 1
map_tile := map.data + (tile_it.p.x + tile_it.p.y*map.x)
if tile_it.set ;; *map_tile |= MAP_TILE_BLOCKER
else ;; *map_tile &= ~MAP_TILE_BLOCKER
remove = true
tile_it.t += Dt*8
if remove
UnorderedRemove(&ANI_SetTiles, tile_it)
tile_i -= 1
for i := 0, i < map.actors.len, i += 1
actor_it := map.actors.data + i
r := Rectangle{actor_it.p.x->F32 * RectX, actor_it.p.y->F32 * RectY, RectX, RectY}
@@ -163,8 +214,20 @@ main :: (): int
MAP_RecomputeHistory(actor_it)
for path_i := 0, path_i < actor_it.history.len, path_i += 1
path_it := actor_it.history.data + path_i
path_r := Rectangle{path_it.p.x->F32 * RectX, path_it.p.y->F32 * RectY, RectX, RectY}
DrawRectangleRec(path_r, BLACK)
// path_r := Rectangle{path_it.p.x->F32 * RectX, path_it.p.y->F32 * RectY, RectX, RectY}
x0 := path_it.came_from.x->F32 * RectX + RectX/2
y0 := path_it.came_from.y->F32 * RectY + RectY/2
x1 := path_it.p.x->F32 * RectX + RectX/2
y1 := path_it.p.y->F32 * RectY + RectY/2
p0 := Vector2{x0, y0}
p1 := Vector2{x1, y1}
DrawLineEx(p0, p1, 5, LIGHTGRAY)
DrawCircleV(p0, 4, LIGHTGRAY)
DrawCircleV(p1, 4, LIGHTGRAY)
if Mode == 0 ;; DrawText("F1", 0, 0, 32, BLACK)