[4.1] Fixing the "Ignore Gravity" (projectiles, bats, birds, ... objects can now move horizontally and vertically)

dale_coop

Moderator
Staff member
A small fix for the "Ignore Gravity" action step flag. Currently if you set this flag, your object can't move horizontally nor vertically.

Now we can have monsters that fly, bats, birds, ...

IgnoreGravity.gif


Here's how to fix that.

1/ Modify your "UserSubroutines.asm" script (located in your "Routines\Basic\ModuleScripts\" folder), and add those two subroutines:
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		;; don't know what to do with this...
doneUpdatingXPosForNonPlayerObjects:
	RTS
	
;; (used by the HandleVerticalInertia macro)
updateYPosForNonPlayerObjects:
	CPX player1_object							;; check if it's the player
	BEQ doneUpdatingYPosForNonPlayerObjects		;; if it IS, don't need to update
	LDA Object_vulnerability,x
    AND #%00100000								;; check if "ignore gravity" is set
	BEQ doneUpdatingYPosForNonPlayerObjects		;; if it is NOT, don't need to update
	LDA Object_movement,x
	AND #%00100000 								;; check if movement vertical engaged
	BEQ doneUpdatingYPosForNonPlayerObjects		;; if it is NOT, don't need to update
	LDA yHold_lo
	STA Object_y_lo,x
	LDA yHold_hi 
	STA Object_y_hi,x
doneUpdatingYPosForNonPlayerObjects:
	RTS


2/ 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.

At line 199 (just after the "STA nt_hold" line), add those 2 lines :

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.


3/ Modify the "HandleVerticalInertia.asm" script (located in the "GameEngineData\Routines\Basic\System\Macros\" folder).
At line 152, add those 2 lines :

Code:
	;; small fix for the ignore gravity objects (maybe issues with other objects in some another cases?)
	JSR updateYPosForNonPlayerObjects
	
	;;;; HERE IS WHERE WE MIGHT ADD DOWNWARD SCROLLING.

At line 177, add those 2 lines :

Code:
	;; small fix for the ignore gravity objects (maybe issues with other objects in some another cases?)
	JSR updateYPosForNonPlayerObjects

	;;; this handles player guided left scrolling


4/ And in order to have collisions with solid objects, I had to also modify the TileCollisions.asm script (cf. in your "Project Settings > Script Settings", the "Tile Collision" element to know which one is used in your module).
Around line 118, like this...

Before:
Code:
;;;;;   For top down type games, or games that generally have no gravity but have 4 directional movement,
;;;;;   we only need to check potential position and jump to the appropriate label.
  ;  CheckPotentialPosition

After:
Code:
;;;;;   For top down type games, or games that generally have no gravity but have 4 directional movement,
;;;;;   we only need to check potential position and jump to the appropriate label.
    	CheckPotentialPosition	;; <<-- uncomment this line (for checking vertical collisions)
	CheckForHorizontalCollision  ;; <<--- checking horizontal solid collisions


Also uncommenting the line 112:
Code:
	CheckPlayerCameraPosition

And also uncommenting the line 128:
Code:
	JSR updateHorizontalPosition


Voilà, now for your Game Objects, Monsters... just set it's action flag to "Ignore Gravity" and it can move as you want.
 
Having so much fun with this.

I almost have all my glitches fixed from the move to 4.1.

After that I'm going to add a new area and boss battle and release an updated demo.
 

dale_coop

Moderator
Staff member
chronicleroflegends said:
Having so much fun with this.

I almost have all my glitches fixed from the move to 4.1.

After that I'm going to add a new area and boss battle and release an updated demo.

Great news! Glad to hear that.
Can't wait for the demo ;)
 

AndyS27

New member
Hey all! First time poster, here.

I implemented your code Dale, and it works wonderfully -- except now the game is experiencing some severe slowdown. I'm guessing it's just running a lot of code. Do you have any recommendations for reducing that lag? Most of the time in my game, there are 2-4 enemies/powerups on the screen at once, so it's really hogging the poor NES's resources. Can you think of any scripts I could disable in the Scrolling Platformer module to free up the CPU?
 

dale_coop

Moderator
Staff member
Hey AndyS27 :)

The scrolling engine is using a lot of memory...and is the cause of the slowdown. I think it's the obvious reason why some code had been disabled (like the code related to ignore gravity).
When you comment don't implement my modifications, the game runs better? If you don't have "ignoring gravity" object on screen, the game runs better? (those code are executed only for "ignore gravity" objects)

You could make comprimises... if you don't need vertical movements disabled it... etc

The scroll is engine sis young and not optimized. With the time, it will run better.
 

AndyS27

New member
dale_coop said:
Hey AndyS27 :)

The scrolling engine is using a lot of memory...and is the cause of the slowdown. I think it's the obvious reason why some code had been disabled (like the code related to ignore gravity).
When you comment don't implement my modifications, the game runs better? If you don't have "ignoring gravity" object on screen, the game runs better? (those code are executed only for "ignore gravity" objects)

You could make comprimises... if you don't need vertical movements disabled it... etc

The scroll is engine sis young and not optimized. With the time, it will run better.

Oh it's worth the trade-off! I just reduced the amount of enemies per screen and the game is running much more smoothly. :) Thank you!
 

dale_coop

Moderator
Staff member
Cool, glad you found a solution.
Yep, as Joe (the new 8 bit heroes) always says, NES dev is just compromises ;)
 

drexegar

Member
dale_coop said:
A small fix for the "Ignore Gravity" action step flag. Currently if you set this flag, your object can't move horizontally nor vertically.

Hey Dale whenever I use ignore gravity my sprites are always lower than its given position. Is there a way to fix that?
 

dale_coop

Moderator
Staff member
Check your projectile script...
If you see:
"ADC weaponOffsetTableX,y" or "ADC weaponOffsetTableY,y"
Replace this with:
"ADC projOffsetTableX,y" and "ADC projOffsetTableY,y"
 

Mossy

New member
hi, so this looks like it will work, but i don,t know how to edit the scripts you are talking about. i couldn't find a way to do it in the actual program, and when i went into the game folder itself and located the user subroutines file you are talking about, i open it up and was greeted with a blank notepad document. do you know whats going wrong here? thanks, mossy.
 

dale_coop

Moderator
Staff member
Yes, exactly, subroutines is empty currently. You can write in it, your own routines... that why I do in this tutorial.
(You will see that other scripts are not blank).

I’d suggest you to install a software that actually display line numbers (like notepad ++).
 

Mossy

New member
cool! that's working, but i don't quite get step four. i don't know what tile collision script to edit in my non scrolling platformer
 

dale_coop

Moderator
Staff member
Open your "Project Settings, Script Settings" locate the "Tile collision" (or Handle Tile Collision"? forgot the exact name of this element... it's one the first elements in the list) and you will see that this element is assigned to the "TileCollisions.asm" script. This particular script is the one you need to modify.
 

Mossy

New member
oh wait, just wondering, whenever i get killed by a monster after losing my 3 health, i respawn and my hud displays my health as 1 or the lightning symbol from the default hud graphics (it should be three). Then, when i next take damage it displays 2. i know the variable itself will always be set to 3, but the hud displays it wrong. im not quite sure, but i think this might not have been happening before i edited that code. however, if i hit an insta kill tile, my hud displays the right number when i respawn. any clue what's going on? (hope im not bothering you)
 

dale_coop

Moderator
Staff member
In the Player Lose Life script, check if the health is set back to 3?
Code:
LDA #$03
STA myHealth
 

WillElm

New member
Do this if you the player to also have the ability to move up and down with ignore gravity on.

dale_coop said:
Ok... I just checked the code from my tutorial (Fixing ignore gravity) and I think I made an exception for the player.
Open the "UserSubroutines.asm"script (located in your "Routines\Basic\ModuleScripts\" folder).
Try commenting out the lines (";" in front of each line):
Code:
	; CPX player1_object							;; check if it's the player
	; BEQ doneUpdatingXPosForNonPlayerObjects
(You have to th that for the lines 5-6 and 24-25).

Now, I think it should work for the player, too.
 

mouse spirit

Well-known member
Thanks dale, but i have an issue.Now on my start screen,i dont see my monster object, and i can no longer start game.the music is still playing though. I used skipstart screen to get past that,when i jump and shoot a projectile,the projectile keeps rising to the top of the screen rather than shoot straight left or right like it did prior.
 
Top Bottom