My First Attempt At A Platformer Engine

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
My First Attempt At A Platformer Engine
by on (#122727)
Hello, this is my first attempt at a platformer engine for the NES. I used the sound engine from the Nerdy Nights tutorials. The source is included along with a ROM, please feel free to mention anything I may be doing wrong or poorly :)

Attachment:
NES Platformer.zip
Re: My First Attempt At A Platformer Engine
by on (#122730)
Code:
DEX
CPX #$00
BNE ReadController1Loop

The CPX is redundant here.

Also, you sould be able to use lowercase for instructions. Less activity on the shift key.
Re: My First Attempt At A Platformer Engine
by on (#122741)
It was hard to get past the first room until I realized I could go left then right to skip the room with the pit under the low ceiling.

Are you intending for jumping to use jetpack-style physics or actual jumping?
Re: My First Attempt At A Platformer Engine
by on (#122744)
tepples wrote:
It was hard to get past the first room until I realized I could go left then right to skip the room with the pit under the low ceiling.

You could also fall down the pit and end up at the top of the screen as well :P. I intend on implementing some sort of Room coordinate system ala-Battlekid. My idea is that depending on what side of the screen you exit on it will increment or decrement the room x,y values and then calculate the room index using index = room_x + (room_y*Max_x).

tepples wrote:
Are you intending for jumping to use jetpack-style physics or actual jumping?

At some point actual jumping will be implemented, it's jetpack-style for now.
Re: My First Attempt At A Platformer Engine
by on (#122756)
I'm noting a short grey glitch mid-screen when dying. Are you trying to set the palette while rendering is off? (It should only be written during vblank to avoid this.)
Re: My First Attempt At A Platformer Engine
by on (#122757)
rainwarrior wrote:
I'm noting a short grey glitch mid-screen when dying. Are you trying to set the palette while rendering is off? (It should only be written during vblank to avoid this.)


Thanks! the palette is now set during VBlank.
Re: My First Attempt At A Platformer Engine
by on (#132371)
Okay so over the past 6 months or so I've completely rewritten this engine from the ground up.
Attachment:
File comment: Updated ROM
Main.nes [128.02 KiB]
Downloaded 253 times


Some new features to the new and improved engine are:
- AI
- Status Bar
- Better jumping physics
- Better background collision detection and resolution
- Different background collision properties ( An example of this is in the water area of the demo wher the water makes you fall slower and some of it moves you to the right as if there is a current).

If anyone wants to pop open an emulator hex editor mess around with things like background collision and AI during run time here are some memory locations and info:

$0700-$071A = AI Memory
Each AI is 9 bytes in size: y,x,sprattributes,sprite#,Health,xVel,yVel,Action,Frame
The action byte, for those who are wondering, basically controls which action "script" is jumped too in the global AI action jump table.
(0 = do nothing, 1 = move left and right, 2 = move up and down, 3 = move in a Zig zag wave, 4 = move in a sine wave)
$0600-$06FF = Background Collision table
Setting bit 7 makes a tile solid, setting bit 0 makes the tile water-like (more resistance to movement than air), bit 1 makes the tile move the player to the right, bit 2 to the left.

When you load the ROM the screen will start black, just press start to begin ( it's in the "menu" state and I haven't really implemented a basic menu/title screen yet). Controls are pretty much like any other platformer on the NES d-pad to move left and right and a to jump. Pressing start and select currently modify the action byte of one of the AI's because I was doing some tests. Lastly when you go to the screens right of the starting area, which ultimately go nowhere, you'll notice the graphics are all messed up. That is intentional and not a glitch as I was testing to see if my tileset swapping between different screens functions correctly.

So yeah enjoy I guess!
Re: My First Attempt At A Platformer Engine
by on (#132372)
Hmm... I dunno, are you looking for feedback?

I'd like to know what kind jump physics you're going for. Currently it seems you're after a jetpack type movement, because it's reversed from a typical jump.

Edit: HAH! I read the rest of the topic. Jetpack style it is. Still, I might slow it down a tad for a more jetpack feel. Possibly take a look at the Yoshi's Island flutter mechanics. I've also managed to kind of hover by mashing A, which supports that the player has a jetpack, but it's very difficult to do this, if this is meant to be a mechanic and not a glitch.

If you hold A button while pressing start, you can just kinda chill in the air.
Edit: Oh, I maybe found out why. $0434 seems to be in charge of how much time is left to hover. At reset it decrements from 0 and wraps through $FF. So you can't float indefinitely as I first thought. Just for a very long time.

Similarly, holding left against walls while a new screen loads allows you to jump off walls. (Jump off the pit in the start while holding left+A. The screen you should fall on allows you to go back up to the first screen, but then you fall to the second screen etc.) Holding down while landing allows you to hover a pixel off the ground. I assume you've begun a crouching state that causes this, since it also prevents you from jumping.

Not bad progress, though.
Re: My First Attempt At A Platformer Engine
by on (#132375)
Thank you for the feedback! Yeah I've kind of moved away from the jetpack style as I have learned more about 6502 programming over the months. I fixed the bug where you can jump off walls and woops I accidentally left some old code in my d-pad down routine (it isn't supposed to do anything) :oops:. I haven't been able to replicate the floating via holding start and A yet.
Re: My First Attempt At A Platformer Engine
by on (#132376)
Being more specific, I mean start the rom. (black screen, game is in menu mode.) Hold A. Don't let go. Press start.

Not holding A+start after the game has begun.
Re: My First Attempt At A Platformer Engine
by on (#132379)
Kasumi wrote:
Being more specific, I mean start the rom. (black screen, game is in menu mode.) Hold A. Don't let go. Press start.

Not holding A+start after the game has begun.


Weird. I'm doing just that in FCEUX,Jnes and Nestopia and everything is functioning as intended; no hovering. Just to be on the safe side though I'll make sure when the game changes state that it clears the controller input byte and resets all the jumping related bytes.
Re: My First Attempt At A Platformer Engine
by on (#132381)
Just so you know I'm not crazy: http://i.imgur.com/3kbQ2pA.gif
Re: My First Attempt At A Platformer Engine
by on (#132383)
Kasumi wrote:
Just so you know I'm not crazy: http://i.imgur.com/3kbQ2pA.gif



Hmmmm, I notice your emulator is in PAL mode ( you're not supposed to see the sprites in the upper left). Have you tried setting it to NTSC? Here try this:
Attachment:
Main.nes [128.02 KiB]
Downloaded 199 times
Re: My First Attempt At A Platformer Engine
by on (#132396)
Light-Dark wrote:
I notice your emulator is in PAL mode

"PAL mode" is a setting that affects timing, not resolution. Both PAL and NTSC consoles generate 240 lines of picture, emulators that crop scanlines in NTSC mode are just (poorly) attempting to simulate the clipping that commonly happens in NTSC TVs, but the amount of picture that's cut varies from TV to TV and you shouldn't rely on that happening. Also, all emulators I know of that crop scanlines allow you to configure how much is cropped.

Quote:
( you're not supposed to see the sprites in the upper left)

There should be no sprites in the upper left! =) The correct place to hide unused sprites is after scanline 239, past the end of the picture. A Y coordinate of anything between 239 and 255 will completely hide a sprite. The X coordinate doesn't matter.
Re: My First Attempt At A Platformer Engine
by on (#132400)
tokumaru wrote:
Light-Dark wrote:
I notice your emulator is in PAL mode

"PAL mode" is a setting that affects timing, not resolution. Both PAL and NTSC consoles generate 240 lines of picture, emulators that crop scanlines in NTSC mode are just (poorly) attempting to simulate the clipping that commonly happens in NTSC TVs, but the amount of picture that's cut varies from TV to TV and you shouldn't rely on that happening. Also, all emulators I know of that crop scanlines allow you to configure how much is cropped.


Okay I see, my bad.

tokumaru wrote:
Quote:
( you're not supposed to see the sprites in the upper left)

There should be no sprites in the upper left! =) The correct place to hide unused sprites is after scanline 239, past the end of the picture. A Y coordinate of anything between 239 and 255 will completely hide a sprite. The X coordinate doesn't matter.


Thank you! That issue has been fixed, sprites that aren't supposed to be displayed are no longer displayed.
Re: My First Attempt At A Platformer Engine
by on (#132421)
New ROM fixes all three issues, yes. No, I was not using PAL mode, as Tokumaru guessed I just unhide all scanlines on all emulators I use.

One other thing, it seems that either your NMI is disabled while switching screens, or your code to update music isn't in the NMI. You can fix the continued single note while switching screens if you keep NMIs enabled and move your update code there.
Re: My First Attempt At A Platformer Engine
by on (#132426)
Kasumi wrote:
New ROM fixes all three issues, yes. No, I was not using PAL mode, as Tokumaru guessed I just unhide all scanlines on all emulators I use.

One other thing, it seems that either your NMI is disabled while switching screens, or your code to update music isn't in the NMI. You can fix the continued single note while switching screens if you keep NMIs enabled and move your update code there.


That's good to hear and thank you! I was wondering what was causing that.
Re: My First Attempt At A Platformer Engine
by on (#132427)
Kasumi wrote:
I just unhide all scanlines on all emulators I use.

Same here. When developing, it's important to see the whole picture your code is generating.
Re: My First Attempt At A Platformer Engine
by on (#136544)
I've been chipping slowly away at this project for a couple of months now and I have more or less got a decent main menu going (Load Adventure is still in the planning stage) with a fully operational Soundtest sub menu (So operational that you can go beyond the song table and play garbage!).
Attachment:
Main.nes [128.02 KiB]
Downloaded 179 times