igwgames / nes-starter-kit

A Beginner's Guide and toolkit for NES game creation.
MIT License
214 stars 24 forks source link

Tutorial on how to remove hud? #34

Open Gabumach opened 4 weeks ago

Gabumach commented 4 weeks ago

Hello! Is it possible to fully remove hud from the game, and let the game use the entire screen for a map? When I try to do it, it ends up in garbage textures or sometimes, game freezing when I try to go to a different room. I apologize if I sound stupid, but I'm a complete newbie to C and this guide in general.

Thanks in advance!

potatolain commented 4 weeks ago

Hello!

So this is technically possible, but it's going to be pretty tough, and it's not something I'd recommend to someone new to the tool or retro development.

The problem is how levels are laid out (relevant chapter). The map generator breaks levels into rooms that are 16 tiles wide by 12 tiles high, which covers a 256px by 192px area. In addition to the tiles, each room contains 32 bytes of sprite information and 32 bytes of padding. If you extend the data you are pulling from the map in your game without changing the map data, you end up trying to draw the sprite data as map tiles, resulting in drawing garbage textures. (Or potential crashes)

It's definitely possible to do, but a tutorial on this would be the most complicated and difficult chapter in the guide, so I am not inclined to write it at this time.


That said, depending on what you want to do I do see a workaround! If you had the current map area centered on the screen without the hud, would that be good enough?

If so, I would update the hud to have almost no data in it, then look at how we use the scroll() method in map.c - you can play with these values to get it more centered on the screen.

A couple disclaimers about this:

  1. I would suggest against changing HUD_PIXEL_HEIGHT for now, as this controls where our sprite0 split happens, and could cause crashes when going between screens
  2. Likewise, don't remove the entire border around the hud - there has to be at least one pixel that lines up with sprite0 in order for split scrolling to work (split() and split_y())

Due to the complexity of the topic I do not plan to write a tutorial on this, but if I can help you further for your case, let's continue the conversation!

Gabumach commented 4 weeks ago

Thank you so much for the response, I appreciate it a lot! I was able to make some progress using your instructions, and now the hud looks like this: nohud Is there any way to remove it completely and how do I increase the level size? I'm trying to recreate this game er0wtqxk and already got the palette working in my homebrew rom.

potatolain commented 4 weeks ago

So unfortunately, making bigger maps is going to be somewhat difficult. I outlined the basic steps above, here's a bit more detail:

  1. Move the hud up by updating HUD_PIXEL_HEIGHT to be 8px, then update the sprite zero position to match that.
  2. Update the hud method to only draw one line of tiles
  3. Update the hud tiles graphics get rid of almost all of the border. Keep a few pixels in the lower right area - you'll have to experiment a bit to see when you can scroll without the game crashing. (The sprite zero/sprite 0 thing mentioned above)
  4. Change the map generation tool to increase the size of each screen, paying close attention to how big your levels are. You want to keep them under 256 bytes per screen, unless you want to rework things a lot more. this is that tool: https://github.com/igwgames/nes-starter-kit-tools/blob/main/tmx2c/src/index.js - you will need to update the javascript, then update the .create-nes-game.json to run your new javascript with nodejs in place of the existing tool -- If you reduce the number of sprites to 8, and use the 32 unused bytes at the end, it should just fit.
  5. Update the map code to pull in those extra tiles when loading the screen.

I know that's a bit loose, and definitely not to the level I write chapters in this guide, but I hope that's a good starting point.