Files
corelang/build/rtsgame/main.core
2023-04-17 21:51:41 +02:00

130 lines
2.5 KiB
Core

#import "raylib.core"
#load "array.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};
Guy :: struct
pos: Vector2
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}})
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()
SCR_X = GetScreenWidth()
SCR_Y = GetScreenHeight()
M_X = GetMouseX()
M_Y = GetMouseY()
M_P = GetMousePosition()
BeginDrawing()
ClearBackground(RAYWHITE)
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