Routines |
Prev: 25129 | Up: Map | Next: 25399 |
Called from the main loop at 25129.
|
||||
25167 | LD A,(31865) | Pick up the tunnel timer. | ||
25170 | AND A | Is Horace in a tunnel at the moment? | ||
25171 | RET NZ | Return if so. | ||
25172 | LD A,255 | Initialise the direction keypress to 'no key'. | ||
25174 | LD (31855),A | |||
25177 | LD A,(27403) | Pick up the game mode indicator. | ||
25180 | AND A | Is it demo mode? | ||
25181 | JR NZ,25284 | Jump if not. | ||
25183 | LD A,0 | Read the keyboard. | ||
25185 | IN A,(254) | |||
25187 | AND 31 | Is a key being pressed? | ||
25189 | CP 31 | |||
25191 | JR Z,25197 | Jump if not. | ||
25193 | POP HL | Drop the return address from the stack. | ||
25194 | JP 26601 | Cycle the screen colours briefly and return to the title screen. | ||
It's demo mode. Time to figure out where to move Horace next.
|
||||
25197 | LD B,4 | Initialise B (the direction indicator) for the loop that follows. | ||
25199 | DEC B | B=3 (left), 2 (down), 1 (right) or 0 (up). | ||
25200 | LD HL,(31851) | Pick up Horace's current location. | ||
25203 | LD C,0 | Initialise C to 0; this is the direction probability parameter. | ||
25205 | PUSH BC | Save the direction indicator briefly. | ||
25206 | LD A,B | Copy the direction indicator to A. | ||
25207 | CALL 27842 | Check the tiles next to Horace in that direction. | ||
25210 | POP BC | Restore the direction indicator to B. | ||
25211 | CP 2 | Is there a wall or the maze exit or entrance in that direction? | ||
25213 | JP NC,25247 | Jump if so with C=0: that direction is blocked. | ||
25216 | CALL 27410 | Set C to a pseudo-random number between 25 and 56; the higher this value, the more likely Horace will turn 90 degrees in the direction indicated by B when his path is blocked. | ||
25219 | AND 31 | |||
25221 | ADD A,25 | |||
25223 | LD C,A | |||
25224 | LD A,(31856) | Pick up Horace's animation frame. | ||
25227 | CP B | Is it equal to the current value of the direction indicator? | ||
25228 | JR NZ,25236 | Jump if not. | ||
25230 | LD A,40 | Now C holds a pseudo-random number between 65 and 96; this value ensures that Horace will keep moving in the same direction if he can. | ||
25232 | ADD A,C | |||
25233 | LD C,A | |||
25234 | JR 25247 | |||
25236 | ADD A,2 | Add 2 to Horace's animation frame; this has the effect of toggling his direction between up/down and left/right. | ||
25238 | AND 3 | |||
25240 | CP B | Is it equal to the current value of the direction indicator now? | ||
25241 | JR NZ,25247 | Jump if not. | ||
25243 | LD A,246 | Now C holds a pseudo-random number between 15 and 46; the higher this value, the more likely Horace will turn round 180 degrees when his path is blocked. | ||
25245 | ADD A,C | |||
25246 | LD C,A | |||
25247 | PUSH BC | Save the direction indicator briefly. | ||
25248 | LD HL,28082 | Point HL at one of the four slots at 28082. | ||
25251 | LD C,B | |||
25252 | LD B,0 | |||
25254 | ADD HL,BC | |||
25255 | POP BC | Restore the direction indicator to B. | ||
25256 | LD A,C | Save the direction probability parameter in the appropriate slot. | ||
25257 | LD (HL),A | |||
25258 | INC B | Have we considered every direction yet? | ||
25259 | DEC B | |||
25260 | JR NZ,25199 | Jump back if not. | ||
Having computed a direction probability parameter for each of the four slots at 28082, we now use those parameters to determine Horace's next animation frame (and therefore direction of travel).
|
||||
25262 | XOR A | Compute in C the index of the slot that holds the largest number (0, 1, 2 or 3). | ||
25263 | LD HL,28086 | |||
25266 | LD B,4 | |||
25268 | DEC B | |||
25269 | DEC HL | |||
25270 | CP (HL) | |||
25271 | JR NC,25275 | |||
25273 | LD A,(HL) | |||
25274 | LD C,B | |||
25275 | INC B | |||
25276 | DEC B | |||
25277 | JR NZ,25268 | |||
25279 | LD A,C | Update Horace's animation frame to this index value. | ||
25280 | LD (31856),A | |||
25283 | RET | |||
A game is in progress.
|
||||
25284 | LD A,251 | Read keys Q-W-E-R-T. | ||
25286 | IN A,(254) | |||
25288 | AND 1 | Is 'Q' (up) being pressed? | ||
25290 | JR Z,25300 | Jump if so. | ||
25292 | LD A,247 | Read keys 1-2-3-4-5. | ||
25294 | IN A,(254) | |||
25296 | AND 8 | Is '4' (up) being pressed? | ||
25298 | JR NZ,25307 | Jump if not. | ||
25300 | LD A,0 | Signal: 'up' key pressed. | ||
25302 | LD (31855),A | |||
25305 | JR 25374 | |||
25307 | LD A,254 | Read keys SHIFT-Z-X-C-V. | ||
25309 | IN A,(254) | |||
25311 | AND 2 | Is 'Z' (down) being pressed? | ||
25313 | JR Z,25323 | Jump if so. | ||
25315 | LD A,247 | Read keys 1-2-3-4-5. | ||
25317 | IN A,(254) | Is '3' (down) being pressed? | ||
25319 | AND 4 | Jump if not. | ||
25321 | JR NZ,25330 | |||
25323 | LD A,2 | Signal: 'down' key pressed. | ||
25325 | LD (31855),A | |||
25328 | JR 25374 | |||
25330 | LD A,223 | Read keys Y-U-I-O-P. | ||
25332 | IN A,(254) | |||
25334 | BIT 0,A | Is 'P' (right) being pressed? | ||
25336 | JR Z,25346 | Jump if so. | ||
25338 | LD A,247 | Read keys 1-2-3-4-5. | ||
25340 | IN A,(254) | |||
25342 | AND 2 | Is '2' (right) being pressed? | ||
25344 | JR NZ,25353 | Jump if not. | ||
25346 | LD A,1 | Signal: 'right' key pressed. | ||
25348 | LD (31855),A | |||
25351 | JR 25374 | |||
25353 | LD A,223 | Read keys Y-U-I-O-P. | ||
25355 | IN A,(254) | |||
25357 | BIT 2,A | Is 'I' (left) being pressed? | ||
25359 | JR Z,25369 | Jump if so. | ||
25361 | LD A,247 | Read keys 1-2-3-4-5. | ||
25363 | IN A,(254) | |||
25365 | AND 1 | Is '1' (left) being pressed? | ||
25367 | JR NZ,25389 | Jump if not. | ||
25369 | LD A,3 | Signal: 'left' key pressed. | ||
25371 | LD (31855),A | |||
25374 | LD HL,(31851) | Pick up Horace's current location. | ||
25377 | CALL 27842 | Check the tiles in front of Horace. | ||
25380 | CP 3 | Is Horace facing a wall? | ||
25382 | JR NZ,25389 | Jump if not. | ||
25384 | LD A,255 | Signal: no key pressed (Horace will not respond to the keypress). | ||
25386 | LD (31855),A | |||
25389 | LD A,(31855) | Pick up the direction keypress indicator. | ||
25392 | CP 255 | Was a direction key pressed? | ||
25394 | RET Z | Return if not. | ||
25395 | LD (31856),A | Otherwise update Horace's animation frame accordingly. | ||
25398 | RET |
Prev: 25129 | Up: Map | Next: 25399 |