After a bit of headache, I've gotten objects to spawn and be deactivated pretty nicely. Right now I have it so that there can be 8 objects that are active at a time, not counting the player, or things that are made by other objects (For instance, projectiles.) For now I've just kept things simple and stuck with my linear search, and when all 8 objects are active, their code running, and the camera's moving, around 20% of frame time is used; and at most times, I feel like there'll be less objects than that. It's usually only around 10% frame use.
So I think the next thing I want to try is background collision with scrolling.
I already asked about this in another thread, but from what others have said it seems to be more involved when there's scrolling. After thinking about it for a bit, though, isn't the only difference really that you're working with 16-bit values instead of 8-bit?
I think I want to try and have collision data work like attribute data, where there can be four different types of collisions (Nothing, solid, death, something else) and 4 16x16 pixel blocks can be packed into one byte. So for each room there could be a pointer table for the collision data for each screen. The high byte of each object's position, as it corresponds to the screen number, could be multiplied by 2 to get the right pointer, and then the low byte is treated as the X position in the table, and from there on it's just like normal background collision detection, right?
Something like:
Code: Select all
RoomCollisionData:
.dw Room0CollisionData, Room1CollisionData, ...
Room0CollisionData:
.dw Room0Screen0CollisionData, Room0Screen1CollisionData, ...
Room0Screen0CollisionData:
.db %01010101,%01010101,%01010101,%01010101 ;first 16 blocks - solid
.db %01000000,%00000000,%00000000,%00000001 ;first and last block solid, blocks 1-14 non-solid
.db %01000101,%01010101,%01010101,%01010001
.db %01000101,%01010101,%01010101,%01010001
.db %01000101,%01010101,%01010101,%01010001
.db %01000101,%01010101,%01010101,%01010001
.db %01000101,%01010101,%01010101,%01010001
.db %01000101,%01010101,%01010101,%01010001
.db %01000101,%01010101,%01010101,%01010001
.db %01000101,%01010101,%01010101,%01010001
.db %01000101,%01010101,%01010101,%01010001
.db %01000101,%01010101,%01010101,%01010001
.db %01000101,%01010101,%01010101,%01010001
.db %01000000,%00000000,%00000000,%00000001
.db %01010101,%01010101,%01010101,%01010101
And then I think something like this would get the correct type of collision (0-3) of wherever the object is:
Code: Select all
int[] AND_Table = {0xC0, 0x30, 0x0C, 0x03};
bgcol_y = obj_y / 4;
bgcol_x = obj_xlo / 64;
bgcol_x_block = (obj_xlo / 16) & 0x03;
bgcol_index = bgcol_y + bgcol_x;
bgcol = Room0Screen0CollisionData[bgcol_index] & AND_Table[bgcol_x_block];
if (bgcol_x_block > 0) {
for (int i = 0; i <= bgcol_x_block - 1; i++)
bgcol /= 4;
}
Sorry, I'm kinda dumping ideas. Time to close my eyes.