-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOXTEST.ELPC
128 lines (100 loc) · 2.08 KB
/
BOXTEST.ELPC
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
' Bounding box collision tester
' -----------------------------
#output "boxtest"
'------------
.declarations
'------------
#declare x1, y1, x2, y2
#declare x, y, idx, a$, xinc, yinc
#struct BOX x1, y1, x2, y2
#define BOX1 = 0
#define BOX2 = 1
#define X1 = 0
#define Y1 = 1
#define X2 = 2
#define Y2 = 3
#declare bx(2,3)
bx(BOX1, X1) = 5
bx(BOX1, Y1) = 5
bx(BOX1, X2) = 10
bx(BOX1, Y2) = 10
bx(BOX2, X1) = 15
bx(BOX2, Y1) = 15
bx(BOX2, X2) = 20
bx(BOX2, Y2) = 20
#define KEY_UP = "{x91}"
#define KEY_DOWN = "{x11}"
#define KEY_LEFT = "{x9D}"
#define KEY_RIGHT = "{x1D}"
'----
.main
'----
print chr$(147);chr$(142);
do while 1
gosub draw_boxes
gosub check_box_collision
gosub get_user_input
loop
'-------------------
.check_box_collision
'-------------------
if not (bx(BOX2, X1) > bx(BOX1, X2) or {x5F}
bx(BOX2, X2) < bx(BOX1, X1) or {x5F}
bx(BOX2, Y1) > bx(BOX1, Y2) or {x5F}
bx(BOX2, Y2) < bx(BOX1, Y1)) then {x5F}
begin
border 2
bend:else begin
border 7
bend
return
'--------------
.get_user_input
'--------------
get key a$
xinc = 0
yinc = 0
if a$ = KEY_UP then yinc = -1
if a$ = KEY_DOWN then yinc = 1
if a$ = KEY_LEFT then xinc = -1
if a$ = KEY_RIGHT then xinc = 1
bx(BOX1, X1) = bx(BOX1, X1) + xinc
bx(BOX1, Y1) = bx(BOX1, Y1) + yinc
bx(BOX1, X2) = bx(BOX1, X2) + xinc
bx(BOX1, Y2) = bx(BOX1, Y2) + yinc
bend
'----------
.draw_boxes
'----------
print chr$(147);
for idx = BOX1 to BOX2
x1 = bx(idx, X1)
y1 = bx(idx, Y1)
x2 = bx(idx, X2)
y2 = bx(idx, Y2)
gosub draw_box
next idx
return
'--------
.draw_box
'--------
' draw corners
' ------------
cursor x1, y1 : print "{x12}°";
cursor x2, y1 : print "{x12}®";
cursor x1, y2 : print "{x12}";
cursor x2, y2 : print "{x12}½";
' draw horizontals
' ----------------
for x = x1+1 to x2-1
cursor x,y1 : print "{x12}À";
cursor x,y2 : print "{x12}C";
next x
' draw verticals
' --------------
for y = y1+1 to y2-1
cursor x1,y : print "{x12}B";
cursor x2,y : print "{x12}B";
next y
return
ÿ