Prev: 57176 Up: Map Next: 57383
57240: Handle Falling Stalactite
Handler for the object type 80 a stalactite that falls from the ceiling towards Sabreman (see Spawn_Falling_Stalactite).
The y velocity (byte 9) goes up by two on every call, to a limit of 109 and the y position and its fraction (byte 13) change by sixteen times the velocity. The stalactite lands on a decoration if it touches the top of one near the middle of it. It lands on the floor if the room has one, and if the room has no floor it falls into the room below. When it lands it becomes the type 81 (see Handle_Rock_Fragments) and is not a stalactite any more.
If Sabreman is not in the room the stalactite carries on falling but is not drawn. The countdown in byte 10 which is reset to 80 while Sabreman is in the room, removes it when he has been away for long enough.
Input
IX Object record
Handle_Falling_Stalactite 57240 CALL StoreEntity Save the state of the stalactite.
57243 LD A,(IX+9) Fetch the y velocity.
57246 ADD A,2 Add two to the y velocity, as gravity pulls the stalactite down.
57248 CP 110 Jump to Handle_Falling_Stalactite_Move if the stalactite is falling at full speed (the y velocity has reached 110).
57250 JR NC,Handle_Falling_Stalactite_Move
57252 LD (IX+9),A Store the y velocity.
Handle_Falling_Stalactite_Move 57255 LD L,(IX+9) Fetch the y velocity into L.
57258 LD H,0 Clear the high byte of the y velocity (as a word).
57260 ADD HL,HL Multiply the y velocity by sixteen.
57261 ADD HL,HL
57262 ADD HL,HL
57263 ADD HL,HL
57264 LD C,(IX+13) Fetch the fraction of the y position.
57267 LD B,(IX+3) Fetch the y position.
57270 ADD HL,BC Add the y velocity.
57271 LD (IX+13),L Store the new fraction of the y position.
57274 LD (IX+3),H Store the new y position.
57277 CALL Read_World_Map Read the world map entry of the room that the stalactite is in. The flags of the room are returned in E.
57280 LD A,E Copy the flags of the room to A.
57281 AND %00010000 Keep only bit 4 (the floor).
57283 LD A,H Fetch the new y position.
57284 JR Z,Handle_Falling_Stalactite_No_Floor Jump to Handle_Falling_Stalactite_No_Floor if the room has no floor.
57286 CP 159 Jump to Handle_Falling_Stalactite_Land_On_Floor if the stalactite has reached the floor.
57288 JR NC,Handle_Falling_Stalactite_Land_On_Floor
57290 JR Handle_Falling_Stalactite_Check_Decorations Jump to Handle_Falling_Stalactite_Check_Decorations.
Handle_Falling_Stalactite_No_Floor 57292 CP 191 Jump to Handle_Falling_Stalactite_Next_Room if the stalactite has fallen out of the bottom of the room.
57294 JP NC,Handle_Falling_Stalactite_Next_Room
Handle_Falling_Stalactite_Check_Decorations 57297 CALL Check_Decoration_Contact Check for contact with the decorations.
57300 BIT 1,C Jump to Handle_Falling_Stalactite_Check_Room if the stalactite is not on top of a decoration.
57302 JR Z,Handle_Falling_Stalactite_Check_Room
57304 BIT 0,C Jump to Handle_Falling_Stalactite_Check_Room if the stalactite is not near the middle of the decoration.
57306 JR NZ,Handle_Falling_Stalactite_Check_Room
57308 LD A,B Copy 160 less the y position of the top of the decoration to A.
57309 NEG Negate it.
57311 ADD A,161 Add 161 to get the y position just below the top of the decoration.
57313 JR Handle_Falling_Stalactite_Shatter Jump to Handle_Falling_Stalactite_Shatter.
Handle_Falling_Stalactite_Land_On_Floor 57315 LD A,(IX+3) Fetch the y position.
57318 AND %11111000 Round it down to a multiple of eight.
57320 DEC A Subtract one.
Handle_Falling_Stalactite_Shatter 57321 LD (IX+3),A Store the y position.
57324 LD (IX+0),81 Change the stalactite into the first piece of rock.
57328 LD (IX+6),0 Reset the counter in byte 6.
Handle_Falling_Stalactite_Check_Room 57332 LD A,(36636) Fetch the room x of Sabreman.
57335 CP (IX+2) Jump to Handle_Falling_Stalactite_Count_Down if the stalactite is in a different room x.
57338 JP NZ,Handle_Falling_Stalactite_Count_Down
57341 LD A,(36638) Fetch the room y of Sabreman.
57344 CP (IX+4) Jump to Handle_Falling_Stalactite_Count_Down if the stalactite is in a different room y.
57347 JP NZ,Handle_Falling_Stalactite_Count_Down
57350 LD (IX+10),80 Reset the countdown to 80.
57354 JP Update_Object_Sprite Jump to Update_Object_Sprite.
Handle_Falling_Stalactite_Next_Room 57357 LD (IX+3),64 Set the y position to 64.
57361 INC (IX+4) Move the stalactite to the room below.
57364 BIT 0,(IX+15) Return if the stalactite has not been drawn yet.
57368 RET NZ
57369 JP RemoveEntity Erase the sprite of the stalactite.
Handle_Falling_Stalactite_Count_Down 57372 DEC (IX+10) Decrease the countdown and jump to Remove_Unseen_Weapon to remove the stalactite when it reaches zero.
57375 JP Z,Remove_Unseen_Weapon
57378 SET 0,(IX+15) Set bit 0 of the redraw flags, as the stalactite is not on the screen.
57382 RET Return.
Prev: 57176 Up: Map Next: 57383