Tuesday, April 21, 2020

NES Anguna

Well, I had a little bit of time still, while Frankengraphics is finishing up her game Project Blue, to have a little downtime on Halcyon, so I decided to see what kind of side project I could do in just a handful of weeks, but would be a full-sized decent game.

Because I tend to go big (Anguna, Halcyon), or small (cheesy competition games like Robo-Ninja Climb), but I rarely do anything medium sized. Which means that despite being part of the nes homebrew community for around 4 years now, I still don't have any games released on cartridge.

So I started brainstorming -- what's something I could make and finish quickly, but is worthy of a cartridge release?



What I came up with is Anguna. again. But what would make this port fun is to see how much of the Atari version I could reuse.  By remaking the same game, reusing the Atari code and world definitions, could I throw the game together in record time?

Both the NES and the Atari use the 6502, and the NES has 16 times as much RAM. So in theory, I could take the Atari code and plot it almost directly into the NES, and the game logic would run.  I just wouldn't have any I/O.

So...I/O.  That means graphics. I would need graphics for this port -- reusing the Atari graphics wouldn't cut it. With some experimentation, I found that most of Chris's sprites from the GBA Anguna would work if I converted them to be 3-color sprites instead of 15 colors, and cut the number of animation frames in half.  The background graphics weren't going to work well though, because of the color use and assumption of a foreground layer that you could walk behind. But I found some nice zelda-like art on opengameart.com that looked like it would work, so I figured I had everything I needed to try to port this game as quickly as possible.

I also decided to keep it mostly secret. (which is why I've been quiet here). I've said a lot about Halcyon, but I wanted to free the freedom on this project to quit halfway through without feeling judged.



I won't go into too many details about the development process (because I'm lazy), but some points of interest:

  • Bringing the main engine in went without a hitch. Just a few hours of converting assembler syntax, I had a no-graphics proof of concept running.
  • Replacing the graphics code for sprites was pretty quick and easy, thanks to enough tools that I'm comfortable with from other small projects. Actually wrangling and preparing each sprite (by loading the GBA version, playing with the palettes, rearranging tiles to make it fit in the reduced space, etc), took a good bit of effort. Particularly for the main character sprite.
  • Collisions took some time to get working, because I had depended on hardware collisions on the Atari, but the NES doesn't have any hardware support for collision detection. Collision logic wasn't difficult, but took some re-writing.
  • While the overall room contents stayed the same, room layouts had to change from the Atari layouts to accommodate the NES graphics. To design the room layouts, I pulled in the whole map tooling/pipeline from Halcyon. This was a bit of overkill, as these are non-scrolling small maps, but it was quick and easy, which was the goal. 
  • Doors (opened by killing enemies, or that close behind you) took longer than I expected. I had weird specific Atari code to handle them using various atari graphical objects (the atari "ball" was used for asymmetrical doors), and that had to be replaced by code that would update the NES nametables on the fly when you opened or closed doors.
  • One of the things that took the longest was the "glow" that surrounds the player in dark rooms. This was a pain to get right, and still looks a little janky. I just rewrite the background tiles as you move around the room.  It was annoying enough to program that I almost ditched it, but I felt like it was one feature that distinguishes the game from a NESMaker game, so it was worth keeping in place.
  • I hired Thomas Cipollone to compose music for it, which was a great decision. He cranked out a handful of good melodies to make the whole thing sound good. 
  • Beyond that, the other thing that took time was just reworking all the extra things: title screens, menus, subscreen, status bar, ending sequence. All that had to be completely rewritten, and all that stuff takes longer than you'd like.
That all said, I started somewhere around Christmas, and the game is "done" and ready for testing now in April. So a full adventure game in 4 months of spare time isn't too shabby.

Next steps are to test like crazy, polish and debug anything that's too broken, and then figure out how I want to go about publishing and selling carts. Then back to Halcyon!

Wednesday, December 11, 2019

NNNNNN in 12 hours

I recently announced my NESdev competition entry for this year: NNNNNN, a multiplayer NES port of the Gravitron from VVVVVV.  Now that it's done, I thought I'd share about the development process.

What to make?


The first question I had was what to make for the competition? Because I'm focusing most of my effort on Halcyon these days, I wanted to think of a game that I could develop really quickly, but still be fun. Treating it like a short game jam, I wanted something that I could take from start to finish in a week's worth of evenings, but still be a reasonably fun game. Honestly, this was the hardest part of the process, which I've been mulling in my brain for months. I have a few ideas (some of which I still might save for next year), but all of them are things that either don't sound fun right now, or would take just a little more work than I'm prepared to invest.

But about 2 weeks ago, it suddenly dawned on me that a NES port of the Gravitron would be tons of fun to play (at least in my opinion), really easy to write, and light on assets (ie I wouldn't need to spend ages fussing with finding new graphics). The only real problem was IP -- what happens if Terry Cavanagh finds out and shuts down my effort?  I debated whether to get permission ahead of time, or to wait and ask forgiveness. But decided that regardless, I'd start on the project and see what I could come up with.

Research


Step 1 is probably the easiest part. Play the game a bunch, and take some notes, to see if it would be as simple as I remembered. There's some Youtube videos out there of people playing the gravitron, which is helpful, and there's a free dedicated Gravitron-only app for mobile. So after spending 20 minutes looking at how the game worked, I was more convinced than ever that I could pull it off.
The most important part of this research bit was thinking through how to make the game match the NES restrictions. The important bits (the top and bottom borders and the timers at the top) could easily be made with background tiles, and the character and obstacles are obviously sprites. There's not too many colors, and not too many sprites on any given horizontal line, which are normally two of the major things that are hard to convert to the NES.

A screenshot of the Super Gravitron from my phone
The aspect ratio was going to be a problem. The original gravitron is really short and wide, which is problematic for the nearly-square nes screen. I'd just have to make do with making a smaller play area (which makes the game a little harder), and going for it.  I was also a little concerned about the animated backdrop. Animated backdrops can be difficult on the NES, and it wasn't completely obvious how I'd be able to pull that off. But I figured that this wasn't a show-stopper, so I'd move forward and figure it out when the time came.

Getting Started: the easy stuff

Now the race has begun, and I wanted to see how quickly I could get this thing off the ground. Because the goal was speed more than cleanliness, I started by copying my entire git repository from Super Homebrew War, and then going through and doing mass amounts of deleting unnecessary code. Within 30 minutes or so, I had a good skeleton of a project, which would start-and-do-nothing without crashing.

I loaded a screenshot of the original game into GIMP and extracted the player and obstacle graphics, and fairly quickly coded up the majority of the main character's behavior in C.  Because the player does nothing but move left and right, and uncontrollably bounce, this was another simple process. I pulled in some existing bitmap fonts (stolen from another old NES game, which, as it turns out, is legal in the US, because bitmapped fonts aren't eligible for copyright!) Using NES Screen tool, I sketched out the general layout of the screen, and had the very basics of the game going without a hitch.

The easy parts are done!  Now I have to start using my brain....
The game also needed music, so I copied over the ggsound library that I've used in previous projects. I had a techno-sounding song lying around that I had previously commissioned from a composer known as Chip Jockey (I had bought the song without having any idea what I'd use it for), so I plugged it into the game, and it sounded great.

Next: Obstacles


I've been doing enough NES game development recently that this type of thing is fresh in my brain and easy enough to churn out. The concept of a handful of obstacles, which merely march across the screen with a simple animation, was really simple. The harder part is figuring out the spawn patterns of the enemies. Back to research mode!

I watched a few videos of the game, and made some notes. The enemies clearly come out in some pre-defined patterns, which seems to randomly selected. That's enough information for now.


But now I actually have to start using my brain. How do I want to store and process the spawn patterns?  I decided on each pattern being a list of pairs of bytes, with each byte being a list that tells enemies spawning that frame, and a timer until the next frame:

pattern1:
.byte %10010000, 10    ;First bit is left or right side
.byte %10001000, 10    ;bits 2-6 are the Y position of which
.byte %10000100, 10    ;enemy to spawn. So this will spawn

.byte %10000010, 40    ;4 enemies in a diagonal line, 10 frames
.byte $ff              ;apart. The $ff marks end of the pattern


This is the first part of the process that took any real debugging and work, making sure my bit shifts and comparisons were correct for each byte in the pattern array.  But with that in place, I had enemies spawning. Using the famous fast rectangle collision routine from AtariAge user Supercat, collisions against the player were simple and fast. Although I only had a couple of test patterns, and the timing and speed of everything was way off, and hitboxes needed to be adjusted, I had the bones of the game in place, after 4 or 5 hours.

Fans of the real game will notice that I have the sprite falling backward (head-first). I didn't notice until significantly later in the process.

Backgrounds


Now things start to get interesting. It's time to see what I can do about the background. First is the timers at the top of the screen. It's easy to put the "current time" and "best time" text as part of the background graphics, as well as the times. But it was also time to think about the animated backdrop. I did a lot of thinking about this during the rest of development.  The big issue is that the NES can only change a handful of background tiles per frame, because you (generally) can only write to the background safely during vblank.  There's not enough to time to rewrite each background tile. And really, using basic 8x8 pixel background tiles is messy for doing a big animated backdrop like the one in the gravitron.

Eventually I decided that I needed to take advantage of the CHR-RAM and redraw the actual tiles every frame.

For those non-NESdev folks reading this, the NES handles graphics by taking pre-made 8x8 tiles, and arranging them on the screen. A lot of games use CHR-ROM, which means the actual tile graphics are on a ROM chip in the cartridge, and can't be changed. Others use a RAM chip for the graphics, and copy the graphics from the game's main program ROM to the video ram at run time. There are advantages and disadvantages of both methods, but by using CHR-RAM, I can, on every single frame, redraw the handful of 8x8 tiles that make up the backdrop.

I sketched it out and determined that I'd need to redraw 16 different backdrop tiles in order to animate this properly. That's 256 bytes of data that would need to be written during vblank, (about 1800 free cycles after OAM DMA finishes)  That's doable, but would definitely require me to optimize things. First, I decided that the millisecond part of the timers (At the top) could be sprites, so I wouldn't have to update them as background elements, saving a little time. (I could cheat for the seconds and minutes, and just skip updating the backdrop when I update them, which wouldn't be noticeable at one missing frame every second)

Then, I needed to optimize and unroll all the background tile updated during vblank. A naive way of re-drawing a tile during vblank might use a loop like this:


;first tell the NES what video ram address you 
;want to write to.
  lda #TILE_VIDEO_RAM_ADDRESS_HI_BYTE         ;2
  sta PPUADDR                                 ;4
  lda # TILE_VIDEO_RAM_ADDRESS_LO_BYTE        ;2
  sta PPUADDR                                 ;4

;then do a loop to write from a ram buffer to the tile

  ldx #16                                     ;2
top:
  lda buffer,x                                ;4
  sta PPUDATA                                 ;4
  dex                                         ;2
  bpl top                                     ;3 

That's 13 cycles per byte, plus 14 cycles of setup (minus 1 cycle for the last bpl). If I did my math right, that's 221 cycles per tile, or over 3500 cycles. About double what I have available.  But hardcoding addresses and unrolling things saves a ton of time:

  lda #TILE_VIDEO_RAM_ADDRESS_HI_BYTE         ;2
  sta PPUADDR                                 ;4
  lda # TILE_VIDEO_RAM_ADDRESS_LO_BYTE        ;2
  sta PPUADDR                                 ;4

  lda buffer+0                                ;4
  sta PPUDATA                                 ;4
  lda buffer+1                                ;4
  sta PPUDATA                                 ;4
  lda buffer+2                                ;4
  sta PPUDATA
  ;etc, 13 more times



Using this method, it's 140 cycles per tile. That still comes to 2240, which is too much, but we're getting there. Luckily, due to the pattern of how the backdrop updates, a few of our tiles are the same thing repeated vertically, so we can optmimize them further:

  lda #TILE_VIDEO_RAM_ADDRESS_HI_BYTE         ;2
  sta PPUADDR                                 ;4
  lda # TILE_VIDEO_RAM_ADDRESS_LO_BYTE        ;2
  sta PPUADDR                                 ;4

  lda buffer                                  ;4
  sta PPUDATA                                 ;4
  sta PPUDATA                                 ;4
  sta PPUDATA                                 ;4
  sta PPUDATA                                 ;4
  sta PPUDATA                                 ;4
  ;etc, 11 more times    
   
That's only 56 cycles!  It's enough to balance things out, and let us fit into the limited time during vblank.

To verify, I used Mesen's event viewer to see if all of my writes to video memory occurred during vblank, and it looks good!
All those dots at the bottom are writes. And they're all in that big blank space at the bottom, where they belong.

Now let's see what the tiles look like when animated:

Trippy!

So the finished effect, which probably took more time than any other single element of the game, at about 3 hours, looks like this:
 


Making it match the real thing


At this point, I felt like I had all the features in place, so it was time to play it back to back with the real thing and see what needed to be adjusted. I knew my speeds/timings were all off, and I had none of the real patterns from the game.

So I opened up a youtube video of someone playing the game, resize it to match my emulator size, and started adjusting things to match the speed. After a few minutes, I had the movement speeds all close enough.

There were a few other minor things that I had forgotten (the enemies change color, and the top and bottom trampoline borders changed color when you hit them). These were fairly simple changes based on how the NES uses palettes.

The one important thing that I had forgotten was warnings about upcoming enemies. These are small arrows that appear on the sides, and warn when an enemy is about to spawn there. They're crucial to surviving, particularly if you take advantage of wrapping around the screen to dodge obstacles.

Unfortunately, adding these warnings wasn't quite as straightforward as everything else in the process.  Because they appear about half a second before the actual obstacle, they could be part of the same pattern as currently-spawning obstacle, or the next pattern, or even (for very short patterns), 2 patterns ahead of the current obstacle.

Previously, I had been only tracking the "current" pattern, and when that pattern finished, I'd randomly pick a new one. But now I had to keep a short queue of patterns.  The pattern a half second in the future, the currently spawning pattern, and any patterns in between.  So I basically have to have a few things:

- A queue of pattern ids
- A pointer to where in the queue we're at for the "warnings".
- A pointer to where in the queue we're at for the "current"
- A pointer to where within the "warning" pattern we're curretly at
- A pointer to where within the "current" pattern we're curretly at

It wasn't overly complicated, but was just enough logic and fiddly indirection that it actually took some real debugging, as opposed to most of the rest of the project.

After I finally had that working, I sat down with a piece of paper and the youtube video (set to 1/4 speed), and wrote down all the enemy patterns that spawned. To this day, I'm still not sure whether every single pattern was pre-generated, or if some of them were completely randomized. But to simplify the game, I limited it to a handful of the patterns that I saw during the first few minutes of the video.  Transcribing them to the source code took another hour, but after that, the game was in pretty good playable shape!  At this point (around 9-10 hours), I was confident that I had a viable entry for the competition.





This was also the point where I decided that I should probably check about getting actual permission for this project.  With much fear and trembling, I send Terry Cavanagh a message (on twitter) with a screenshot, telling him that I had made the game, and asking if I could release the rom. His response: "Sure!"  WHEW.  That worry was resolved.

Title Screen


Next up was a title screen. I lucked out by the fact that I had (by complete accident) included my font in just the right place in video memory so that the tile id of each glyph was the same as its ASCII code. That meant that I could actually use C strings for text! I whipped together some routines in C to write text to the screen (which were horribly slow, but because they run during couple frames of black screen before the title appears, nobody would notice). With those, I threw together a primitive title screen, but it was ugly and needed something.




The title screen for the mobile Super Gravitron had these cool-looking little rectangles flying around in the background, so I stole that idea. Using sprites, I generated a bunch of them to randomly fly around. And because they have no logic other than flying across the screen before reappearing randomly somewhere else, they were painless to create.

Multiplayer


Now really what I had been hoping to add all along (but not sure if I'd have time) was multiplayer. I'm a huge fan of 4-player simultaneous games (which are sorely lacking on the NES). And the chaos of this game would be perfect for multiplayer madness.

For the most part, adding extra player characters was straightforward, but two things are worth mentioning.

First, I did something goofy for the main character logic -- instead of handling each character's input and updates in a loop, I copied the player update logic 4 times.  Why?  Becuase I wrote it in C, but the 6502 C compiler is notoriously bad about handling loops where you loop through elements repeatedly in arrays. Instead of storing the loop counter in a register (x or y), it stores it in a variable, then reloads it to x every time you try to look up a value in an array.

So to keep the performance from being stupid, I really needed to either rewrite the routine in assembly, or copy/paste the routine 4 times and let it hard code the addresses.  I chose copy/paste because I was at around 11 hours and wanted to be finished.

The other painful thing was handling player deaths. When a player dies, everything pauses, the player changes color for half a second, then the remaining enemies do a cool extra-fast flyaway, then it starts over. Somehow, even though it seems really simple, I had a difficult time getting the logic right to handle deaths for all 4 players.  I just kept introducing bugs when trying to manage the "make the player stop moving and change color while dying" state for some players but not all players were dead. I don't know why I had so much trouble with it (the logic isn't complicated!) but I wasted a good hour on it.

Finished?


Now everything was done.  Except one small thing. There's a sound effect that occurs when you die, and I wanted it in the game. And I wanted it to sound somewhat like the real thing. And I'm terrible at making sound effects.





There's a great program out there, FamiTracker, for working with NES audio. But I'm not very good at using it. And certainly not good at trying to reproduce an existing sound. But there was no other way to do it, so I used my last hour fiddling with instrument settings in FamiTracker until I got this sound reasonably close to the real thing.

Finished!


So, after about 12 hours of work (spread out throughout the week), I was done!  I loaded it onto a cart (which is always scary, as it usually never works right on hardware), and (thanks to the accuracy of Mesen), it worked on the first try! I gathered my family around and forced them to test it out with me. Our family average was somewhere around 3 seconds per life.  Success!

All in all, I'm pretty happy with how it turned out. There's definitely some things that could be slightly closer to the real thing (better analysis of how the patterns were generated, making sure speeds matched the real thing, making fonts match, etc), but I feel like it captures the fun energy of the original game and successfully adds a multiplayer element.  And I managed to pull off a reasonable competition entry in a week.

You can download the game here. If you try it, let me know your best time!
 

Wednesday, November 20, 2019

Seeker missiles revisited

If you follow me on twitter, you saw back in February that I was attempting to get enemy-seeking missiles working correctly. At the time, I felt like I got all the bugs worked out, and they were good to go. But now that I'm at the point in content-creation of the game that the player actually GETS the seeker missiles, I'm not quite satisfied with how they behave, so it's time to revisit them.

The thing about seeker missiles (or any sort of "move an entity directly toward another entity at a set speed) behavior is that it's not as simple to get right on the 6502. (at least if you care at all about performance and would like to get more than 1 frame per second in your game).

The reason why is because of trigonometry.

There are two parts to making good enemy-seeking missiles. First is to select which enemy to target (usually the closest, although you might have a priority system instead to that they always target the most dangerous enemy or something. For this post, I'll assume we're targeting the closest enemy)

The way you'd do this on modern hardware is by first finding the closest enemy by using the Pythagorean theorem -- distance is the square root of x2 * y2. You can even omit the square root if you only care about finding the closest -- just find the sum of squares of the x and y distances for each enemy, and the closest is the smallest.

Unfortunately, arbitrary multiplication is slow on the 6502. Without a multiply instruction, you're stuck adding in a loop, (or bit shifts for multiplications times a power of 2). If the x distance is 74, that means adding 74 to itself 74 times in a loop.

That would look something like this (squaring a single 8-bit value into a 16-bit value):

  ldx val        ;3 cycles
  lda #0         ;2
  sta result     ;3
  sta result+1   ;3  (11 cycles for loop setup)
:
  lda result   ;3 
  clc          ;2
  adc val      ;3
  sta result   ;3
  lda result+1 ;3
  adc #0       ;2
  sta result+1 ;3
  dex          ;2
  bpl :-       ;3  (24 per each time through loop)

  ;11 + (24 * 74) = 1787 cycles 


I scribbled that down without checking it, so it may be off by 1 or something, but it's something like 6% of a frame just to do that single 74*74 calculation. Good luck trying to also do y2, then computing this for each possible enemy. So we need a better way.

To be honest, I haven't found a perfect solution for this. Luckily, for this part of the problem, we don't really have to be exact. If the missile targets an enemy that's not exactly the closest, I don't really care.  So for this first step, I just compare x + y instead of x2 * y2. Sure, that overestimates how far away enemies are that are more diagonal from the missile, but ... I don't care.

The more interesting part is the second half of the problem. Doing the math to determine the X and Y components of movement to move the missile toward the target.

The easiest solution is just to move at full speed horizontally until your x component matches the target, and also move at full speed vertically until your y component matches the target.  The problems with this are obvious though: the missile moves too quickly in a straight diagonal, until it gets even with the target in one dimension, then moves straight until it hits it.  This is a fairly obviously ugly movement.  It's fine in some cases, particularly if the entity is moving fast enough that you don't really pay attention to the movement itself.  I used this method in Super Homebrew War when a player gets the "swap everyone's location" power.  I didn't have the programmer time or rom space for something more complicated, so I just went with this. The swapping all happens so quickly that you don't really notice that it's ugly.


Another solution would be to use to a constant TIME instead of constant VELOCITY.  If you assume that the missile will always take approximately a second to reach the target, you can divide the x distance into 64 pieces (dividing by 64 is fast with bit shifts), and divide the y distance into 64, and move each by that amount every frame.  That will produce a nice even movement, BUT the speed will change based on the total distance traveled. A missile will take the same amount of time to reach enemy A as enemy B, which may be undesired.
The REAL solution involves trigonometry, which is hard on the 6502. You find the angle (the arctan of y / x). Then to find each frame's x and y components of movement, you use cos(angle) * vel = x.  (or sin to find y).  It's simple high school trigonometry. Easy if you have a calculator or a modern processor. Not as easy on the 6502.

But for Halcyon, I want things to look nice and polished, so I wasn't happy with either of the two previous solutions. So trigonometry it is.

For the arctan, I found a pre-written routine that does a pretty good fast estimation of arctan that was written by one Johan Forslöf. I don't pretend to understand the math behind it (he claims it simply "uses logarithmic division to get the y/x ratio and integrates the power function into the atan table"), but it does what I need it to do.

For sin and cos, the trick (like many things on the 6502) is just to use pre-computed tables. If you assume that the angle is a 1-byte value, then there are only 255 possible sin values you have to compute. So you can compute them ahead of time (using a python script or something similar), and just put them into your rom as a lookup table. The cartridge rom that I'm using for Halcyon has plenty of rom space, so a 255-byte table is no big deal.  Then to compute the sin, you just look up the precomputed value for any angle. Table lookups are one of the things that the 6502 does best, so this is nice and fast:

ldx angle      ;3
lda sinTable,x ;4 (7 cycles total)

For cosine, you can take advantage of the fact that cosine is just sine rotated by one quadrant, so you add (or is it subtract? I never remember) 64 from your angle and use the same table.

So with these tricks, you can have a pretty nicely functioning enemy-seeking missile, without using too much CPU time.

Now if I could only figure out why it's not working, and my missile is just bouncing along in a goofy-looking sine wave pattern.










Tuesday, November 12, 2019

Scrolling glitch

For an 8-way scrolling engine with 4 nametables (ie 4 in-memory screens for the camera to pan across), it's easy to end up with a lot of small glitches in the background. Scrolling diagonally across the seam of screens, it's easy to get some of the PPU memory address math wrong, and end up writing to the wrong spot on the screen. But it might only happen when the screen is aligned exactly wrong, so it can take awhile to find and fix all the glitches.

The gray outline shows what's actually on screen. The rest is video memory that's not shown.


Over the past couple of years of working on this project, I've gradually worked through what I thought was every single scroll glitch, and fixed them. Mesen, the NES emulator that I use, has some wonderful features for debugging this sort of thing. You can play through the game, and when you notice a rare, hard-to-reproduce bug like this, you can save your game history, then go back and replay the whole history through the debugger, stepping through what you did, rewinding if you went too far, and watching updates as they happen. It's amazing.

Despite all this, there's one scrolling glitch that, until tonight, I've never been able to reliably reproduce enough to find and fix. It only seems to happen in one particular room, and then, only rarely, even if I do the exact same movement when I enter the room.

The room that gave me all the trouble. Depending on some random numbers, you can end up with 7 enemies going at once, which has the potential to slow things down.



Luckily, tonight I caught the glitch in the emulator!  I went to quickly hit the "save history" button, and I accidentally pressed "reload save state" and jumped back to some previous point in the game, and lost it.   ARRGH!

But, I had the good fortune of being able to reproduce it again fairly soon after, and this time I managed to save the history, and replayed it over and and over and over again.

It didn't make any sense -- as I was scrolling diagonally through the room, it would just skip updating the background for a single frame. So instead of writing new tiles at the edge of the screen, garbage tiles would just scroll in instead. I couldn't figure out why it was skipping an update.

After about the 30th time I replayed it, though, I noticed something. My frame counter was jumping from $1d to $1f when I advanced a single frame. That's not right! 

To make a long story short (too late), I tie some of my scroll logic to the frame counter (to alternate between a few types of updates). In the rare case that too much is happening in a single frame, you can end up with that dreaded NES slowdown, which means that you hit vblank before you finish your frame's logic (ie you get 2 screen draws per logical frame, cutting your game to 30fps instead of 60).  During the screen draw interrupt (NMI) is when I advance my frame timer. 
You can use a grayscale bit in the video settings as a poor-man's profiler. The gray shows how much of my CPU time I'm using this frame.


So this one single room has enough enemies to very occasionally cause a slowdown (usually only for 1 or 2 frames so I never even notice), BUT during those slowdowns, my frame timer advances twice per logical frame. So my scrolling updater (which depends on that timer) fails.

It was an easy fix once I realized what was happening -- I now just use a separate counter for the background updates, and only increment it after actually doing an background update. It wastes a byte of ram, but this is the NES, which has a whopping 2k of ram! What's a wasted byte?

So now, for maybe the 100th time, my git commit message said "Fixed what was hopefully the last scroll glitch."  Maybe I'm actually right this time?

Monday, November 11, 2019

Who needs enemies?

One of the things I keep thinking as I'm building content in Halcyon is "does this room really need any enemies?"  I mean, the fun of the game is supposed to be about exploration. Enemies just slow that down, right?  Or maybe it's just that I'm being lazy and don't want to figure out what enemies to put into a room. Do I need to mix it up for each room, or is it ok to have a few rooms in a row with really similar enemies?  Will the players find this room to be boring, too similar to the last room? 

I have no idea.  But regardless, it sure is tempting to leave a lot of rooms empty.

Tuesday, November 5, 2019

Enemy names

I realized that I'm not all that creative when it comes to enemy names. For my enemy code, each enemy has a textual name that it's referred to in labels, in the map editor, etc.

Here's a handful of the names so far:

  • flapper
  • hopper
  • walker
  • gunner
  • diver
  • zapper
  • spitter
And then some that are even more boring:
  • blob
  • boss1
  • boss2
  • boss3
  • barrier
  • fish
Good thing these names are all secret....

Saturday, November 2, 2019

What sort of game is this anyway?

I've said before that I'm making a Metroidvania. A kind of mash-up of Metroid and Blaster Master in this case.  But these days, that Metroidvania label (as well as "rogue-like") gets attached to almost everything under the sun. Dead Cells, a procedurally generated level-based action platformer routinely gets labeled as both a roguelike and a metroidvania (while I would say it is neither).  Even among things that actually could accurately be described as Metroidvanias, there's a huge range of variety in what that can mean, and what sort of thing a game really is. So this post is my attempt to answer the question: "What sort of metroidvania is Halcyon?"

To answer that, there's a number of different aspects that are worth discussing: non-linearity, challenge, and reward structures. Let's dive in.

Linearity


The first question is how linear is the game? At the far non-linear side of the spectrum are games with a big open world where you can really go anywhere in any order you want. The recent NES homebrew game Lizard by Brad Smith is a good example of this, as is Super Pitfall. There's a big giant world, and it's yours to explore. You can really do things in just about any order you want.



You can go any way you want in Super Pitfall, but mostly you just die. A lot.


Then there are games that have a little more linearity to them: the original Metroid is a good example. You can't really progress until you find the missiles and bombs. But when it comes down to it, you can go kill Ridley or Kraid in either order, without ever finding a number of the other powerups.  There may be a recommended order to do things, but you're not always doing everything in the same order.  (The original Legend of Zelda was very similar in it's non-linearity. There was an order to the dungeons, and some of them required items from other dungeons. But there's not much preventing you from doing some of them out of order(and we did so when we were first exploring the game as kids....if you got stuck on level 6, you went on to try level 7 instead).

Next up are games that are slightly more linear, like Super Metroid. Advanced players know how to exploit the game and can do things out of order, but the average player will end up doing things in mostly the same order every time. Sure, there's plenty to explore, and plenty of secret passages that you may or may not find. But the general order ("find this powerup to open the way to the next section. Find another and then you can go back through that other section") is generally the same for each player. (assuming they aren't purposely going back and trying to break the game sequence).

Despite the awesome Metroidvania-style map, Circle of the Moon was a huge disappointment to me. Each colored section was a distinct "level" that you had to play through in order.



At the far linear end of the Metroidvania genre are games like Castlevania: Circle of the Moon. Although it's one big world, it's divided into clear level-like areas. You beat the boss of the first to get an item that lets you explore the next. Beat that next level, and you get rewarded with the power that lets you explore the 3rd section. And so forth. These are the least interesting to me: although they pretend to be big contiguous-world metroidvanias, they're really not much different than a linear level-based game.

Where does Halcyon fit into this spectrum? I'm attempting to place it somewhere between Metroid and Super Metroid. I'd like the player to have a little bit more freedom in the order of things than Super Metroid, but I found Metroid to be a little too painful in terms of a beginning player not having any idea of where to go. A few parts of Halcyon will require you to go get powerup X right now to continue, but there will be other parts of the game where you can decide which way you want to go, with a number of different areas to explore and routes to take.

As a side tangent -- the world in Halcyon is a euclidean contiguous world. There are no warps between worlds or front/back (like Goonies 2) or weird non-euclidean layouts like Blaster Master. It (like Metroid) is just one large mappable world.

Difficulty


I've made some hard games in the past. My friends who have played my original Robo-Ninja for Android may have had some unkind words about me at times. Robo-Ninja (also a metroidvania) was designed to be HARD. The world wasn't big or complicated, but each room was a challenge.

Robo-Ninja -- possibly the world's first tap-to-jump metroidvania?



When I'm talking about a difficulty spectrum here, I'm talking not about how big or confusing the world is, but how difficult the enemies, obstacles, and other "platformer skill" elements are. The original Metroid was a pretty tough game, particularly at the beginning when you didn't have many energy tanks). Lizard is HARD -- you die A LOT. Blaster Master had a weird difficulty curve -- some levels were really easy, but some levels (and bosses) made you want to punch the screen.


The game was fun and easy-going until you had to fight THIS GUY.


Super Metroid, on the other hand, wasn't a very hard game. There were a couple parts that were tricky, but you really didn't die all that much. The fun of the game was exploring and figuring out where to go, and looking for secrets. The enemies were mostly just there to keep you on your toes.

Symphony of the Night was also like that. Other than that one boss (I don't remember his name, but I'm sure if you played it, you know who I mean), it was a fairly easy game, mechanically. The joy of the game wasn't in the finesse of fighting and jumping.

Unlike Robo-Ninja, this time I'm going easy. Halcyon is (hopefully) going to be more like Super Metroid or Symphony of the Night in this regard. If I can get the difficulty set the way I want, you might die a couple times, just enough to keep you interested and careful. But the combat isn't supposed to be hard. Anybody with moderate video game skill should be able to take their time and explore and enjoy the game.

Reward


One of the things that I want from Halcyon is for exploration to feel rewarding. Super Pitfall had a giant world with lots of areas to explore, but it was just a vast mostly-empty world. There was nothing that made you feel rewarded when you went this way vs that way. You'd explore a route and die, without having found anything interesting. You'd try a different route and die. You never seemed to make any sort of progress.

Lizard also had a fairly brutal reward system (in my opinion). There were coins scattered around the world, but you had no idea what they were for, and you'd lose them if you died. If you explored a lot, you could find a new power (a new lizard costume), but you didn't get to keep it. Even defeating a boss just mostly felt confusing to me.  These were all purposeful design decisions that Brad made (as opposed to just poorly-designed flaws), but playing it helped me figure out what sort of feeling of reward I wanted to put into Halcyon.

This screenshot from Lizard sums up how I felt most of the time.


First, I wanted a map screen that would be permanently revealed as you explored. (Like Super Metroid, Symphony of the Night, or many other newer games). With a revealed map, you always feel like you're making progress. Even if you get fairly lost, and don't discover where to go, your adventurous route is marked on your map. There's some internal feeling of reward in uncovering the map. You did something permanent. You got here once and you know how to get here again.

Second, I wanted a lot of powerups scattered throughout the world. Heart containers in Zelda and missile packs in Metroid were great -- they could distribute them freely all over the place, giving you lots of minor rewards throughout the game. I love Super Metroid's method of putting a minor reward behind some secret passage. The real thrill was finding the secret passage, but they gave you a permanent upgrade as a reward once you found it. To make this happen, I have a number of types of powerups in Halcyon, so that I can hand them out like candy. There are a few major ability powerups (which are the keys to unlocking content and progressing), but there are also new alternate weapons, max health increases, weapon power increases, energy increases, etc.  If it was ONLY health increases, I think they would quickly become boring and lose their sense of reward. So my goal is to have all sorts of types of things to find to keep it feeling rewarding.

A tiny sliver of Halcyon's minimap


Hopefully my describing where Halcyon fits in along each axis will help provide a better picture of "just what is this game all about, anyway?" But just a few more bullet points might be helpful:

- There's a little bit of story/plot, but not much. If all goes to plan, and
  we can get the details ironed out, there will be an opening story sequence, a tiny bit of plot along the way, and and ending story. But this won't be a story-driven game. You won't be talking to lots of people, getting clues in towns, or interacting with a lot of characters and dialog.

- Like Blaster Master, there will be a dynamic of getting in and out of your
  vehicle to explore different areas that are better handled on foot or in-vehicle. Unlike Blaster Master, there are no overhead sequences. The world is one single contiguous side-scrolling map.

- There will be secret passages and hidden items. More Metroid than Blaster
  master in this regard. Some will be pretty obvious. Others might be rather difficult to find. (dare I say obtuse?) My goal (if I pull it off well, which I may not) is that all of the secret passages necessary to win the game will be fairly intuitive to find, while many of the optional routes or powerups will be better hidden.

 If you have any questions, I'd love to hear from you! Pester me on Twitter or email at nathan@bitethechili.com.





NES Anguna

Well, I had a little bit of time still, while Frankengraphics is finishing up her game Project Blue, to have a little downtime on Halcyon, s...