Based on what I've already done in previous versions of NESMaker...
Here's how to add an Ammo system for your projectiles (or laser gun charge system... or whatever you want it to be) in your Platformer game.
[media]https://youtu.be/VHCnJ0-diys[/media]
1/ Add a new "User Constant" in the "Project settings", name it "PLAYER1_MAX_AMMO" with a value of "5".
2/ In the "HUD & Boxes > User Variables", rename the "UserVar_5" (or another unused one) to "myAmmo" with an Initial Value of "0":
You can display it in your HUD elements...
3/ Make a new "b_create_projectile_usingAmmo.asm" script in the "GameEngineData\Routines\Basic\ModuleScripts\InputScripts" folder, containing:
4/ Make a new "PowerUp_ChargeAmmo.asm" script in the "GameEngineData\Routines\Basic\ModuleScripts\PowerUpCode" folder, containing:
5/ In the "Project Settings > Scripts Settings" assign the "PowerUp_ChargeAmmo.asm" script to the unused "PowerUp_01" (or another one if you prefer)
6/ In the "Scripts > Input Scripts", add the "b_create_projectile_usingAmmo.asm" script to your project.
7/ Assign it to your "Press" "B" button.
And voilĂ !
Here's how to add an Ammo system for your projectiles (or laser gun charge system... or whatever you want it to be) in your Platformer game.
[media]https://youtu.be/VHCnJ0-diys[/media]
1/ Add a new "User Constant" in the "Project settings", name it "PLAYER1_MAX_AMMO" with a value of "5".
2/ In the "HUD & Boxes > User Variables", rename the "UserVar_5" (or another unused one) to "myAmmo" with an Initial Value of "0":
You can display it in your HUD elements...
3/ Make a new "b_create_projectile_usingAmmo.asm" script in the "GameEngineData\Routines\Basic\ModuleScripts\InputScripts" folder, containing:
Code:
LDA gameHandler
AND #%00100000
BEQ canShoot
RTS
canShoot:
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 checkIfCanShoot
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
4/ Make a new "PowerUp_ChargeAmmo.asm" script in the "GameEngineData\Routines\Basic\ModuleScripts\PowerUpCode" folder, containing:
Code:
;;; Charge the weapon / Ammo
;;; works with HUD variable HUD_myAmmo.
LDA #PLAYER1_MAX_AMMO
STA 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
;PlaySound #SND_INCREASE_HEALTH
skipGettingAmmo:
RTS
5/ In the "Project Settings > Scripts Settings" assign the "PowerUp_ChargeAmmo.asm" script to the unused "PowerUp_01" (or another one if you prefer)
6/ In the "Scripts > Input Scripts", add the "b_create_projectile_usingAmmo.asm" script to your project.
7/ Assign it to your "Press" "B" button.
And voilĂ !