Prev: 39958 Up: Map Next: 40153
40008: Set Magic Knight's velocity to zero, if appropriate move to new room, update state of storm cloud and execute room-specific routine
Used by the routines at 38205 and 38434.
40008 LD HL,0 Set Magic Knight's current x- and y-velocities to zero...
40011 LD (24844),HL ...
40014 CALL 39668 Check whether Magic Knight is moving into a new room and react if so
40017 LD A,(23702) If Magic Knight is currently in Bearwoolf's cave or hoard, or in Limbo then decrease Magic Knight's current strength by average of 1/4 if he is carrying the Glow Shield and jump to room-specific routine
40020 CP 3
40022 JP C,40190
40025 CP 17 If Magic Knight is currently in the Castle or the Spaceship then decrease Magic Knight's current strength by average of 1/4 if he is carrying the Glow Shield and jump to room-specific routine
40027 JP NC,40190
40030 LD A,(23702) If Magic Knight's current room...
40033 LD B,A ...
40034 LD A,(23715) ...is the same as the Storm Cloud's current room...
40037 CP B ...
40038 CALL Z,64637 ...then if do-not-draw-storm-cloud flag is set then prepare to draw Storm Cloud
40041 LD A,(23715) Load B with the Storm Cloud's current room as stored at 23715...
40044 LD B,A ...
40045 LD A,(23700) Load C with Storm Cloud's current x-coordinate...
40048 LD C,A ...
40049 LD A,(23702) Load H with Magic Knight's current room...
40052 LD H,A ...
40053 LD A,(24840) Load L with Magic Knight's current x-coordinate (pixels)...
40056 LD L,A ...
40057 XOR A Set A to zero and reset carry flag
40058 SBC HL,BC If Magic Knight and Storm Cloud have the same horizontal position in the same room...
40060 JR Z,40102 ...then skip ahead to 40102 (have a lightning bolt strike Magic Knight)
40062 JP P,40068 If Magic Knight is to the right of the Storm Cloud then skip ahead to 40068
40065 DEC BC Move the Storm Cloud one pixel to the left, changing room if appropriate
40066 JR 40069 Skip ahead to 40069
40068 INC BC Move the Storm Cloud one pixel to the right, changing room if appropriate
40069 LD A,B Load A with Storm Cloud's current room in B...
40070 LD (23715),A ...and store at 23715
40073 LD A,C Load A with Storm Cloud's current x-coordinate in C...
40074 LD (23700),A ...and store at 23700
40077 CP 32 If Storm Cloud's current x-coordinate is less than 32...
40079 JP C,40091 ...then skip ahead to 40091
40082 CP 223 If Storm Cloud's current x-coordinate is at least 223...
40084 JP NC,40094 ...then skip ahead to 40094
40087 SUB 30 Subtract 30 from A (Storm Cloud's current x-coordinate)
40089 JR 40096 Skip ahead to 40096
40091 XOR A Load A with zero
40092 JR 40096 Skip ahead to 40096
40094 LD A,195 Load A with 195
40096 LD (23701),A Store new apparent x-coordinate at 23701
40099 JP 40190 Decrease Magic Knight's current strength by average of 1/4 if he is carrying the Glow Shield and jump to room-specific routine
40102 LD A,255 Store 255 at 23694 and 23696...
40104 LD (23696),A ...to preserve attributes already on screen...
40107 LD (23694),A ...
40110 LD A,(23701) Load C with apparent x-coordinate stored previously...
40113 ADD A,30 ...and add 30...
40115 LD C,A ...to give x-coordinate of origin of lightning bolt
40116 LD B,119 Load B with 119 (y-coordinate of origin of lightning bolt)
40118 LD A,(24840) Load E with Magic Knight's current x-coordinate (pixels) plus eight...
40121 ADD A,8 ...(x-coordinate of target of lightning bolt)...
40123 LD E,A ...
40124 LD A,(24841) Load A with Magic Knight's current y-coordinate (pixels)
40127 SUB 175 Subtract y-coordinate from 175 to change y-origin to top of screen...
40129 NEG ...and have y-coordinate increase downwards rather than upwards
40131 LD D,A Load D with result
40132 PUSH BC Store BC (coordinates of lightning bolt origin)
40133 PUSH DE Store DE (coordinates of lightning bolt target)
40134 CALL 48360 Draw the lightning bolt
40137 LD B,20 Wait for 20 interrupts...
40139 HALT ...
40140 DJNZ 40139 ...
40142 POP DE Restore DE (coordinates of lightning bolt target)
40143 POP BC Restore BC (coordinates of lightning bolt origin)
40144 CALL 48360 Erase the lightning bolt drawn previously
40147 CALL 40153 Decrease Magic Knight's current strength by ten
40150 JP 40190 Decrease Magic Knight's current strength by average of 1/4 if he is carrying the Glow Shield and jump to room-specific routine
Prev: 39958 Up: Map Next: 40153