How do you make the attack shoot left on shooter module please?

TolerantX

Active member
I tried dissecting the code and reassembling it to no ends trying to get the character to shoot left when facing left in the shooter module. I used scripts from the adventure and platformer modules but the shooting left doesn't work correctly when scrolling. the bullets spawn at awkward places. In my game it's like section Z where you shoot left with b and right with a, so when you read my script keep that in mind. I also limit my projectiles per screen and have it change the player to state 3 when they fire a shot... here's my script... in this it is correct except the player shoots RIGHT, not left.... in my script i need them to shoot left THANK YOU

Code:
    LDX player1_object
    GetCurrentActionType player1_object
    FaceDirection player1_object, FACE_LEFT
    CmP #$03
    BNE notAlreadyShooting2
    JMP doneShooting2 
notAlreadyShooting2

;; UNCOMMENT 11-16 IF YOU WANT THE PLAYER TO STOP MOVING UPON ATTACK.
	LDX player1_object  ;; Now x is loaded with the player
	LDA #$00
	STA Object_h_speed_hi,x
	STA Object_h_speed_lo,x
	STA Object_v_speed_hi,x
	STA Object_v_speed_lo,x

	ChangeObjectState #$03, #$02

	LDA Object_movement,x
	AND #%00000111 ;; this is now the "facing direction"
	TAY ;; now it is loaded in y.
	LDA weaponOffsetTableX,y
	STA temp
	LDA weaponOffsetTableY,y
	STA temp1

    LDA #%00000010
    TAY ;; now y contains direction, so we can figure out position offset
    
     LDA Object_x_hi,x
     ;;; offset x for creation
     CLC
     ADC weaponOffsetTableX,y
     ; SEC
     ; SBC xScroll
     SEC 
     SBC #$08 ;; width of gun 
     STA temp
     LDA Object_y_hi,x
     CLC
     ADC weaponOffsetTableY,y
     sec
     sbc #$08 ;; height of gun
     STA temp1

     LDA Object_scroll,x
     STA temp2
 
    ;;We count the projectile already on screen to see if can Shoot another one :
    CountObjects #%00000100, #$00   ;; count player weapon on screen
    LDA monsterCounter              ;; the variable used to count is monsterCounter
    CLC
    CMP #PROJECTILE_MAX             ;; compare to 2
    BCC +                    ;; if less than 2 on screen we can create a projectile
    RTS                             ;; else we quit
	+

     CreateObject temp, temp1, #OBJECT_PLAYER_PROJECTILE, #$00, temp2
  
    ;;;; x is now the newly created object's x.
    LDA #%11000010
    STA Object_movement,x
    PlaySound #SND_SHOOT
doneShooting2:

RTS
 

dale_coop

Moderator
Staff member
Hmm... but what do you want for that script ?
This script shoots a projectile to the direction your player is facing?
OR
This script shoots a projectile to the LEFT (to assign to your "B" button)? (and you have already another script to shoot to the RIGHT assigned to your "A" button) (in that case you don't really care the player's facing direction)
OR
This script shoots a projectile to the LEFT if "B" is pressed or it shoots a projectile to the "RIGHT" is the "A" is pressed. AND you will assign that unique script twice (to the "A" button and to the "B" button)? (in that case you don't really care the player's facing direction)

...And only LEFT or RIGHT (not Up or Down or diagonal directions)?

I am kinda confused by your demand.
 

dale_coop

Moderator
Staff member
Let's presuming you just want a script that shoots to LEFT, here's the script (based on yours):
Code:
	FaceDirection player1_object, FACE_LEFT
	
	LDX player1_object
	GetCurrentActionType player1_object
	CMP #$03
	BNE notAlreadyShooting2
	JMP doneShooting2 
	
notAlreadyShooting2:

	LDA #$00
	STA Object_h_speed_hi,x
	STA Object_h_speed_lo,x
	STA Object_v_speed_hi,x
	STA Object_v_speed_lo,x

	ChangeObjectState #$03, #$02
	
	LDA Object_movement,x
	AND #%00000111 ;; this is now the "facing direction"
	STA temp3
	;CMP #FACE_UP_LEFT
	;BCS +
	;LDA #FACE_RIGHT
	;STA temp3
	;JMP ++
	;+	
	;LDA #FACE_LEFT
	;STA temp3
	;++
	
	TAY ;; now it is loaded in y.
    
	;;; offset x for creation:
	LDA Object_x_hi,x
	CLC
	ADC projOffsetTableX,y
	SEC 
	SBC #$08 					;; width of the projectile
	STA temp
	LDA Object_y_hi,x
	CLC
	ADC projOffsetTableY,y
	SEC
	SBC #$08 					;; height of the projectile
	STA temp1

	LDA Object_scroll,x
	STA temp2
 
	;;We count the projectile already on screen to see if can Shoot another one :
	CountObjects #%00000100, #$00   ;; count player weapon on screen
	LDA monsterCounter              ;; the variable used to count is monsterCounter
	CLC
	CMP #$02             ;; compare to 2
	BCC +                    ;; if less than 2 on screen we can create a projectile
	RTS                             ;; else we quit
	+

	CreateObject temp, temp1, #OBJECT_PLAYER_PROJECTILE, #$00, temp2

	;;;; x is now the newly created object's x.
	LDA temp3
	STA Object_movement,x
	LDY temp3
	LDA directionTable,y
	ORA Object_movement,x
	STA Object_movement,x

	PlaySound #SND_SHOOT
doneShooting2:

		RTS

note: for the creation origin of the projectile... notice that I replaced the "weaponOffsetTableX / weaponOffsetTableY" of your original script by "projOffsetTableX / projOffsetTableY".
 

TolerantX

Active member
It fires left now, but the offset is above my character, and I've set all the directions to 0,15 in the offset. Is there a way to adjust it to line up with the player better?
 

dale_coop

Moderator
Staff member
is it your Melee offeset? or your projectile (Source) offset? could you share a screenshot?
 
Top Bottom