[4.1.5] How to change direction of projectiles in platformer Basic_noscroll module

JFranco

New member
Hello,

I'd like to be able to:
-Press the A button and have a projectile fire

-If it's just the A button being pressed, the projectile fires in whatever direction the player is facing (DONE)
-If the A button is pressed with an arrow key on the D-pad, the projectile fires in whichever direction is pressed on the keypad (despite where the player is facing)

The second part is the tricky part.

At first I thought it was all about altering the fifth argument in the CreateObject macro (ex: CreateObject temp, temp1, #$03, #$00, temp2), but now I'm realizing object direction is controlled by Object_Movement variable. Now i'm wondering if the directional_table not being linked is a factor?

P.S. My game uses gravity

Thanks in advance for any help (this includes link to videos or threads that can point me in the right direction)

Cheers,
Justin
 

JFranco

New member
Absolutely!

Please note: this is assigned in my input scripts as MAIN GAME : NULL : PRESS A

Also, I *know* there's a better way to check to see which D-pad arrow key was pressed, but I'll deal with that later. I just want to get the projectile to shoot right when the A + RIGHT buttons are pressed.

Code:
LDA gamepad

    AND #%00000001 ; checking if A was pressed
   
    BNE +
    JMP doneShooting

    
    +
         
            CLC
            LDA gamepad
            AND #%10000000 ; checking for Right button

            BNE +

            ;Right was NOT pressed, do stuff here then JMP to end

            JMP doneShooting

            +
            JMP ShootGuns ;execute gun shooting subroutine  
    
    
    
    
    
            CLC
            LDA gamepad
            AND #%01000000 ; checking for LEFT button

            BNE +
            ;LEFT was NOT pressed, do stuff here then JMP to end
            JMP doneShooting

            +

            ; LEFT was pressed, do some stuff here:
            
            ;load the LEFT direction into temp 2
            JMP ShootGuns ;execute gun shooting subroutine  
    
    
    
            CLC
            LDA gamepad
            AND #%10000000 ; checking for Right button

            BNE +

            ;Right was NOT pressed, do stuff here then JMP to end

            JMP doneShooting

            +

            ; Right was pressed, do some stuff here:
            
            ; load the Right direction into temp 2
            JMP ShootGuns ;execute gun shooting subroutine  
    
    
    
            CLC
            LDA gamepad
            AND #%00100000 ; checking for Down button

            BNE +

            ;Down was NOT pressed, do stuff here then JMP to end

            JMP doneShooting

            +

            ; Down was pressed, do some stuff here:
            
            ; load the Down direction into temp 2
            JMP ShootGuns ;execute gun shooting subroutine    
    
    
    
    
            CLC
            LDA gamepad
            AND #%00010000 ; checking for Up button

            BNE +

            ;Up was NOT pressed, do stuff here then JMP to end

            JMP doneShooting

            +

            ; Up was pressed, do some stuff here:
            
            ; load the UP direction into temp 2
            JMP ShootGuns ;execute gun shooting subroutine


ShootGuns:
    
    LDX player1_object
    CLC
    LDA Object_x_hi,x
    ADC #$1C                        ;change this in order to centre the bullets from plane on x-axis
    STA temp
    CLC
    LDA Object_y_hi,x
    ADC #$1D                        ;change this in order to centre the bullets from plane on y-axis
    STA temp1
    
    LDA Object_scroll,x
    STA temp2
 
    
    ;CreateObject x value, y value, object type, action step, Object_scroll (nametable...current, left or right)
    ;create an object at player's position. use game object #4 (projectile)
    
        
    CreateObject temp, temp1, #$03, #$00, temp2
   
     doneShooting:
  
  RTS
 

JFranco

New member
Hmmm... it appears that adding:

Code:
    CLC 
    LDA #%11000000
    STA Object_movement, x

after calling the CreateObject macro did the trick.

now to fine-tune this...
 

dale_coop

Moderator
Staff member
In your script, you need to check if "A" is pressed, because it's always true, if that script is assigned to your "A" press button.
So you just need to check the directions if left/right is pressed, like you did.
 
Top Bottom