Hi RetroBro,
I think you've got the main gist of it in your goal description! Here are some (purely conceptual) code snippets as to how I would be tackling this. This assumes that you already declared a variable (User variable, Zero Page variable or Overflow RAM) with the name
buckshot. Also, please, do not blindly copy-and-paste these scripts (they are untested and may not work as intended for your specific project) but rather use them as a reference when you're going to add the buckshot to your game.
1) When the player collides with your pickup object, you'd want to activate the buckshot by setting the variable, and then destroy the pickup object:
Code:
;; Activate the buckshot by setting the variable to 1
LDA #$01
STA buckshot
;; Remove the pickup
DestroyObject
Note: this assumes that the pickup is an object. If you're using a pickup tile, you'll have to replace
DestroyObject with something like
ChangeTileAtCollision #$00, #$00.
2) When the player presses the fire button, you'll want the player object to create a player projectile. Which projectile this is, depends on whether the buckshot variable is zero or one. Also, you'd want to reset the buckshot, so the next shot will be a normal projectile again. Something like this would do that trick:
Code:
;; Check whether to shoot the buckshot or the normal projectile
LDA buckshot
BEQ +normalShot
+buckShot:
;; Reset the buckshot variable
LDA #$00
STA buckshot
;; Load the buckshot object number
LDA #$05 ; <-- replace with the buckshot's object number
JMP +preloadProjectile
+normalShot:
;; Load the normal shot object number
LDA #$04 ; <-- replace with the normal projectile's object number
+preloadProjectile:
;; Store the projectile object number in temp variable
STA temp
;; Create the object on screen
CreateObjectOnScreen (...), (...), temp, #$00, (...) ; <-- replace (...) with x-coordinate, y-coordinate and screen value.
3) When the player projectile hits the monster, the "monster hurt script" is being executed. Here you'll want to check if the projectile is a buckshot or not, and then take the appropriate amount of health points from the monster. If there's no health left, you can destroy the monster. Something like this:
Code:
;; Check if it's a buckshot that's colliding with the monster.
LDX selfObject
LDA Object_type,x
CMP #$05 ; <-- replace with the buckshot's object number
BEQ +buckShot
+normalShot:
LDA #$01 ; <-- replace with the normal damage value
JMP +hurtMonster
+buckShot:
LDA #$02 ; <-- replace with the buckshot damage value
+hurtMonster:
;; Take the damage from the monster's health.
STA temp
LDX otherObject
LDA Object_health,x
SEC
SBC temp
;; Check if the health is less than zero. Elaboration: if the
;; monster has less health than what has been taken from the
;; monster, its health will wrap around and make the monster
;; super healthy (#$01 minus #$02 equals #$FF). Luckily, when
;; this happens, the carry flag will be cleared. So here, we
;; check if the carry flag is set (BCS) and if not, we reset
;; the value to zero.
BCS +
LDA #$00
+
;; If new health is zero, destroy the monster.
BNE +
DestroyObject
JMP +done
+
;; If new health is not zero, update the object's health.
STA Object_health,x
+done:
Once again, this code is incomplete and untested, but I think there's enough in there for you to make it work
Good luck!