Start rts thing

This commit is contained in:
Krzosa Karol
2023-04-17 21:51:41 +02:00
parent 7cb4b7145f
commit 013db0f985
4 changed files with 94 additions and 45 deletions

View File

@@ -1,6 +1,7 @@
#import "LibC.core"
#import "raylib.core"
#load "array.core"
/*@feature_idea: labeled block
It acts just like a scope in C.
@@ -42,54 +43,87 @@ Add :: (a: *Array($T), item: T)
guys: Array(Guy)
Add(&guys, {100, 100})
*/
Array :: struct($T: Type)
data: *T
len: int
cap: int
// @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};
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
Map_Tile :: int
Map :: struct
data: *Map_Tile
x: int
y: int
SCR_X := 1280
SCR_Y := 720
M_X := 0
M_Y := 0
M_P: Vector2
main :: (): int
guys: Array(Guy)
Add(&guys, {pos = {100, 100}})
InitWindow(1280, 720, "Testing")
map_data: [16*16]int
map: Map = {data = &map_data[0], x = 16, y = 16}
InitWindow(SCR_X, SCR_Y, "Testing")
SetTargetFPS(60)
// InitAudioDevice()
// sound := LoadSound("catune - Pass the town, and to the C.mp3")
// SetMasterVolume(0.01)
// PlaySound(sound)
for !WindowShouldClose()
Y := GetScreenHeight()
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
SCR_X = GetScreenWidth()
SCR_Y = GetScreenHeight()
M_X = GetMouseX()
M_Y = GetMouseY()
M_P = GetMousePosition()
BeginDrawing()
ClearBackground(RAYWHITE)
DrawFPS(0, 0)
DrawText(TextFormat("Testing %d", 32), 100, 100, 20, MAROON)
DrawCube({0,0,0}, 10, 10, 10, BLACK)
for i := 0, i < guys.len, i += 1
it := guys.data + i
DrawCircleV(it.pos, 16, MAROON)
RX := 16
RY := 16
for x := 0, x < 16, x += 1
for y := 0, y < 16, y += 1
it := map.data[x + y*map.x]
r: Rectangle = {(x * RX)->F32, (y * RY)->F32, RX->F32, RY->F32}
r2: Rectangle = {r.x + 1, r.y + 1, r.width - 2, r.height - 2}
color := RED
if it == 1 ;; color = GREEN
if CheckCollisionPointRec(M_P, r) ;; color = BLUE
DrawRectangleRec(r2, color)
// DrawFPS(0, 0)
// DrawText(TextFormat("Testing %d", 32), 100, 100, 20, MAROON)
EndDrawing()
return 0