Picking up and shooting with a laser gun (Platformer 4.5.9)

smmulry

New member
I want the character in my game to pick up a laser gun and shoot lasers with it. So far I get him to shoot lasers without picking up the gun, but I want the player to only be able to shoot when they pick up the gun. Help please.
 

smmulry

New member
I am using the Platformer mod and the shoot projectile code is below

HTML clipboard ;;; Create a Projectile.
;;; Assumes that the projectile you want to create is in GameObject Slot 01.

TXA
PHA
TYA
PHA
LDX player1_object
LDA Object_screen,x

STA tempD
LDA Object_x_hi,x
CLC
ADC #$04
STA tempA
LDA Object_y_hi,x
CLC
ADC #$04
STA tempB
LDA Object_direction,x
AND #%00000111
STA tempC
CreateObjectOnScreen tempA, tempB, #$01, #$00, tempD
;;; x, y, object, starting action.
;;; and now with that object, copy the player's
;;; direction and start it moving that way.
LDA tempC
STA Object_direction,x
TAY
LDA DirectionTableOrdered,y
STA temp1
TXA
STA temp
StartMoving temp, temp1
PLA
TAY
PLA
TAX

RTS
 

NightMusic

Member
I am using the Platformer mod and the shoot projectile code is below

HTML clipboard ;;; Create a Projectile.
;;; Assumes that the projectile you want to create is in GameObject Slot 01.

TXA
PHA
TYA
PHA
LDX player1_object
LDA Object_screen,x

STA tempD
LDA Object_x_hi,x
CLC
ADC #$04
STA tempA
LDA Object_y_hi,x
CLC
ADC #$04
STA tempB
LDA Object_direction,x
AND #%00000111
STA tempC
CreateObjectOnScreen tempA, tempB, #$01, #$00, tempD
;;; x, y, object, starting action.
;;; and now with that object, copy the player's
;;; direction and start it moving that way.
LDA tempC
STA Object_direction,x
TAY
LDA DirectionTableOrdered,y
STA temp1
TXA
STA temp
StartMoving temp, temp1
PLA
TAY
PLA
TAX

RTS
you want to shoot projectile with ammo?

I USE OBJECT #$02 as mine

Code:
;;; Create a Projectile.
;;; Assumes that the projectile you want to create is in GameObject Slot 01.
;;; Assumes variable called myAmmo exists.
;;; assumes myAmmo is in hud element 8.

+checkShoot

    LDA myAmmo                ;; load the myAmmo variable into the accumulator.            ;;
    BNE canShoot            ;; if there is ammo go to canShoot, if not go to next line.  ;;
        JMP canNotShoot        ;; jump to subroutine canNotShoot, at the end of the script. ;;

    canShoot:                ;; this is what happens when you canShoot.    ;;

;PlaySound #sfx_laser

    ;; the myAmmo stuff and updating it happens below here. ;;
    DEC myAmmo                ;; decrease/decrement the myAmmo variable.    ;;
    UpdateHudElement #$07    ;; change this to which element shows myAmmo. ;;

    TXA
    PHA
    TYA
    PHA
        LDX player1_object                ;; get player1_object load into x ;;
        LDA Object_screen,x                ;; load the data of player1_object ;;
  
        STA tempD                        ;; store this location into tempD for later ;;
        LDA Object_x_hi,x               
        CLC                           
        ADC #$04                       
        STA tempA
        LDA Object_y_hi,x
        CLC
        ADC #$04
        STA tempB
        LDA Object_direction,x                ;; Get the player's direction ;;
        AND #%00000111                       
        STA tempC                            ;; store it into tempC ;;
        CreateObjectOnScreen tempA, tempB, #$02, #$00, tempD
        ;;; x, y, object, starting action. ;;;
        ;;; the x y from tempA and tempB are where the object will be made in correllation with the player. ;;;   
        ;;; the next number here #$02 is the object number you're creating. ;;;
        ;;; the next number here #$00 is the object you're creating's action step. ;;;
        ;;; tempD is the screen. ;;;
 
 ;;; now with that object, retrieve the player's direction from previously and start it moving that way. ;;;
            LDA tempC                        ;; the player's direction stored earlier ;;
            STA Object_direction,x   
            TAY
            LDA DirectionTableOrdered,y
            STA temp1
            TXA
            STA temp
            StartMoving temp, temp1
    PLA
    TAY
    PLA
    TAX

canNotShoot:    ;; this is what happens when you canNotShoot. ;;
    RTS
 
Top Bottom