01-22-2023, 10:04 PM
Thinking on the concept of a CollisionArray a little more, I think I'd do my data structure a wee bit different.
TYPE CA_Type
AS INTEGER y, x1, x2
AS _UNSIGNED LONG kolor
END TYPE
Now, why would I define my data in such an odd way? Let's say we have some image like the below:
...................
.
.
.
...................
(And pretend our text is actually pictures creating a C shaped square with the right side opened.)
Now, all our colors are black, so I can store by CA(value).kolor as Black.
And the first line, I can store as : CA(value).Y = 1: CA(value).X1 = 0: CA(value).X2 = 20
Then when it comes time to check for collisions, I know to check: (X1,Y) to (X2,Y) for black
HOW I check that range of X values for that color, is up to me to decide, based upon how complex I want my code and how important speed is for the routine. Am I doing something simple which can render 600FPS, while I have a limit 30 in play? PFFFTT! In that case, I can code whatever the heck I want. A FOR...NEXT loop and check each value POINT by point would be fine. Do I need something speedier though, as I've got 80 enemy ships shooting a dozen bullets across the screen to track as well?? I might want to read in that whole strip of video information into a string with _MEM, and then just do a quick INSTR check for the string equivalent of a 4-byte Black pixel. If I've got an enemy bullet that I know is going to be at point (x,y), then I can just check my array for y matches first, and then see if the bulletX is >= array.X1 and <= array.X2....
Instead of storing every pixel individually, it'd be a case of storing which row they're on (Y value) and then their start and stop points (X1 and X2). (And color may not even matter, if you draw you draw your hero/ship/character onto the screen last. Just check to see if any pixel from X1, Y to x2, Y is non-transparent (or non-background, whatever the background color is).
Seems a slightly better data structure, to me, than using a type which just holds one pixel and its color.
TYPE CA_Type
AS INTEGER y, x1, x2
AS _UNSIGNED LONG kolor
END TYPE
Now, why would I define my data in such an odd way? Let's say we have some image like the below:
...................
.
.
.
...................
(And pretend our text is actually pictures creating a C shaped square with the right side opened.)
Now, all our colors are black, so I can store by CA(value).kolor as Black.
And the first line, I can store as : CA(value).Y = 1: CA(value).X1 = 0: CA(value).X2 = 20
Then when it comes time to check for collisions, I know to check: (X1,Y) to (X2,Y) for black
HOW I check that range of X values for that color, is up to me to decide, based upon how complex I want my code and how important speed is for the routine. Am I doing something simple which can render 600FPS, while I have a limit 30 in play? PFFFTT! In that case, I can code whatever the heck I want. A FOR...NEXT loop and check each value POINT by point would be fine. Do I need something speedier though, as I've got 80 enemy ships shooting a dozen bullets across the screen to track as well?? I might want to read in that whole strip of video information into a string with _MEM, and then just do a quick INSTR check for the string equivalent of a 4-byte Black pixel. If I've got an enemy bullet that I know is going to be at point (x,y), then I can just check my array for y matches first, and then see if the bulletX is >= array.X1 and <= array.X2....
Instead of storing every pixel individually, it'd be a case of storing which row they're on (Y value) and then their start and stop points (X1 and X2). (And color may not even matter, if you draw you draw your hero/ship/character onto the screen last. Just check to see if any pixel from X1, Y to x2, Y is non-transparent (or non-background, whatever the background color is).
Seems a slightly better data structure, to me, than using a type which just holds one pixel and its color.