forked from bext-lang/b
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraylib.b
More file actions
107 lines (90 loc) · 2.56 KB
/
raylib.b
File metadata and controls
107 lines (90 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// -*- mode: simpc -*-
// To compile this example you need to download raylib from https://github.com/raysan5/raylib/releases
// Than pass appropriate linker flags to the b compiler.
// # Linux
//
// $ b raylib.b -C link-args='-L/path/to/raylib-version_linux_amd64/lib/ -l:libraylib.a -lm' -run
//
// # Windows mingw32-w64
// > b -t gas-x86_64-windows raylib.b -C link-args='-L$HOME/opt/raylib-version_win64_mingw-w64/lib/ -l:libraylib.a -lwinmm -lgdi32' -run
W;
OBJ_X; OBJ_Y; OBJ_DX; OBJ_DY; OBJ_C; SIZE_OF_OBJ;
OBJS_COUNT;
OBJS;
COLORS_COUNT 6;
COLORS [6]
// B originally does not support hex literals actually.
0xFF1818FF,
0xFF18FF18,
0xFFFF1818,
0xFFFFFF18,
0xFFFF18FF,
0xFF18FFFF;
update_obj(obj) {
auto nx, ny;
nx = obj[OBJ_X] + obj[OBJ_DX];
if (nx < 0 | nx + 100 >= GetScreenWidth()) {
obj[OBJ_DX] = -obj[OBJ_DX];
obj[OBJ_C] += 1;
obj[OBJ_C] %= COLORS_COUNT;
} else {
obj[OBJ_X] = nx;
}
ny = obj[OBJ_Y] + obj[OBJ_DY];
if (ny < 0 | ny + 100 >= GetScreenHeight()) {
obj[OBJ_DY] = -obj[OBJ_DY];
obj[OBJ_C] += 1;
obj[OBJ_C] %= COLORS_COUNT;
} else {
obj[OBJ_Y] = ny;
}
}
draw_obj(obj) DrawRectangle(obj[OBJ_X], obj[OBJ_Y], 100, 100, COLORS[obj[OBJ_C]]);
main() {
W = &0[1];
auto i;
i = 0;
OBJ_X = i++;
OBJ_Y = i++;
OBJ_DX = i++;
OBJ_DY = i++;
OBJ_C = i++;
SIZE_OF_OBJ = i++;
OBJS_COUNT = 10;
OBJS = malloc(W*SIZE_OF_OBJ*OBJS_COUNT);
i = 0; while (i < OBJS_COUNT) {
OBJS[i*SIZE_OF_OBJ + OBJ_X] = rand()%500;
OBJS[i*SIZE_OF_OBJ + OBJ_Y] = rand()%500;
OBJS[i*SIZE_OF_OBJ + OBJ_DX] = rand()%10;
OBJS[i*SIZE_OF_OBJ + OBJ_DY] = rand()%10;
OBJS[i*SIZE_OF_OBJ + OBJ_C] = rand()%COLORS_COUNT;
++i;
}
auto paused;
paused = 0;
InitWindow(800, 600, "Hello, from B");
SetTargetFPS(60);
while (!WindowShouldClose()) {
if (IsKeyPressed(32)) {
paused = !paused;
}
if (!paused) {
i = 0; while (i < OBJS_COUNT) {
update_obj(&OBJS[(i++)*SIZE_OF_OBJ]);
}
}
BeginDrawing();
ClearBackground(0xFF181818);
i = 0; while (i < OBJS_COUNT) {
draw_obj(&OBJS[(i++)*SIZE_OF_OBJ]);
}
EndDrawing();
}
}
// libc
extrn malloc, rand;
// Raylib
extrn InitWindow, BeginDrawing, EndDrawing,
WindowShouldClose, ClearBackground,
SetTargetFPS, GetScreenWidth, GetScreenHeight,
DrawRectangle, IsKeyPressed;