-
Notifications
You must be signed in to change notification settings - Fork 0
/
flakes.fs
99 lines (85 loc) · 2.63 KB
/
flakes.fs
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
VARIABLE white-image
VARIABLE yellow-image
300e FCONSTANT flake-speed
10 CONSTANT white-length
5 CONSTANT yellow-length
CREATE white-array white-length SDL_Rect * ALLOT
CREATE yellow-array yellow-length SDL_Rect * ALLOT
CREATE white-farray white-length 2 * CELLS ALLOT
CREATE yellow-farray yellow-length 2 * CELLS ALLOT
white-farray white-length 2 * CELLS 0 FILL
yellow-farray yellow-length 2 * CELLS 0 FILL
: flakes-cleanup ( -- )
white-image @ SDL_DestroyTexture
yellow-image @ SDL_DestroyTexture
;
: flake-reset { address faddress range -- }
SCREEN_WIDTH address SDL_Rect-w int32<@ - random DUP address SDL_Rect-x int32>!
S>F faddress F!
0 address SDL_Rect-h int32<@ - range random - DUP address SDL_Rect-y int32>!
S>F faddress CELL + F!
;
: flakes-array-init ( array-adress length -- )
0 DO
DUP SDL_Rect I * +
OVER SDL_Rect-w int32<@ OVER SDL_Rect-w int32>!
OVER SDL_Rect-h int32<@ SWAP SDL_Rect-h int32>!
LOOP DROP
;
: flakes-array-reset { array farray length -- }
length 0 DO
array SDL_Rect I * +
farray 2 I * FLOATS +
SCREEN_HEIGHT 2 * flake-reset
LOOP
;
: flakes-reset ( -- )
white-array white-farray white-length flakes-array-reset
yellow-array yellow-farray yellow-length flakes-array-reset
;
: flakes-init ( -- error )
white-array white-image s" images/white.png" >c-str load-texture-and-rect
IF
yellow-array yellow-image s" images/yellow.png" >c-str load-texture-and-rect
IF
white-array white-length flakes-array-init
yellow-array yellow-length flakes-array-init
TRUE
ELSE
FALSE
THEN
ELSE
FALSE
THEN
;
: flake-left ( a -- n )
SDL_Rect-x int32<@
;
: flake-right ( a -- n )
DUP SDL_Rect-x int32<@ SWAP SDL_Rect-w int32<@ +
;
: flake-bottom ( a -- n )
DUP SDL_Rect-y int32<@ SWAP SDL_Rect-h int32<@ +
;
: flakes-array-update { array farray range -- }
range 0 DO
array SDL_Rect I * +
farray I 2 * CELLS +
DUP CELL + { flake xpos ypos }
ypos F@ flake-speed delta-time F@ F* F+ FDUP ypos F!
F>S flake SDL_Rect-y int32>!
550 flake flake-bottom < IF flake xpos SCREEN_HEIGHT flake-reset THEN
LOOP
;
: flakes-update ( -- )
white-array white-farray white-length flakes-array-update
yellow-array yellow-farray yellow-length flakes-array-update
;
: flakes-draw ( -- )
white-length 0 DO
renderer @ white-image @ 0 SDL_Rect I * white-array + SDL_RenderCopy DROP
LOOP
yellow-length 0 DO
renderer @ yellow-image @ 0 SDL_Rect I * yellow-array + SDL_RenderCopy DROP
LOOP
;