-
Notifications
You must be signed in to change notification settings - Fork 20
Salvo the Slime
Salvo generates slime sprites whenever an egg or a spat slime is colliding with him. The two act a bit differently as far as the timing of it.
Either way, a global slime generation timer at memory address $7E10B8 gets initialized to $00 upon initial collision. From there, if it's an egg, the timer keeps increasing every frame until the egg has passed through, and the code checks for timer AND $03 == 0, meaning every 4 frames, a slime is generated:
LDA $10B8 ; $06880F | slime generation timer
AND #$0003 ; $068812 | every 4 frames a slime spawns
ORA $10B6 ; $068815 |
BNE CODE_06886C ; $068818 |
In the case of the spat slime, the same code above is run hence it checks for 0, but the difference is that the timer will alternate 0, 1, 0, 1, ... instead of steadily increasing like the egg does. Because it keeps getting reset to 0 every other frame, this makes spat slime generation a bit quicker: every other frame.
The generated slime has some values put into it; initially it spawns at the egg/spat slime location and it is in a "falling" state. Some RNG is used here for the velocities: namely, X velocity will be a random value from -256 to 255, and Y velocity will be a random value from -1023 to 0. The X velocity is used for which way to face:
SBC #$0100 ; $068893 | rand [-256, 256)
STA $71E0,y ; $068896 | -> x velocity
BMI CODE_0688A1 ; $068899 |
LDA #$0002 ; $06889B | face right if velocity positive
STA $73C0,y ; $06889E |
CODE_0688A1:
PLA ; $0688A1 | \
XBA ; $0688A2 | |
AND #$03FF ; $0688A3 | | -rand [0, 1024)
EOR #$FFFF ; $0688A6 | | -> y velocity
INC A ; $0688A9 | |
STA $71E2,y ; $0688AA | /
This is just initial falling velocity of course; when they reach the ground they all crawl at the same speeds.