2019-02-22 17:27:09 +00:00
|
|
|
|
2019-05-22 15:45:05 +00:00
|
|
|
/*
|
|
|
|
If you have more objects than will fit into the 64 hardware
|
|
|
|
sprites, you can omit some of the sprites each frame.
|
|
|
|
We also use oam_meta_spr_pal() to change the color of each
|
|
|
|
metasprite.
|
|
|
|
*/
|
|
|
|
|
2019-02-22 17:27:09 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
// include NESLIB header
|
|
|
|
#include "neslib.h"
|
|
|
|
|
|
|
|
// include CC65 NES Header (PPU)
|
|
|
|
#include <nes.h>
|
|
|
|
|
|
|
|
// link the pattern table into CHR ROM
|
|
|
|
//#link "chr_generic.s"
|
|
|
|
|
|
|
|
///// METASPRITES
|
|
|
|
|
2019-04-15 23:37:11 +00:00
|
|
|
#define TILE 0xd8
|
2019-08-09 15:42:36 +00:00
|
|
|
#define ATTR 0x0
|
2019-02-22 17:27:09 +00:00
|
|
|
|
2019-04-15 23:37:11 +00:00
|
|
|
// define a 2x2 metasprite
|
|
|
|
const unsigned char metasprite[]={
|
|
|
|
0, 0, TILE+0, ATTR,
|
|
|
|
0, 8, TILE+1, ATTR,
|
|
|
|
8, 0, TILE+2, ATTR,
|
|
|
|
8, 8, TILE+3, ATTR,
|
2019-02-22 17:27:09 +00:00
|
|
|
128};
|
|
|
|
|
2019-03-22 16:32:37 +00:00
|
|
|
/*{pal:"nes",layout:"nes"}*/
|
|
|
|
const char PALETTE[32] = {
|
2019-04-15 23:37:11 +00:00
|
|
|
0x03, // screen color
|
2019-02-22 17:27:09 +00:00
|
|
|
|
2019-04-15 23:37:11 +00:00
|
|
|
0x11,0x30,0x27,0x0, // background palette 0
|
|
|
|
0x1c,0x20,0x2c,0x0, // background palette 1
|
|
|
|
0x00,0x10,0x20,0x0, // background palette 2
|
|
|
|
0x06,0x16,0x26,0x0, // background palette 3
|
2019-02-22 17:27:09 +00:00
|
|
|
|
2019-04-15 23:37:11 +00:00
|
|
|
0x16,0x35,0x24,0x0, // sprite palette 0
|
|
|
|
0x00,0x37,0x25,0x0, // sprite palette 1
|
|
|
|
0x0d,0x2d,0x3a,0x0, // sprite palette 2
|
|
|
|
0x0d,0x27,0x2a // sprite palette 3
|
2019-02-22 17:27:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// setup PPU and tables
|
|
|
|
void setup_graphics() {
|
|
|
|
// clear sprites
|
|
|
|
oam_clear();
|
|
|
|
// set palette colors
|
|
|
|
pal_all(PALETTE);
|
|
|
|
// turn on PPU
|
|
|
|
ppu_on_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
// number of actors (4 h/w sprites each)
|
2019-04-04 02:23:58 +00:00
|
|
|
#define NUM_ACTORS 24
|
2019-02-22 17:27:09 +00:00
|
|
|
|
|
|
|
// actor x/y positions
|
2019-04-15 23:37:11 +00:00
|
|
|
byte actor_x[NUM_ACTORS];
|
|
|
|
byte actor_y[NUM_ACTORS];
|
|
|
|
// actor x/y deltas per frame (signed)
|
|
|
|
sbyte actor_dx[NUM_ACTORS];
|
|
|
|
sbyte actor_dy[NUM_ACTORS];
|
2019-02-22 17:27:09 +00:00
|
|
|
|
|
|
|
// main program
|
|
|
|
void main() {
|
2019-07-29 02:57:16 +00:00
|
|
|
byte i; // actor index
|
2019-02-22 17:27:09 +00:00
|
|
|
|
2019-07-29 02:57:16 +00:00
|
|
|
// setup PPU
|
2019-02-22 17:27:09 +00:00
|
|
|
setup_graphics();
|
|
|
|
// initialize actors with random values
|
|
|
|
for (i=0; i<NUM_ACTORS; i++) {
|
|
|
|
actor_x[i] = rand();
|
|
|
|
actor_y[i] = rand();
|
|
|
|
actor_dx[i] = (rand() & 7) - 3;
|
|
|
|
actor_dy[i] = (rand() & 7) - 3;
|
|
|
|
}
|
|
|
|
// loop forever
|
|
|
|
while (1) {
|
|
|
|
// start with OAMid/sprite 0
|
2019-05-11 01:25:21 +00:00
|
|
|
oam_off = 0;
|
2019-02-22 17:27:09 +00:00
|
|
|
// draw and move all actors
|
|
|
|
// (note we don't reset i each loop iteration)
|
2019-05-11 01:25:21 +00:00
|
|
|
while (oam_off < 256-4*4) {
|
|
|
|
// advance and wrap around actor array
|
|
|
|
if (++i >= NUM_ACTORS)
|
2019-02-22 17:27:09 +00:00
|
|
|
i -= NUM_ACTORS;
|
2019-05-11 01:25:21 +00:00
|
|
|
// draw and move actor
|
|
|
|
oam_meta_spr_pal(
|
|
|
|
actor_x[i] += actor_dx[i], // add x+dx and pass param
|
|
|
|
actor_y[i] += actor_dy[i], // add y+dy and pass param
|
|
|
|
i&3, // palette color
|
|
|
|
metasprite); // metasprites
|
2019-02-22 17:27:09 +00:00
|
|
|
}
|
|
|
|
// hide rest of sprites
|
2019-05-11 01:25:21 +00:00
|
|
|
oam_hide_rest(oam_off);
|
|
|
|
// wait for next NMI
|
|
|
|
// we don't want to skip frames b/c it makes flicker worse
|
|
|
|
ppu_wait_nmi();
|
2019-02-22 17:27:09 +00:00
|
|
|
}
|
|
|
|
}
|