SHOW:
|
|
- or go back to the newest paste.
1 | - | local rect = graydraw.rect |
1 | + | local rect = graydraw.rect |
2 | - | local setColor = graydraw.setcolor |
2 | + | local setColor = graydraw.setcolor |
3 | - | local wait = misc.wait |
3 | + | local wait = misc.wait |
4 | - | local line = graydraw.line |
4 | + | local line = graydraw.line |
5 | - | local graytext = graydraw.text |
5 | + | local graytext = graydraw.text |
6 | - | local fill = graydraw.fill |
6 | + | local fill = graydraw.fill |
7 | - | local pixel = graydraw.pixel |
7 | + | local pixel = graydraw.pixel |
8 | - | local random = misc.random |
8 | + | local random = misc.random |
9 | - | |
9 | + | |
10 | - | |
10 | + | |
11 | - | car = {height = 8, width = 8, sprite = "\000\000<((f^fz(<V<(jvNnr8<V\000"} |
11 | + | car = {height = 8, width = 8, sprite = "\000\000<((f^fz(<V<(jvNnr8<V\000"} |
12 | - | |
12 | + | |
13 | - | |
13 | + | |
14 | - | screenWidth = 128 |
14 | + | screenWidth = 128 |
15 | - | screenHeight = 64 |
15 | + | screenHeight = 64 |
16 | - | |
16 | + | |
17 | - | ai = {x = {}, y = {}, speed = {}, topspeed = {}, number = 3} |
17 | + | ai = {x = {}, y = {}, speed = {}, topspeed = {}, number = 3} |
18 | - | continue = 0 |
18 | + | continue = 0 |
19 | - | done = 0 |
19 | + | done = 0 |
20 | - | gDoorPosition = {0,0,0} |
20 | + | gDoorPosition = {0,0,0} |
21 | - | gDoorText = {"Play", "Optn", "Help"} |
21 | + | gDoorText = {"Play", "Optn", "Help"} |
22 | - | gDoorActive = 1 |
22 | + | gDoorActive = 1 |
23 | - | i = 0 |
23 | + | i = 0 |
24 | - | invert = 0 |
24 | + | invert = 0 |
25 | - | Key = 0 |
25 | + | Key = 0 |
26 | - | key_alpha = 33 |
26 | + | key_alpha = 33 |
27 | - | key_left = 37 |
27 | + | key_left = 37 |
28 | - | key_right = 40 |
28 | + | key_right = 40 |
29 | - | key_down = 38 |
29 | + | key_down = 38 |
30 | - | key_up = 39 |
30 | + | key_up = 39 |
31 | - | key_exit = 36 |
31 | + | key_exit = 36 |
32 | - | key_shift = 41 |
32 | + | key_shift = 41 |
33 | - | player = {x = 0, y = 0, speed = 0, topspeed = 6} |
33 | + | player = {x = 0, y = 0, speed = 0, topspeed = 6} |
34 | - | |
34 | + | |
35 | - | |
35 | + | |
36 | - | |
36 | + | |
37 | - | function main() |
37 | + | function main() |
38 | - | setColor(1) |
38 | + | setColor(1) |
39 | - | menu() |
39 | + | menu() |
40 | - | end |
40 | + | end |
41 | - | |
41 | + | |
42 | - | function menu() |
42 | + | function menu() |
43 | - | clear nil |
43 | + | clear nil |
44 | - | |
44 | + | |
45 | - | while done ~= 1 do |
45 | + | while done ~= 1 do |
46 | - | if key(key_left) then gDoorActive = gDoorActive - 1 wait(3) end |
46 | + | if key(key_left) then gDoorActive = gDoorActive - 1 wait(3) end |
47 | - | if key(key_right) then gDoorActive = gDoorActive + 1 wait(3) end |
47 | + | if key(key_right) then gDoorActive = gDoorActive + 1 wait(3) end |
48 | - | if key(key_exit) then done = 1 end |
48 | + | if key(key_exit) then done = 1 end |
49 | - | if key(key_shift) then selection = gDoorActive continue = 1 end |
49 | + | if key(key_shift) then selection = gDoorActive continue = 1 end |
50 | - | if gDoorActive < 1 then gDoorActive = 1 end |
50 | + | if gDoorActive < 1 then gDoorActive = 1 end |
51 | - | if gDoorActive > 3 then gDoorActive = 3 end |
51 | + | if gDoorActive > 3 then gDoorActive = 3 end |
52 | - | |
52 | + | |
53 | - | if selection == 1 then play() |
53 | + | if selection == 1 then play() |
54 | - | elseif selection == 2 then optn() |
54 | + | elseif selection == 2 then optn() |
55 | - | elseif selection == 3 then help() |
55 | + | elseif selection == 3 then help() |
56 | - | end |
56 | + | end |
57 | - | |
57 | + | |
58 | - | selection = 0 |
58 | + | selection = 0 |
59 | - | |
59 | + | |
60 | - | for i = 1, 3, 1 do |
60 | + | for i = 1, 3, 1 do |
61 | - | if i == gDoorActive and gDoorPosition[i] < 30 then gDoorPosition[i] = gDoorPosition[i] + 1 |
61 | + | if i == gDoorActive and gDoorPosition[i] < 30 then gDoorPosition[i] = gDoorPosition[i] + 1 |
62 | - | elseif gDoorPosition[i] > 0 then gDoorPosition[i] = gDoorPosition[i] - 1 end |
62 | + | elseif gDoorPosition[i] > 0 then gDoorPosition[i] = gDoorPosition[i] - 1 end |
63 | - | end |
63 | + | end |
64 | - | |
64 | + | |
65 | - | for ix = 1, 3, 1 do |
65 | + | for ix = 1, 3, 1 do |
66 | - | garageDoor(ix * 35 - 20, 25, 30, 30, gDoorPosition[ix], 5, gDoorText[ix], 5) |
66 | + | garageDoor(ix * 35 - 20, 25, 30, 30, gDoorPosition[ix], 5, gDoorText[ix], 5) |
67 | - | end |
67 | + | end |
68 | - | |
68 | + | |
69 | - | refresh2() |
69 | + | refresh2() |
70 | - | wait(1) |
70 | + | wait(1) |
71 | - | end |
71 | + | end |
72 | - | |
72 | + | |
73 | - | continue = 0 |
73 | + | continue = 0 |
74 | - | end |
74 | + | end |
75 | - | |
75 | + | |
76 | - | function garageDoor(x, y, width, height, position, panelHeight, text, margin) |
76 | + | function garageDoor(x, y, width, height, position, panelHeight, text, margin) |
77 | - | |
77 | + | |
78 | - | buffer = height/2 |
78 | + | buffer = height/2 |
79 | - | graytext(x + margin, y + buffer, text) --display text |
79 | + | graytext(x + margin, y + buffer, text) --display text |
80 | - | |
80 | + | |
81 | - | rect(x, y, x + width, y + height, 5, 5) --draw garage |
81 | + | rect(x, y, x + width, y + height, 5, 5) --draw garage |
82 | - | |
82 | + | |
83 | - | rect(x, y, x + width, y + height - position, 4, 0) --draw door |
83 | + | rect(x, y, x + width, y + height - position, 4, 0) --draw door |
84 | - | |
84 | + | |
85 | - | --draw panels |
85 | + | --draw panels |
86 | - | for iy = height - position, 0, -panelHeight do |
86 | + | for iy = height - position, 0, -panelHeight do |
87 | - | line(x, y + iy, x + width, y + iy, 4) |
87 | + | line(x, y + iy, x + width, y + iy, 4) |
88 | - | end |
88 | + | end |
89 | - | end |
89 | + | end |
90 | - | |
90 | + | |
91 | - | function play() |
91 | + | function play() |
92 | - | clear nil |
92 | + | clear nil |
93 | - | var = 0 |
93 | + | var = 0 |
94 | - | iy = 0 |
94 | + | iy = 0 |
95 | - | for i=1, ai.number, 1 do |
95 | + | for i=1, ai.number, 1 do |
96 | - | ai.y[i] = 0 |
96 | + | ai.y[i] = 0 |
97 | - | ai.x[i] = i*8+1 |
97 | + | ai.x[i] = i*8+1 |
98 | - | ai.topspeed[i] = 6 |
98 | + | ai.topspeed[i] = 6 |
99 | - | if i == 1 then ai.speed[i] = ai.topspeed[i] else ai.speed = 1 + random(ai.topspeed[i]) end |
99 | + | if i == 1 then ai.speed[i] = ai.topspeed[i] else ai.speed = 1 + random(ai.topspeed[i]) end |
100 | - | end |
100 | + | end |
101 | - | |
101 | + | |
102 | - | player.y = 0 |
102 | + | player.y = 0 |
103 | - | |
103 | + | |
104 | - | --[[-- |
104 | + | --[[-- |
105 | - | graytext(5, 5, "Please Wait...") |
105 | + | graytext(5, 5, "Please Wait...") |
106 | - | refresh2() |
106 | + | refresh2() |
107 | - | |
107 | + | |
108 | - | clear nil |
108 | + | clear nil |
109 | - | for iy=1, screenHeight, 1 do |
109 | + | for iy=1, screenHeight, 1 do |
110 | - | for ix = 1, screenWidth, 1 do |
110 | + | for ix = 1, screenWidth, 1 do |
111 | - | if i == 1 then pixel(ix, iy, 4) i = 0 else i = i + 1 end |
111 | + | if i == 1 then pixel(ix, iy, 4) i = 0 else i = i + 1 end |
112 | - | end |
112 | + | end |
113 | - | if i==0 then i = 1 else i = 0 end |
113 | + | if i==0 then i = 1 else i = 0 end |
114 | - | end |
114 | + | end |
115 | - | --]]-- |
115 | + | --]]-- |
116 | - | |
116 | + | |
117 | - | line(42, 0, 42, 64, 4) |
117 | + | line(42, 0, 42, 64, 4) |
118 | - | line(84, 0, 84, 64, 4) |
118 | + | line(84, 0, 84, 64, 4) |
119 | - | |
119 | + | |
120 | - | refresh2() |
120 | + | refresh2() |
121 | - | |
121 | + | |
122 | - | |
122 | + | |
123 | - | --game loop |
123 | + | --game loop |
124 | - | while not key(key_exit) do |
124 | + | while not key(key_exit) do |
125 | - | rect(43, 0, 83, 64, 0, 0) --clears only the road |
125 | + | rect(43, 0, 83, 64, 0, 0) --clears only the road |
126 | - | |
126 | + | |
127 | - | if key(key_left) and player.x > 0 then player.x = player.x - 1 |
127 | + | if key(key_left) and player.x > 0 then player.x = player.x - 1 |
128 | - | elseif key(key_right) and player.x < 40 - car.width + 1 then player.x = player.x + 1 |
128 | + | elseif key(key_right) and player.x < 40 - car.width + 1 then player.x = player.x + 1 |
129 | - | elseif key(key_shift) then player.speed = player.speed + 1 |
129 | + | elseif key(key_shift) then player.speed = player.speed + 1 |
130 | - | elseif key(key_alpha) then player.speed = player.speed - 1 |
130 | + | elseif key(key_alpha) then player.speed = player.speed - 1 |
131 | - | end |
131 | + | end |
132 | - | |
132 | + | |
133 | - | if player.speed > player.topspeed then player.speed = player.topspeed |
133 | + | if player.speed > player.topspeed then player.speed = player.topspeed |
134 | - | elseif player.speed < 0 then player.speed = 0 |
134 | + | elseif player.speed < 0 then player.speed = 0 |
135 | - | end |
135 | + | end |
136 | - | |
136 | + | |
137 | - | aiRace() |
137 | + | aiRace() |
138 | - | |
138 | + | |
139 | - | spritexy player.x + 43, screenHeight - car.height, car.sprite |
139 | + | spritexy player.x + 43, screenHeight - car.height, car.sprite |
140 | - | player.y = player.y + player.speed |
140 | + | player.y = player.y + player.speed |
141 | - | refresh2() |
141 | + | refresh2() |
142 | - | end |
142 | + | end |
143 | - | |
143 | + | |
144 | - | waitKey(key_exit) |
144 | + | waitKey(key_exit) |
145 | - | clear nil |
145 | + | clear nil |
146 | - | end |
146 | + | end |
147 | - | |
147 | + | |
148 | - | function aiRace() |
148 | + | function aiRace() |
149 | - | for i=1, ai.number, 1 do |
149 | + | for i=1, ai.number, 1 do |
150 | - | --ai and collisions with ai |
150 | + | --ai and collisions with ai |
151 | - | for j=1, ai.number do |
151 | + | for j=1, ai.number do |
152 | - | --if car i is not the same as car j |
152 | + | --if car i is not the same as car j |
153 | - | if i~=j then |
153 | + | if i~=j then |
154 | - | --if car j is in front or behind car i |
154 | + | --if car j is in front or behind car i |
155 | - | if ai.x[j] > ai.x[i] - 16 and ai.x[j] < ai.x[i] + 16 then |
155 | + | if ai.x[j] > ai.x[i] - 16 and ai.x[j] < ai.x[i] + 16 then |
156 | - | --if car j is in front |
156 | + | --if car j is in front |
157 | - | if ai.y[j] > ai.y[i] and ai.y[j] < ai.y[i] + 16 then |
157 | + | if ai.y[j] > ai.y[i] and ai.y[j] < ai.y[i] + 16 then |
158 | - | if ai.speed[i] > 0 then ai.speed[i] = ai.speed[i] - 1 else ai.x[i] = ai.x[i] + 1 end |
158 | + | if ai.speed[i] > 0 then ai.speed[i] = ai.speed[i] - 1 else ai.x[i] = ai.x[i] + 1 end |
159 | - | end |
159 | + | end |
160 | - | --if car j is behind |
160 | + | --if car j is behind |
161 | - | if ai.y[j] < ai.y[i] and ai.y[j] > ai.y[i] - 16 then |
161 | + | if ai.y[j] < ai.y[i] and ai.y[j] > ai.y[i] - 16 then |
162 | - | if ai.speed[i] < ai.topspeed[i] then ai.speed[i] = ai.speed[i] + 1 else ai.x[i] = ai.x - 1 end |
162 | + | if ai.speed[i] < ai.topspeed[i] then ai.speed[i] = ai.speed[i] + 1 else ai.x[i] = ai.x - 1 end |
163 | - | end |
163 | + | end |
164 | - | end |
164 | + | end |
165 | - | --if car j is left or right of car i |
165 | + | --if car j is left or right of car i |
166 | - | if ai.y[j] > ai.y[i] - 16 and ai.y[j] < ai.y[i] + 16 then |
166 | + | if ai.y[j] > ai.y[i] - 16 and ai.y[j] < ai.y[i] + 16 then |
167 | - | --if car j is to the right |
167 | + | --if car j is to the right |
168 | - | if ai.x[j] > ai.x[i] and ai.x[j] < ai.x[i] + 16 then |
168 | + | if ai.x[j] > ai.x[i] and ai.x[j] < ai.x[i] + 16 then |
169 | - | --if the car i is not against the left wall |
169 | + | --if the car i is not against the left wall |
170 | - | if ai.x[i] > 0 then ai.x[i] = ai.x[i] - 1 elseif ai.speed > 0 then ai.speed[i] = ai.speed[i] - 1 end |
170 | + | if ai.x[i] > 0 then ai.x[i] = ai.x[i] - 1 elseif ai.speed > 0 then ai.speed[i] = ai.speed[i] - 1 end |
171 | - | end |
171 | + | end |
172 | - | --if car j is to the left |
172 | + | --if car j is to the left |
173 | - | if ai.x[j] < ai.x[i] and ai.x[j] > ai.x[i] - 16 then |
173 | + | if ai.x[j] < ai.x[i] and ai.x[j] > ai.x[i] - 16 then |
174 | - | --if car i is not against right wall |
174 | + | --if car i is not against right wall |
175 | - | if ai.x[i] < 40 then ai.x[i] = ai.x[i] + 1 elseif ai.speed > 0 then ai.speed[i] = ai.speed[i] - 1 end |
175 | + | if ai.x[i] < 40 then ai.x[i] = ai.x[i] + 1 elseif ai.speed > 0 then ai.speed[i] = ai.speed[i] - 1 end |
176 | - | end |
176 | + | end |
177 | - | end |
177 | + | end |
178 | - | end |
178 | + | end |
179 | - | end |
179 | + | end |
180 | - | --collisions with player |
180 | + | --collisions with player |
181 | - | if ai.y[i] > player.y and ai.y[i] < player.y + 8 and ai.x[i] > player.x and ai.x[i] < player.x + 8 then crash() end |
181 | + | if ai.y[i] > player.y and ai.y[i] < player.y + 8 and ai.x[i] > player.x and ai.x[i] < player.x + 8 then crash() end |
182 | - | |
182 | + | |
183 | - | --display |
183 | + | --display |
184 | - | buffer = ai.y[i] - player.y |
184 | + | buffer = ai.y[i] - player.y |
185 | - | spritexy ai.x[i] + 43, screenHeight - car.height - buffer, car.sprite |
185 | + | spritexy ai.x[i] + 43, screenHeight - car.height - buffer, car.sprite |
186 | - | ai.y[i] = ai.y[i] + ai.speed[i] |
186 | + | ai.y[i] = ai.y[i] + ai.speed[i] |
187 | - | end |
187 | + | end |
188 | - | |
188 | + | |
189 | - | end |
189 | + | end |
190 | - | |
190 | + | |
191 | - | function crash() |
191 | + | function crash() |
192 | - | clear nil |
192 | + | clear nil |
193 | - | graytext(1, 1, "You Died!") |
193 | + | graytext(1, 1, "You Died!") |
194 | - | refresh2() |
194 | + | refresh2() |
195 | - | wait(100) |
195 | + | wait(100) |
196 | - | menu() |
196 | + | menu() |
197 | - | end |
197 | + | end |
198 | - | |
198 | + | |
199 | - | function optn() |
199 | + | function optn() |
200 | - | clear nil |
200 | + | clear nil |
201 | - | graytext(1, 1, "Options Menu") |
201 | + | graytext(1, 1, "Options Menu") |
202 | - | refresh2() |
202 | + | refresh2() |
203 | - | waitKey(key_exit) |
203 | + | waitKey(key_exit) |
204 | - | clear nil |
204 | + | clear nil |
205 | - | end |
205 | + | end |
206 | - | |
206 | + | |
207 | - | function help() |
207 | + | function help() |
208 | - | clear nil |
208 | + | clear nil |
209 | - | graytext(1, 1, "How may I help you?") |
209 | + | graytext(1, 1, "How may I help you?") |
210 | - | refresh2() |
210 | + | refresh2() |
211 | - | waitKey(key_exit) |
211 | + | waitKey(key_exit) |
212 | - | clear nil |
212 | + | clear nil |
213 | - | end |
213 | + | end |
214 | - | |
214 | + | |
215 | - | function bye() |
215 | + | function bye() |
216 | - | clear nil |
216 | + | clear nil |
217 | - | graytext(1, 1, "Bye!") |
217 | + | graytext(1, 1, "Bye!") |
218 | - | refresh2() |
218 | + | refresh2() |
219 | - | wait(100) |
219 | + | wait(100) |
220 | - | end |
220 | + | end |
221 | - | |
221 | + | |
222 | - | function waitKey(Key) |
222 | + | function waitKey(Key) |
223 | - | while not key(Key) do wait(3) end |
223 | + | while not key(Key) do wait(3) end |
224 | - | wait(3) |
224 | + | wait(3) |
225 | - | end |
225 | + | end |
226 | - | |
226 | + | |
227 | - | function refresh2() |
227 | + | function refresh2() |
228 | - | --if invert == 1 then rect(0, 0, screenWidth, screenHeight) end |
228 | + | --if invert == 1 then rect(0, 0, screenWidth, screenHeight) end |
229 | - | if invert == 1 then fill(5) end |
229 | + | if invert == 1 then fill(5) end |
230 | - | refresh |
230 | + | refresh |
231 | - | end |
231 | + | end |
232 | - | |
232 | + | |
233 | main() |