2022-07-19 19:53:26 +00:00
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
//#link "common.c"
|
|
|
|
|
|
|
|
#include "sprites.h"
|
|
|
|
//#link "sprites.c"
|
|
|
|
|
|
|
|
/*{w:12,h:21,bpp:2,brev:1}*/
|
|
|
|
const char SPRITEMC[3*21] = {
|
|
|
|
0x00,0xAA,0x80,0x02,0xAA,0xA0,0x0A,0xAA,0xA8,
|
|
|
|
0x0A,0xAE,0xA8,0x0A,0xBB,0xA8,0x0A,0xBA,0xA8,
|
|
|
|
0x0A,0xBB,0xA8,0x0A,0xAE,0xA8,0x0A,0xAA,0xA8,
|
|
|
|
0x09,0xAA,0x98,0x08,0x6A,0x48,0x08,0x1D,0x08,
|
|
|
|
0x02,0x0C,0x20,0x02,0x0C,0x20,0x02,0x0C,0x20,
|
|
|
|
0x00,0x8C,0x80,0x00,0x8C,0x80,0x00,0x55,0x40,
|
|
|
|
0x00,0x77,0x40,0x00,0x5D,0x40,0x00,0x15,0x00
|
|
|
|
};
|
|
|
|
|
2022-08-11 20:27:20 +00:00
|
|
|
#define SPRITE_SHAPE 192
|
|
|
|
|
|
|
|
// X/Y position arrays
|
|
|
|
int xpos[8]; // fixed point 9.7
|
|
|
|
int ypos[8]; // fixed point 8.8
|
|
|
|
// X/Y velocity arrays
|
2022-07-19 19:53:26 +00:00
|
|
|
int xvel[8];
|
|
|
|
int yvel[8];
|
|
|
|
|
|
|
|
void init_sprites(void) {
|
|
|
|
byte i;
|
|
|
|
// setup sprite positions
|
|
|
|
for (i=0; i<8; i++) {
|
2022-08-11 20:27:20 +00:00
|
|
|
xpos[i] = ((i & 3) * 0x2000) - 0x3000;
|
2022-07-19 19:53:26 +00:00
|
|
|
ypos[i] = (i * 0x1000) - 0x3000;
|
|
|
|
sprshad.spr_color[i] = i | 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void move_sprites(void) {
|
|
|
|
byte i;
|
|
|
|
for (i=0; i<8; i++) {
|
|
|
|
//VIC.bordercolor = i;
|
2022-08-11 20:27:20 +00:00
|
|
|
sprite_draw(i,
|
|
|
|
(xpos[i] >> 7) + 172,
|
|
|
|
(ypos[i] >> 8) + 145,
|
|
|
|
SPRITE_SHAPE);
|
2022-07-19 19:53:26 +00:00
|
|
|
// update position
|
|
|
|
xpos[i] += xvel[i];
|
|
|
|
ypos[i] += yvel[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_sprites(void) {
|
|
|
|
byte i;
|
|
|
|
for (i=0; i<8; i++) {
|
|
|
|
// update velocity
|
|
|
|
xvel[i] -= xpos[i] >> 12;
|
|
|
|
yvel[i] -= ypos[i] >> 12;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void collide_sprites(byte spr_coll) {
|
|
|
|
byte i;
|
|
|
|
byte mask = 1;
|
|
|
|
// exit if no collisions
|
|
|
|
if (!spr_coll) return;
|
|
|
|
// iterate all sprites that have their flag set
|
|
|
|
for (i=0; i<8; i++, mask<<=1) {
|
|
|
|
//VIC.bordercolor = i;
|
|
|
|
if (spr_coll & mask) {
|
|
|
|
// find the first sprite that intersects
|
|
|
|
byte j = sprite_get_closest_collision(i, spr_coll);
|
|
|
|
// returns 0..7 if a sprite was found
|
|
|
|
if (j < 8) {
|
|
|
|
xvel[i] = (xpos[i] - xpos[j]) >> 4;
|
|
|
|
yvel[i] = (ypos[i] - ypos[j]) >> 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-11 20:27:20 +00:00
|
|
|
void iterate_game(void) {
|
2022-07-19 19:53:26 +00:00
|
|
|
byte spr_coll;
|
2022-08-11 20:27:20 +00:00
|
|
|
|
2022-07-19 19:53:26 +00:00
|
|
|
// wait for vblank
|
2022-08-11 20:27:20 +00:00
|
|
|
waitvsync();
|
2022-07-19 19:53:26 +00:00
|
|
|
// grab and reset sprite-sprite collision flags
|
|
|
|
spr_coll = VIC.spr_coll;
|
|
|
|
// then update sprite registers from shadow RAM
|
|
|
|
sprite_update(DEFAULT_SCREEN);
|
|
|
|
// draw sprites into shadow ram
|
|
|
|
move_sprites();
|
|
|
|
// and update velocity and position
|
|
|
|
update_sprites();
|
|
|
|
// if any flags are set in the collision register,
|
|
|
|
// process sprite collisions
|
|
|
|
collide_sprites(spr_coll);
|
|
|
|
}
|
|
|
|
|
|
|
|
void main(void) {
|
|
|
|
|
|
|
|
clrscr();
|
|
|
|
VIC.bordercolor = 0;
|
|
|
|
|
|
|
|
// setup sprite library and copy sprite to VIC bank
|
|
|
|
sprite_clear();
|
2022-08-11 20:27:20 +00:00
|
|
|
sprite_set_shapes(SPRITEMC, SPRITE_SHAPE, 1);
|
2022-07-19 19:53:26 +00:00
|
|
|
|
|
|
|
// set colors
|
|
|
|
sprshad.spr_mcolor = 0xff;
|
2022-07-20 19:32:47 +00:00
|
|
|
VIC.spr_mcolor0 = 4;
|
|
|
|
VIC.spr_mcolor1 = 7;
|
2022-07-19 19:53:26 +00:00
|
|
|
|
|
|
|
// set sprite initial positions
|
|
|
|
init_sprites();
|
|
|
|
|
|
|
|
// game loop
|
|
|
|
while (1) {
|
2022-08-11 20:27:20 +00:00
|
|
|
iterate_game();
|
2022-07-19 19:53:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|