How to make character move while shooting? [SOLVED]

User avatar
PortableAnswers
Posts: 56
Joined: Wed May 02, 2018 11:52 am
Location: USA
Contact:

How to make character move while shooting? [SOLVED]

Post by PortableAnswers » Sat Sep 15, 2018 12:03 am

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: Select all

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
Last edited by PortableAnswers on Sat Oct 06, 2018 11:35 am, edited 2 times in total.
digit2600
Posts: 61
Joined: Mon Apr 16, 2018 9:50 pm

Re: How to make character move while shooting?

Post by digit2600 » Sat Sep 15, 2018 1:42 pm

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: Select all

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]
User avatar
PortableAnswers
Posts: 56
Joined: Wed May 02, 2018 11:52 am
Location: USA
Contact:

Re: How to make character move while shooting?

Post by PortableAnswers » Sat Sep 15, 2018 5:18 pm

Did that work for you?
User avatar
dale_coop
Posts: 1302
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: How to make character move while shooting?

Post by dale_coop » Mon Sep 17, 2018 11:49 am

What is your object state (action step) for shooting? action step 2 ? action step 3?
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE
User avatar
dale_coop
Posts: 1302
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: How to make character move while shooting?

Post by dale_coop » Mon Sep 17, 2018 12:00 pm

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: Select all

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: Select all

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
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE
User avatar
PortableAnswers
Posts: 56
Joined: Wed May 02, 2018 11:52 am
Location: USA
Contact:

Re: How to make character move while shooting?

Post by PortableAnswers » Tue Sep 18, 2018 8:46 pm

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!
Last edited by PortableAnswers on Tue Sep 18, 2018 9:49 pm, edited 2 times in total.
User avatar
dale_coop
Posts: 1302
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: How to make character move while shooting?

Post by dale_coop » Tue Sep 18, 2018 8:57 pm

Yes, PortableAnswer
In your "a_create_projectile.asm" just try to make the same modifications at the beginning the script.
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE
User avatar
PortableAnswers
Posts: 56
Joined: Wed May 02, 2018 11:52 am
Location: USA
Contact:

Re: How to make character move while shooting?

Post by PortableAnswers » Tue Sep 18, 2018 9:31 pm

Thanks again! You're a wizard!
Last edited by PortableAnswers on Fri Sep 21, 2018 8:18 pm, edited 1 time in total.
User avatar
dale_coop
Posts: 1302
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: How to make character move while shooting?

Post by dale_coop » Tue Sep 18, 2018 10:11 pm

Glad if I could help you :)
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE
User avatar
PortableAnswers
Posts: 56
Joined: Wed May 02, 2018 11:52 am
Location: USA
Contact:

Re: How to make character move while shooting?

Post by PortableAnswers » Sat Sep 22, 2018 2:46 am

dale_coop wrote:
Tue Sep 18, 2018 10:11 pm
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.
Post Reply