How to make character move while shooting? [SOLVED]

PortableAnswers

New member
Hello, apologies if this question has been asked. I have not yet found what I am looking for. With the help of dale_coop, I was able to get my character to shoot the projectile in each direction from specified x and y coordinates. I am now hoping to have my player move while he is shooting. Below is my current code for the "a_create_projectile.asm" script.

Code:
createWeaponProjectile:
 LDA gameHandler
    AND #%00100000
    BEQ notNPCstate_proj
 JMP doneShooting
 notNPCstate_proj
 LDA weaponsUnlocked
 AND #%00000010
 BNE canShoot
 JMP doneShooting
canShoot:
LDX player1_object
 GetCurrentActionType player1_object


 CMP #$02
 BNE notAlreadyShooting
 JMP doneShooting
notAlreadyShooting
 ;;; don't attack if already attacking.
 ;;; do we have to check for hurt here?
 ;;;;; Here, we WOULD create melee
 ChangeObjectState #$02, #$02
 LDA Object_movement,x
 AND #%00001111
 STA Object_movement,x
 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
 
 
 LDA Object_x_hi,x
 STA temp
 LDA Object_y_hi,x
 STA temp1
 
    LDA Object_movement,x
    AND #%00000111
    STA temp2
    CMP #%00000110
    BEQ setLEFTOffsetProjectile
    CMP #%00000010
    BEQ setRIGHTOffsetProjectile
    CMP #%00000100
    BEQ setUPOffsetProjectile
    CMP #%00000000
    BEQ setDOWNOffsetProjectile
    JMP doneShooting
    
setLEFTOffsetProjectile:
    LDA Object_x_hi,x
    CLC
    SBC #$-13    ;;<<-- horizontal offset of your weapon when your player facing left (change the value to adjust from #$00 to #$0F or more)
    STA temp
    LDA Object_y_hi,x
    CLC
    ADC #$11    ;;<<-- vertical offset of your weapon  when your player facing left(change the value to adjust from #$00 to #$0F or more)
    STA temp1
    JMP continueCreatingProjectile
    
setRIGHTOffsetProjectile:
    LDA Object_x_hi,x
    CLC
    ADC #$13    ;;<<-- L/R - horizontal offset of your weapon when your player facing right (change the value to adjust from #$00 to #$0F or more)
    STA temp
    LDA Object_y_hi,x
    CLC
    ADC #$11    ;;<<-- U/D - vertical offset of your weapon when your player facing right (change the value to adjust from #$00 to #$0F or more)
    STA temp1
    JMP continueCreatingProjectile

setUPOffsetProjectile:
    LDA Object_x_hi,x
    CLC
    ADC #$07    ;;<<-- horizontal offset of your weapon when your player facing up (change the value to adjust from #$00 to #$0F or more)
    STA temp
    LDA Object_y_hi,x
    CLC
    SBC #$-00    ;;<<-- vertical offset of your weapon when your player facing up (change the value to adjust) from #$00 to #$0F or more
    STA temp1
    JMP continueCreatingProjectile

setDOWNOffsetProjectile:
    LDA Object_x_hi,x
    CLC
    ADC #$07    ;;<<-- horizontal offset of your weapon when your player facing down (change the value to adjust from #$00 to #$0F or more)
    STA temp
    LDA Object_y_hi,x
    CLC
    ADC #$16    ;;<<-- vertical offset of your weapon when your player facing down (change the value to adjust from #$00 to #$0F or more)
    STA temp1
    JMP continueCreatingProjectile
    
continueCreatingProjectile:
    CreateObject temp, temp1, #$03, #$00
 
    ;;;; x is now the newly created object's x.
    LDA Object_movement,x
    ORA temp2
    STA Object_movement,x
    LDY temp2
    LDA directionTable,y
    ORA Object_movement,x
    STA Object_movement,x
    PlaySound #sfx_shoot
 
doneShooting:
RTS


;;000 down
;010 right
;100 up
;110 left
 

digit2600

Member
in the move player left/ right scripts,

cmp the state of shooting (#$03, maybe? ) and beq to + instead of ++

i think...

i set mine up for the platform engine so it may be a little different, but same idea...

Code:
LDX player1_object GetCurrentActionType player1_object
 CMP #$01;;walk state
 BEQ+ 
CMP #$02;; attack state
BEQ +
 ChangeObjectState #$01, #$03, #$02 
+
 StartMoving player1_object, MOVE_LEFT
 ++
 FaceDirection player1_object, FACE_LEFT 
 rts 
 [code]
 

dale_coop

Moderator
Staff member
If your player's "shooting" is the action step "02", then... (if not 02, tell me, I will modify the script to be correct).

You could try to check if the player is running, and if he his, just by pass the changeObjectState... something like this.
Replacing that:
Code:
canShoot:
	LDX player1_object
	GetCurrentActionType player1_object
	CMP #$02
	BNE notAlreadyShooting
	JMP doneShooting
notAlreadyShooting
	;;; don't attack if already attacking.
	;;; do we have to check for hurt here?
	;;;;; Here, we WOULD create melee
	ChangeObjectState #$02, #$02
	LDA Object_movement,x
	AND #%00001111
	STA Object_movement,x
	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
	
	LDA Object_x_hi,x
	STA temp
	LDA Object_y_hi,x
	STA temp1
By that:
Code:
canShoot:
	LDX player1_object
	GetCurrentActionType player1_object
	CMP #$01	;; if the Player is walking/running
	BEQ isNowShooting  ;; keep it walking/running
	CMP #$02	;; else if is already shooting...
	BNE notAlreadyShooting
	JMP doneShooting
notAlreadyShooting:
	;;; don't attack if already attacking.
	;;; do we have to check for hurt here?
	;;;;; Here, we WOULD create melee
	ChangeObjectState #$02, #$02
	LDA Object_movement,x
	AND #%00001111
	STA Object_movement,x
	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
isNowShooting: 
	;; the script continues from here
	
	LDA Object_x_hi,x
	STA temp
	LDA Object_y_hi,x
	STA temp1
 

PortableAnswers

New member
Hey dale-coop, thanks for your help!

I HAD the following action steps:
1 - Idle
2 - Walk
3 - Attack

I switched it to:
1 - Idle
2 - Attach
3 - Walk

Is your code for the "a_create_projectile.asm" script?

Edit:
I can now shoot while moving!
 

dale_coop

Moderator
Staff member
Yes, PortableAnswer
In your "a_create_projectile.asm" just try to make the same modifications at the beginning the script.
 

PortableAnswers

New member
dale_coop said:
Glad if I could help you :)

Hey there, should this script continue to work in version 4.0.11?
I cannot seem to get my projectile working at all.
I've imported the projectile's game object from 4.0.6 so none of it's properties should have changed.
I also set the A button to "a_create_projectile.asm" script when it is pressed.
 

PortableAnswers

New member
Then I am probably just doing something wrong. I was also unsuccessful at getting the default "a_create_projectile" script that is unaltered to work. I notice in the newest version of NESmaker, there is something called Projectile Source under Game Objects. I am wondering if that has something to do with it?
 

dale_coop

Moderator
Staff member
In the Adventure module, the "projectile source" object is used for monster's projectiles, and the "Projectile" game object is your player projectile.
 

dale_coop

Moderator
Staff member
But in the 4.0.11, your player needs to "get" this weapon, to be able to use it ;)
An NPC can give your player the item "Magic-Projectile"
Or you can give this ability by default to your player, in your "project > Info", check "Weapon 2".
 
Top Bottom