278 lines
7.7 KiB
Core
278 lines
7.7 KiB
Core
|
|
/*@feature_idea: labeled block
|
|
|
|
It acts just like a scope in C.
|
|
BUT it can be turned into a goto label by adding another semicolon
|
|
at the end.
|
|
|
|
:block
|
|
thing := 1
|
|
thing2 := thing
|
|
|
|
:label_without_block
|
|
thing := 1
|
|
|
|
|
|
:goto_block:
|
|
thing := 1
|
|
thing2 := thing
|
|
|
|
:goto_block: for
|
|
*/
|
|
|
|
/*
|
|
@reproduction:
|
|
This kills the compiler due to referencing slice data
|
|
|
|
Array :: struct($T: Type)
|
|
slice: []T
|
|
cap: S64
|
|
|
|
Guy :: struct
|
|
pos: Vector2
|
|
|
|
Add :: (a: *Array($T), item: T)
|
|
if a.cap == 0
|
|
a.cap = 16
|
|
a.slice.data = malloc(sizeof(T) * a.cap)
|
|
a.slice.data[a.slice.len++] = item
|
|
|
|
guys: Array(Guy)
|
|
Add(&guys, {100, 100})
|
|
*/
|
|
|
|
|
|
// @reproduction
|
|
// MAP: [16*16]int = {0, 1}
|
|
//
|
|
// This generates: int MAP[256] = (int [256]){[0] = 0, [0] = 1}; it doesn't work because of the (int[256]) is this MSVC being retarded here? not supporting C properly?
|
|
// Also this ^ ^
|
|
|
|
// @reproduction
|
|
// map_data: [16*16]int
|
|
// map: Map = {data = map_data->*int, 16, 16}
|
|
//
|
|
// Failed to cast from [[256]int] to [*int]
|
|
|
|
// @reproduction
|
|
// map_data: [16*16]int
|
|
// map: Map = {data = &map_data[0], 16, 16}
|
|
//
|
|
// Map map = (Map ){.data = (&(map_data[0])), .data = 0x10, .x = 16};
|
|
|
|
// @reproduction Couldn't figure out type of compound expression when variable got declared and separetly
|
|
// got assigned a value
|
|
//
|
|
// Error! Couldn't infer type of compound expression
|
|
// if Mode == 0 && colliding && IsMouseButtonPressed(MOUSE_BUTTON_RIGHT) ;; GuyP = {x,y}
|
|
// Error! Couldn't infer type of compound expression
|
|
// if Mode == 1 && colliding && IsMouseButtonPressed(MOUSE_BUTTON_LEFT) ;; MAP_CurrentMap.actors.data[0].p = {x,y}
|
|
|
|
// @compiler_todo: It's possible to have 2 definitions with same name. 1 global, 1 local
|
|
// Mode := 0
|
|
// main :: ()
|
|
// if IsKeyPressed(KEY_F1) ;; Mode := 0
|
|
|
|
#import "raylib.core"
|
|
#load "array.core"
|
|
#load "map.core"
|
|
|
|
V2I :: struct ;; x: int; y: int
|
|
|
|
WinX := 1280
|
|
WinY := 720
|
|
MouseX := 0
|
|
MouseY := 0
|
|
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()
|
|
|
|
// InitAudioDevice()
|
|
// sound := LoadSound("catune - Pass the town, and to the C.mp3")
|
|
// SetMasterVolume(0.01)
|
|
// PlaySound(sound)
|
|
|
|
InitWindow(WinX, WinY, "Testing")
|
|
SetTargetFPS(60)
|
|
|
|
orange := ORANGE
|
|
orange.a = 255/2
|
|
|
|
brown := BROWN
|
|
brown.a = 255/2
|
|
|
|
actor_color := DARKGREEN
|
|
actor_color.a = 255/2
|
|
|
|
past_actor_color := BLUE
|
|
past_actor_color.a = 255/2
|
|
|
|
target_color := RED
|
|
target_color.a = 255/2
|
|
|
|
for !WindowShouldClose()
|
|
WinX = GetScreenWidth()
|
|
WinY = GetScreenHeight()
|
|
MouseX = GetMouseX()
|
|
MouseY = GetMouseY()
|
|
MouseP = GetMousePosition()
|
|
Dt = GetFrameTime()
|
|
map := &MAP_CurrentMap
|
|
|
|
|
|
if IsKeyPressed(KEY_F1) ;; Mode = 0
|
|
if IsKeyPressed(KEY_F2) ;; Mode = 1
|
|
if IsKeyPressed(KEY_F3)
|
|
for i := 0, i < map.actors.len, i += 1
|
|
it := map.actors.data + i
|
|
MAP_MoveTowardsTarget(it)
|
|
if IsKeyPressed(KEY_F4)
|
|
MAP_RandomizeActors()
|
|
if IsKeyDown(KEY_SPACE)
|
|
for i := 0, i < map.actors.len, i += 1
|
|
it := map.actors.data + i
|
|
MAP_PathFindStep(it)
|
|
|
|
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)
|
|
r: Rectangle = {x->F32 * RectX, y->F32 * RectY, RectX, RectY}
|
|
r2: Rectangle = {r.x + 1, r.y + 1, r.width - 2, r.height - 2}
|
|
|
|
colliding := CheckCollisionPointRec(MouseP, r)
|
|
|
|
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 := RAYWHITE
|
|
if *it == 1 ;; color = GRAY
|
|
if colliding == true
|
|
color = Color{a = 100}
|
|
|
|
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}
|
|
target_r := Rectangle{actor_it.target_p.x->F32 * RectX, actor_it.target_p.y->F32 * RectY, RectX, RectY}
|
|
|
|
main_p := Vector2{actor_it.p.x->F32 * RectX + RectX/2, actor_it.p.y->F32 * RectY + RectY/2}
|
|
DrawCircleV(main_p, RectX/2, actor_color)
|
|
// DrawRectangleRec(r, actor_color)
|
|
DrawRectangleRec(target_r, target_color)
|
|
|
|
smaller_the_further: F32 = 0
|
|
for tile_i := actor_it.tiles_visited.len - 1, tile_i >= 0, tile_i -= 1
|
|
tile_it := actor_it.tiles_visited.data + tile_i
|
|
p := Vector2{tile_it.x->F32 * RectX + RectX/2, tile_it.y->F32 * RectY + RectY/2}
|
|
DrawCircleV(p, RectX/2 - smaller_the_further, past_actor_color)
|
|
smaller_the_further += 0.3
|
|
|
|
for path_i := 0, path_i < actor_it.open_paths.len, path_i += 1
|
|
path_it := actor_it.open_paths.data + path_i
|
|
path_r := Rectangle{path_it.p.x->F32 * RectX, path_it.p.y->F32 * RectY, RectX, RectY}
|
|
DrawRectangleRec(path_r, orange)
|
|
|
|
for path_i := 0, path_i < actor_it.close_paths.len, path_i += 1
|
|
path_it := actor_it.close_paths.data + path_i
|
|
path_r := Rectangle{path_it.p.x->F32 * RectX, path_it.p.y->F32 * RectY, RectX, RectY}
|
|
DrawRectangleRec(path_r, brown)
|
|
|
|
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}
|
|
|
|
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)
|
|
|
|
menu_open := false
|
|
if menu_open
|
|
text_size := 24
|
|
text_p := 4
|
|
text_y := WinY - text_size
|
|
|
|
DrawText("Space :: PathFind", text_p, text_y, text_size, GRAY)
|
|
text_y -= text_size
|
|
DrawText("F4 :: Randomize actors", text_p, text_y, text_size, GRAY)
|
|
text_y -= text_size
|
|
|
|
DrawText("F3 :: Simulate actors", text_p, text_y, text_size, GRAY)
|
|
text_y -= text_size
|
|
text: *char = "Mode(F1) :: Block placing"
|
|
if Mode == 1 ;; text = "Mode(F2) :: Actor placing"
|
|
DrawText(text, text_p, text_y, text_size, GRAY)
|
|
text_y -= text_size
|
|
|
|
|
|
|
|
EndDrawing()
|
|
|
|
return 0
|