I had a lot minutes scratching my head... what the hell I missed when setting my projectile game object. Why it doesn't move when my player shoots. After some tests, I realized that when objects are set as "ignore gravity"... it looks like they don't move (missing some update of Object_x_lo/hi variables).
To make it works, I wrote a small fix (that only will have impact on game objets and monsters that are set as "ignore gravity" and are meant to move).
Now, it should work :
So, here's my small tutorial :
How to add projectiles for your player, in the platformer game in NESMaker 4.1
1/ Open your platformer game project (scrolling or not scrolling) and go to "Project Settings > User Constants", select the "OBJECT_PLAYER_PROJECTILE" element and change its value to "02":
We will use the game object #$02 (the one named "Source Projectile").
2 / Set your "Source Projectile" object :
In the Details Object, set as "Player weapon", set also its Speed and Acceleration.
Then, in the "Actions", set the "Ignore Gravity".
Lastly, don't forget to give a Bounding Box.
3/ Make a new script "b_create_projectile_platformer.asm" in your "GameEngineData\Routines\Basic\ModuleScripts\InputScripts" folder, with that code:
Modify the "UserSubroutines.asm" script, located in your "GameEngineData\Routines\Basic\ModuleScripts" folder, adding this:
4/ Modify the "HandleHorisontalInertia.asm" script (located in the "GameEngineData\Routines\Basic\System\Macros" folder).
At line 154, add those 2 lines :
Around line 199 (just after the "STA nt_hold" line), add those 2 lines :
6 / Modify (or preferred, duplicate the original one) your "TileCollisions.asm" script (in your "GameEngineData\Routines\Basic\ModuleScripts\MainScripts\ScrollingPlatformer" folder) , at line 126, add this line:
Also, uncommenting the line 112:
And also uncommenting the line 128:
7/ Add the "b_create_projectile_platformer.asm" script to your "Scripts > Input Scripts", and assign it to the "Press" "B" button in your "Input Editor".
8/ Now, you can select the "Game Objects" element and click on the "Melee" button to select/display "Source" :
And set the position of your projectile when the player facing Right and Left.
9/ If you use Monster Barrier tile, you need also to modify the "MonsterBarrier.asm" script (in your "Routines\Basic\ModuleScripts\TileScripts\ScrollingPlatformer" folder), replacing with that code:
VoilĂ ! Now, projectiles should work.
To make it works, I wrote a small fix (that only will have impact on game objets and monsters that are set as "ignore gravity" and are meant to move).
Now, it should work :
So, here's my small tutorial :
How to add projectiles for your player, in the platformer game in NESMaker 4.1
1/ Open your platformer game project (scrolling or not scrolling) and go to "Project Settings > User Constants", select the "OBJECT_PLAYER_PROJECTILE" element and change its value to "02":
We will use the game object #$02 (the one named "Source Projectile").
2 / Set your "Source Projectile" object :
In the Details Object, set as "Player weapon", set also its Speed and Acceleration.
Then, in the "Actions", set the "Ignore Gravity".
Lastly, don't forget to give a Bounding Box.
3/ Make a new script "b_create_projectile_platformer.asm" in your "GameEngineData\Routines\Basic\ModuleScripts\InputScripts" folder, with that code:
Code:
LDA gameHandler
AND #%00100000
BEQ canShoot
JMP doneShooting
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 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
Modify the "UserSubroutines.asm" script, located in your "GameEngineData\Routines\Basic\ModuleScripts" folder, adding this:
Code:
;; temporarly put this subroutine here, but would be better into a custom script.
;; fix for the non moving ignore-gravity-objects (like projectiles) in the platform games:
;; (used by the HandleHorizontalInertia macro)
updateXPosForNonPlayerObjects:
CPX player1_object ;; check if it's the player
BEQ doneUpdatingXPosForNonPlayerObjects ;; if it IS, don't need to update
LDA Object_vulnerability,x
AND #%00100000 ;; check if "ignore gravity" is set
BEQ doneUpdatingXPosForNonPlayerObjects ;; if it is NOT, don't need to update
LDA Object_movement,x
AND #%10000000 ;; check if movement horizontal engaged
BEQ doneUpdatingXPosForNonPlayerObjects ;; if it is NOT, don't need to update
LDA xHold_lo
STA Object_x_lo,x
LDA xHold_hi
STA Object_x_hi,x
;LDA nt_hold
;STA Object_scroll,x ;;not sure what to do with this
doneUpdatingXPosForNonPlayerObjects:
RTS
4/ Modify the "HandleHorisontalInertia.asm" script (located in the "GameEngineData\Routines\Basic\System\Macros" folder).
At line 154, add those 2 lines :
Code:
;; small fix for the ignore gravity objects (maybe issues with other objects in some another cases?)
JSR updateXPosForNonPlayerObjects
;;;; here is a macro that handles player guided right scrolling.
;;;; you can disable right scrolling by simply commenting this one macro out.
Code:
;; small fix for the ignore gravity objects (maybe issues with other objects in some another cases?)
JSR updateXPosForNonPlayerObjects
;;; this handles player guided left scrolling
;;; to disable left scrolling, simply comment this one macro out.
6 / Modify (or preferred, duplicate the original one) your "TileCollisions.asm" script (in your "GameEngineData\Routines\Basic\ModuleScripts\MainScripts\ScrollingPlatformer" folder) , at line 126, add this line:
Code:
CheckForHorizontalCollision ;; <<--- checking solid collisions now
; JSR updateHorizontalPosition
; JSR updateVerticalPosition
Also, uncommenting the line 112:
Code:
CheckPlayerCameraPosition
And also uncommenting the line 128:
Code:
JSR updateHorizontalPosition
7/ Add the "b_create_projectile_platformer.asm" script to your "Scripts > Input Scripts", and assign it to the "Press" "B" button in your "Input Editor".
8/ Now, you can select the "Game Objects" element and click on the "Melee" button to select/display "Source" :
And set the position of your projectile when the player facing Right and Left.
9/ If you use Monster Barrier tile, you need also to modify the "MonsterBarrier.asm" script (in your "Routines\Basic\ModuleScripts\TileScripts\ScrollingPlatformer" folder), replacing with that code:
Code:
;;; SOLID
;;;This is how to inform a solid collision.
;;; You can also add this to the end of
;;; any tile type if you want it to have an effect AND
;;; be treated like solid.
;;; You could also check to see if it is a non-player object,
;;; and only return solid if it's a not player. This would
;;; cause monsters to treat things like spikes or ladder or fire
;;; as solid while the player is able to interract with it.
CPX player1_object
BEQ skipSolidRead
LDA Object_flags,x ;; check the type of object
AND #%00010100 ;; is it a player/monster weapon ?
BNE skipSolidRead ;; it IS, we skip
LDA #TILE_SOLID
STA tile_solidity
skipSolidRead:
;; if you want it solid, declare it at the end
VoilĂ ! Now, projectiles should work.