19. Game Coding 2

 

 

Now, I’ve rewritten all this…

Bullets are also defined by structs.

struct BULLET {
unsigned char Y; // y = 0 = off
unsigned char Y_sub;
unsigned char tile;
unsigned char attrib;
unsigned char X;
unsigned char X_sub;
unsigned char Y_speed; // high nibble = speed, low = sub
unsigned char X_speed;
};

And, most importantly, I’ve redesigned how sprites are drawn on the screen. It’s done dynamically each frame. First, I move all sprites (in the OAM buffer, RAM addresses $200-$2ff) offscreen (Y coordinate > $f0). Then I draw the Sprite Zero, then each active sprite object is put into the buffer. I’m varying the order that they are added to the buffer each frame, so that they flicker.

And, now I’m using NES screen tool to generate metasprite data. I wasn’t 100% happy with the code provided in Shiru’s example code…so I rewrote it all. Specifically, if the metasprite starts to go offscreen, it won’t be half on the right and half on the left. The rightmost sprites will be pushed offscreen (to the bottom). It’s far less efficient code, but it looks nicer. Also, I wrote it so that any metasprite can be flipped horizontally (and possibly vertically). Then, to convert the ‘save metasprite bank’ output to a format that will work well with my system…I wrote a python script to reformat it. It only works with 1 metasprite at a time, and you still have to manually type the reversed x coordinates. That’s because metasprites don’t have a standard width.

Anyway, it’s now easier to make and edit metasprites.

In the example code, down = spawn some bullets. Select = spawn some ships. You can see that I’m testing Horizontal flipping on one of the 3/4 enemies.

I also added a much more efficient hitbox code, in ASM, now that we are increasing the number of sprite object collision tests.

 

spacy2b

 

 

http://dl.dropboxusercontent.com/s/fczfdpahrdgb7rl/spacy2.zip

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s