Files
corelang/build/examples/game2d.core
2023-04-05 21:49:05 +02:00

94 lines
1.5 KiB
Core

#import "LibC.core"
#import "raylib.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})
*/
Array :: struct($T: Type)
data: *T
len: S64
cap: S64
Guy :: struct
pos: Vector2
Add :: (a: *Array($T), item: T)
if a.cap == 0
a.cap = 16
a.data = malloc(SizeOf(T) * a.cap->U64)
if a.len + 1 > a.cap
a.cap *= 2
a.data = realloc(a.data, SizeOf(T) * a.cap->U64)
a.data[a.len++] = item
main :: (): int
guys: Array(Guy)
Add(&guys, {pos = {100, 100}})
InitWindow(1280, 720, "Testing")
SetTargetFPS(60)
for !WindowShouldClose()
g := guys.data
if IsKeyDown(KEY_W);; g.pos.y -= 2
if IsKeyDown(KEY_S);; g.pos.y += 2
if IsKeyDown(KEY_A);; g.pos.x -= 2
if IsKeyDown(KEY_D);; g.pos.x += 2
BeginDrawing()
ClearBackground({100})
DrawText("Testing and stuff", 100, 100, 20, RAYWHITE)
for i := 0, i < guys.len, i += 1
it := guys.data + i
DrawCircleV(it.pos, 16, MAROON)
EndDrawing()
return 0