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

dale_coop

Moderator
Staff member
You could modify the monster barrier script.
Check that post, for example: http://nesmakers.com/viewtopic.php?p=17441#p17441
 

dale_coop

Moderator
Staff member
Are you sure you modified the right MonsterBarrier script? (check in the "Project Setttings > Script Settings" (the script that is assigned to the "Tile Collision 4" element)
 

dale_coop

Moderator
Staff member
Hmmm you could add some code, in the HandleLoadScript.asm script (in your « System » folder):

;; set back the ammo to 5:
LDA #$05
STA myAmmo


For example, around the beginning of the script, just after the line ";;;;;;;;;;;; SET SCREENS RELATIVE TO THE SCREEN TO BE LOADED" (around line 18-20)
 

Yan

Member
Thanks for the answer!

Unfortunately I can't find the HandeLoadScript.asm in my system folder.
 

dale_coop

Moderator
Staff member
My bad... I wrote from my iphone and didn't check the real name of the script... it's "HandleScreenLoads.asm" (in your "System" folder).
 

red moon

Member
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:
    ;; 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
 

red moon

Member
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:
    ;; 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
 

dale_coop

Moderator
Staff member
Try replacing with the line 23, currenlty:
Code:
	JMP wasAlreadyShooting
with that one:
Code:
	JMP checkIfCanShoot
 

red moon

Member
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.
 

red moon

Member
Hey, thanks for getting back so quickly!
My base value is 0, with the value set to 5.
 

Attachments

  • hud1.jpg
    hud1.jpg
    279.8 KB · Views: 1,925
  • hud2.jpg
    hud2.jpg
    238.9 KB · Views: 1,925

red moon

Member
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.
 
Top Bottom