More powerful projectile 4.5.9

TheRetroBro

Active member
I want to create a projectile that does more damage than my standard projectile. Would this be done in my monster hurt script?

Need some guidance on wehre to start on this. my goal is as follows:

Create a variable "buckshot"
make pickup that fills buckshot (will atomically fire when picked up which means will take over as primary weapon until expired)

I want this object lets call it object 5 (buckshot projectile) to do more damage say twice the damage than standard projectile.
 

kevin81

Well-known member
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!
 

tbizzle

Well-known member
I want to create a projectile that does more damage than my standard projectile. Would this be done in my monster hurt script?

Need some guidance on wehre to start on this. my goal is as follows:

Create a variable "buckshot"
make pickup that fills buckshot (will atomically fire when picked up which means will take over as primary weapon until expired)

I want this object lets call it object 5 (buckshot projectile) to do more damage say twice the damage than standard projectile.

Here is a tutorial on how to do so.

 

TheRetroBro

Active member
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!
This works great, HOWEVER I cannot get two things to work..maybe im adding it to the wrong area. I cannot get monster hurt state or my objects to drop first is monster death animation other is an ammo drop: See my code below


Code:
;; Check if it's a buckshot that's colliding with the monster.
PlaySound #sfx_index_sfx_killmonster
ChangeActionStep temp, #$07 
   LDX selfObject
    LDA Object_type,x
    CMP #$03 ; <-- replace with the buckshot's object number
    BEQ +superammo

    +normalShot:
        LDA #$01 ; <-- replace with the normal damage value
        JMP +hurtMonster

    +superammo:
        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

        ;PlaySound #sfx_index_sfx_killmonster;; 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
            CreateObjectOnScreen tempA, tempB, #$F, #$00, tempD
            CreateObjectOnScreen tempA, tempB, #$02, #$00, tempD
            JMP +done
        +
        ;; If new health is not zero, update the object's health.
        STA Object_health,x
    +done:
 
Top Bottom