[4.1] Adding Ammo system (charging weapon) for your projectiles in the Platformer module

Yan
Posts: 16
Joined: Sun Dec 01, 2019 11:49 pm
Location: Brazil

Re: [4.1] Adding Ammo system (charging weapon) for your projectiles in the Platformer module

Post by Yan » Wed Dec 11, 2019 2:37 pm

It works :D

Thank you
User avatar
red moon
Posts: 338
Joined: Mon Aug 12, 2019 12:19 am

Re: [4.1] Adding Ammo system (charging weapon) for your projectiles in the Platformer module

Post by red moon » Tue Jan 07, 2020 9:57 pm

Hey Dale,
I started following this along then realized that my script was unique since it features the press up release projectile instructions. It will need the Ammo elements added in and then it should function as intended I expect.

Here is the code in its present state.
I do have 2 questions relating to this.
How do I set it so the powerup ammo elements adds 2 rather than 5?
and can I add code to the player death script so the ammo power up will drop?

That way the player can only refill ammo by drops left by defeated enemies. thanks!

Code: Select all

    ;; checking if "Up" is pressed on the gamepad
	LDA gamepad
	AND #%00010000
	BNE +
	RTS		;; if not pressed, then we stop the script, here
	+
	LDA gameHandler
    AND #%00100000  
    BEQ canShoot
    JMP doneShooting
canShoot:
	LDA weaponsUnlocked
	AND #%00000010
	BNE canShootProjUnlocked
	JMP doneShooting
canShootProjUnlocked:
    LDX player1_object
    ;;; IF YOU WANT TO USE AN SPECIFIC ANIMATION / ACTION STEP WHEN SHOOTING, comment out the following 3 lines: 
    ;;; check if already shooting (assuming the shoot action step is 05)
    ;GetCurrentActionType player1_object
    ;CMP #$05
    ;BNE notAlreadyShooting
    JMP wasAlreadyShooting 
notAlreadyShooting
    ;;; IF YOU WANT TO USE AN SPECIFIC ANIMATION / ACTION STEP WHEN SHOOTING, comment out the following 1 line: 
    ;;; if not already shooting, change it's action step (assuming the shoot action step is 05)
    ;ChangeObjectState #$05, #$02
    
    ;;; if you want your player stops when he's shooting, comment out the following lines:
    ;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
    
;; if was already shooting
wasAlreadyShooting:

    LDA Object_movement,x
    AND #%00000111
    STA temp2
    TAY

    LDA Object_x_hi,x
    SEC 
    SBC #$08 ;; width of projectile 
    STA temp
    LDA Object_scroll,x
    SBC #$00
    STA temp3

    LDA temp
    ;;; offset x for creation
    CLC
    ADC projOffsetTableX,y
    STA temp
    LDA temp3
    ADC #$00
    STA temp3

    LDA Object_y_hi,x
    CLC
    ADC projOffsetTableY,y
    sec
    sbc #$08 ;; height of projectile
    STA temp1   
    
    
    CreateObject temp, temp1, #OBJECT_PLAYER_PROJECTILE, #$00, temp3
  
    ;;;; 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 #SND_SHOOT
doneShooting:
    RTS
User avatar
red moon
Posts: 338
Joined: Mon Aug 12, 2019 12:19 am

Re: [4.1] Adding Ammo system (charging weapon) for your projectiles in the Platformer module

Post by red moon » Wed Jan 15, 2020 1:35 am

Hey Dale, I tried to add some of the code elements from your script to my b_create_projectile_platformer, adding the 2 elements I found that dealt with ammo. However, it has an issue with line 23.
Can you take a look at the code below when you get the chance,, thanks!

Code: Select all

    ;; checking if "Up" is pressed on the gamepad
	LDA gamepad
	AND #%00010000
	BNE +
	RTS		;; if not pressed, then we stop the script, here
	+
	LDA gameHandler
    AND #%00100000  
    BEQ canShoot
    JMP doneShooting
canShoot:
	LDA weaponsUnlocked
	AND #%00000010
	BNE canShootProjUnlocked
	JMP doneShooting
canShootProjUnlocked:
    LDX player1_object
    ;;; IF YOU WANT TO USE AN SPECIFIC ANIMATION / ACTION STEP WHEN SHOOTING, comment out the following 3 lines: 
    ;;; check if already shooting (assuming the shoot action step is 05)
    ;GetCurrentActionType player1_object
    ;CMP #$05
    ;BNE notAlreadyShooting
    JMP wasAlreadyShooting 
notAlreadyShooting
    ;;; IF YOU WANT TO USE AN SPECIFIC ANIMATION / ACTION STEP WHEN SHOOTING, comment out the following 1 line: 
    ;;; if not already shooting, change it's action step (assuming the shoot action step is 05)
    ;ChangeObjectState #$05, #$02
    
    ;;; if you want your player stops when he's shooting, comment out the following lines:
    ;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
	
	
    
;; if was already shooting
checkIfCanShoot:
	;; will check if the weapon is charged (if Ammo > 0) :
	LDA myAmmo
	BNE	continueShooting	;; if not equal to 0, we can shoot
	;;if no Ammo, we're done here.
	RTS
	
;; if enought Ammo we can continue shooting:
continueShooting:
	LDA Object_movement,x
	AND #%00000111
	STA temp2
	TAY

    LDA Object_x_hi,x
    SEC 
    SBC #$08 ;; width of projectile 
    STA temp
    LDA Object_scroll,x
    SBC #$00
    STA temp3

    LDA temp
    ;;; offset x for creation
    CLC
    ADC projOffsetTableX,y
    STA temp
    LDA temp3
    ADC #$00
    STA temp3

    LDA Object_y_hi,x
    CLC
    ADC projOffsetTableY,y
    sec
    sbc #$08 ;; height of projectile
    STA temp1   
    
    
    CreateObject temp, temp1, #OBJECT_PLAYER_PROJECTILE, #$00, temp3
  
    ;;;; 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
    
	;; start Updating Ammo
	DEC myAmmo
	LDA myAmmo
	;;; we also need to set up the routine to update the HUD
	;; for this to work right, health must be a "blank-then-draw" type element.
	STA hudElementTilesToLoad
	LDA #$00
	STA hudElementTilesMax
	UpdateHud HUD_myAmmo
	;; finished Updating Ammo
	
    ;PlaySound #SND_SHOOT
doneShooting:
    RTS
User avatar
dale_coop
Posts: 4613
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: [4.1] Adding Ammo system (charging weapon) for your projectiles in the Platformer module

Post by dale_coop » Wed Jan 15, 2020 8:40 am

Try replacing with the line 23, currenlty:

Code: Select all

	JMP wasAlreadyShooting 
with that one:

Code: Select all

	JMP checkIfCanShoot
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
User avatar
red moon
Posts: 338
Joined: Mon Aug 12, 2019 12:19 am

Re: [4.1] Adding Ammo system (charging weapon) for your projectiles in the Platformer module

Post by red moon » Wed Jan 15, 2020 3:15 pm

Great, I will...thank you Dale!
User avatar
red moon
Posts: 338
Joined: Mon Aug 12, 2019 12:19 am

Re: [4.1] Adding Ammo system (charging weapon) for your projectiles in the Platformer module

Post by red moon » Thu Jan 16, 2020 8:18 pm

That did it thanks Dale!
One thing I noticed watching your video versus mine...you don't have any HUD ammo elements until you grab the ammo power up. When I run my game the ammo is displayed. I cannot shoot until I grab the ammo, but once I do it then switches to the empty tile as I fire.
User avatar
dale_coop
Posts: 4613
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: [4.1] Adding Ammo system (charging weapon) for your projectiles in the Platformer module

Post by dale_coop » Thu Jan 16, 2020 9:58 pm

What is you ammo hud variable initial value ? you set it to "0"?
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
User avatar
red moon
Posts: 338
Joined: Mon Aug 12, 2019 12:19 am

Re: [4.1] Adding Ammo system (charging weapon) for your projectiles in the Platformer module

Post by red moon » Thu Jan 16, 2020 11:04 pm

Hey, thanks for getting back so quickly!
My base value is 0, with the value set to 5.
Attachments
hud2.jpg
hud2.jpg (238.92 KiB) Viewed 66 times
hud1.jpg
hud1.jpg (279.83 KiB) Viewed 66 times
User avatar
red moon
Posts: 338
Joined: Mon Aug 12, 2019 12:19 am

Re: [4.1] Adding Ammo system (charging weapon) for your projectiles in the Platformer module

Post by red moon » Fri Jan 17, 2020 2:02 am

Dale, after giving it some thought, I went back and set the initial value to 5 so you would have a full meter after picking up the initial shard powerup. The hud element does seem to refresh when I enter a new screen however but you don't actually have any more ammo.
I wanted to see what you thought the best way to go about this.

If its set to 0 initially, then the hud would be correct and not show anything until the shard is collected, then it would populate the hud with 5 tiles that are replaced by the empty tile after each use.
User avatar
red moon
Posts: 338
Joined: Mon Aug 12, 2019 12:19 am

Re: [4.1] Adding Ammo system (charging weapon) for your projectiles in the Platformer module

Post by red moon » Fri Jan 17, 2020 2:20 am

Switched it back to 0 for now, since that should be the correct initial value...
Post Reply