-
Notifications
You must be signed in to change notification settings - Fork 0
/
score.fs
70 lines (62 loc) · 1.49 KB
/
score.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
VARIABLE score-image
CREATE score-rect SDL_Rect ALLOT
CREATE score-color SDL_Color ALLOT
24 CONSTANT score-font-size
VARIABLE score-font
VARIABLE score 0 score !
: score-cleanup ( -- )
score-font @ TTF_CloseFont
score-image @ SDL_DestroyTexture
;
: score-update ( -- error )
score-image @ SDL_DestroyTexture
0 score-image !
score-font @
s" Score: " PAD PLACE
score @ 0 <<# #s #> #>> PAD +PLACE
s\" \0" PAD +PLACE
PAD COUNT DROP
score-color TTF_RenderText_Blended DUP @ 0= IF
." Error creating font surface: " SDL_GetError c-str> TYPE CR
DROP
TRUE
ELSE
score-rect rect-from-surface
10 score-rect SDL_Rect-x int32>!
10 score-rect SDL_Rect-y int32>!
score-image SWAP texture-from-surface IF
TRUE
ELSE
FALSE
THEN
THEN
;
: score-reset ( -- error )
0 score !
score-update
;
: score-increment ( -- error )
1 score @ + score !
score-update
;
: score-init ( -- error )
score-color
255 OVER SDL_Color-r C!
255 OVER SDL_Color-g C!
255 OVER SDL_Color-b C!
255 SWAP SDL_Color-a C!
s" fonts/freesansbold.ttf" >c-str score-font-size TTF_OpenFont score-font !
score-font @ 0= IF
." Error creating font: " SDL_GetError c-str> TYPE CR
FALSE
ELSE
score-update IF
FALSE
ELSE
TRUE
THEN
THEN
;
: score-draw ( -- )
renderer @ score-image @ 0 score-rect SDL_RenderCopy DROP
;