Very basic and in-progress collision detection

This commit is contained in:
Lucas S. Vieira 2024-08-03 04:04:25 -03:00
parent 77ba77b97e
commit f2590cf202
6 changed files with 165 additions and 89 deletions

Binary file not shown.

File diff suppressed because one or more lines are too long

View file

@ -7,15 +7,15 @@
<layer id="1" name="LAYER0" width="255" height="31">
<data encoding="csv">
12,0,0,0,7,12,12,12,12,12,9,9,12,12,12,12,12,12,12,12,12,8,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
12,0,0,0,0,0,7,12,8,0,0,0,12,12,9,9,9,9,9,12,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

View file

@ -492,25 +492,62 @@ linecast(LevelData *lvl, TileMap128 *map128, TileMap16 *map16,
// x or y pushbacks.
// But, if our height on heightmask has a 0 height, then we proceed.
uint8_t mask_byte = 0;
int16_t h;
if(mask0) {
mask_byte = mask0[index >> 1];
mask_byte = mask_byte >> (((index & 0x1) ^ 0x1) << 2);
mask_byte = mask_byte & 0xf;
}
if(mask_byte > 0) {
h = (direction == 0) ? vx : vy;
h = ((magnitude < 0) ? 0 : 16) - (h & 0x0f);
}
}
// Piece 1 is verified if and only if last piece had no collision or
// if there was no collision on that spot.
if((mask_byte == 0) && mask1) {
mask_byte = mask1[index >> 1];
mask_byte = mask_byte >> (((index & 0x1) ^ 0x1) << 2);
mask_byte = mask_byte & 0xf;
if(mask_byte > 0) {
h = (direction == 0) ? vx : vy;
h = ((magnitude < 0) ? 0 : 16) - ((h + abs(magnitude)) & 0xf);
}
}
// Now mask_byte holds a number [0-15] telling the height on that tile.
// Regardless, we need to calculate the proper X or Y value and leverage the
// value of mask_byte to ensure we have our proper pushback value.
CollisionEvent ev = { 0 };
ev.collided = (mask_byte > 0);
// It is not enough for us just to have a mask with a cute height value.
// We need to know if, within our piece, the casted line reaches that
// height.
// We can deduce that by taking the mod of the magnitude on the direction
// of the casted line.
// Let's take a ground (top to bottom) collision for instance; here, our
// magnitude is positive.
// Take the Y position of the end by adding the magnitude to VY. Then take
// the integer remainder (VY + Magnitude) % 16. This is how deep we are at
// the LAST detected piece, with respect to its top.
// We need to be careful here with this depth. If we have two pieces and
// Now, there are two ways to calculate depth, depending on what piece
// we found the collision at. On both these ways, we will calculate the
// pushback with respect to the (VX, VY) point.
// If we found a collision at piece 0, take h = (16 - (VY % 16)) to know
// the start height inside our piece. If h > height, we have no
// collision; otherwise, we do have a collision, and the pushback from
// the tip of our line should be (height - h).
// If we found a collision at piece 1, take h = (16 - ((VY + Magnitude) % 16)).
// Perform the exact same check as above, except the retrieved height should
// be from piece 1.
ev.collided = (mask_byte > 0) && (h <= mask_byte);
// The pushback is, with respect to the linecast's start X or Y position
// (deducible by the direction), the amount that should be added or
@ -519,13 +556,14 @@ linecast(LevelData *lvl, TileMap128 *map128, TileMap16 *map16,
if(ev.collided) {
ev.direction = direction;
if(ev.direction == 0) { // horizontal
// TODO
ev.pushback = mask_byte;
} else { // vertical
// TODO
ev.pushback = mask_byte;
}
ev.pushback = (int16_t)mask_byte - h - (magnitude < 0 ? 16 : 0);
/* if(ev.direction == 0) { // horizontal */
/* // TODO */
/* ev.pushback = (int16_t)mask_byte - h - (magnitude < 0 ? 16 : 0); */
/* } else { // vertical */
/* // TODO */
/* ev.pushback = (int16_t)mask_byte - h - (magnitude < 0 ? 16 : 0); */
/* } */
}
return ev;

View file

@ -22,6 +22,8 @@ volatile int timer_counter = 0;
volatile int frame_counter = 0;
volatile int frame_rate = 0;
static int debug_mode = 0;
/* #define SPRTSZ 56 */
/* static int x = (SPRTSZ >> 1), y = (SPRTSZ >> 1); */
@ -169,6 +171,10 @@ engine_update()
sound_xa_set_channel(music_channel);
}
if(pad_pressed(PAD_SELECT)) {
debug_mode = !debug_mode;
}
/* #define SPD (8 * ONE) */
/* if(pad_pressing(PAD_RIGHT)) { */
@ -197,8 +203,8 @@ engine_update()
anchory = (player.pos.vy >> 12) + 4;
uint16_t grn_ceil_dist = 8;
uint16_t grn_mag = 12;
uint16_t ceil_mag = 12;
uint16_t grn_mag = 14;
uint16_t ceil_mag = 14;
uint16_t left_mag = 12;
uint16_t right_mag = 12;
@ -228,75 +234,105 @@ engine_update()
uint16_t
ax = anchorx - (cam_pos.vx >> 12) + CENTERX,
ay = anchory - (cam_pos.vy >> 12) + CENTERY;
LINE_F2 line;
setLineF2(&line);
// Ground sensor left
setRGB0(&line, 0, 93, 0);
setXY2(&line, ax - grn_ceil_dist, ay + 8, ax - grn_ceil_dist, ay + 8 + grn_mag);
DrawPrim((void *)&line);
// (dot)
if(ev_grnd1.collided) setRGB0(&line, 255, 0, 0);
else setRGB0(&line, 255, 255, 255);
setXY2(&line, ax - grn_ceil_dist, ay + 8 + grn_mag, ax - grn_ceil_dist, ay + 8 + grn_mag);
DrawPrim((void *)&line);
// Ground sensor right
setRGB0(&line, 23, 99, 63);
setXY2(&line, ax + grn_ceil_dist, ay + 8, ax + grn_ceil_dist, ay + 8 + grn_mag);
DrawPrim((void *)&line);
// (dot)
if(ev_grnd2.collided) setRGB0(&line, 255, 0, 0);
else setRGB0(&line, 255, 255, 255);
setXY2(&line, ax + grn_ceil_dist, ay + 8 + grn_mag, ax + grn_ceil_dist, ay + 8 + grn_mag);
DrawPrim((void *)&line);
// Ceiling sensor left
setRGB0(&line, 0, 68, 93);
setXY2(&line, ax - grn_ceil_dist, ay - 8, ax - grn_ceil_dist, ay - 8 - ceil_mag);
DrawPrim((void *)&line);
// (dot)
if(ev_ceil1.collided) setRGB0(&line, 255, 0, 0);
else setRGB0(&line, 255, 255, 255);
setXY2(&line, ax - grn_ceil_dist, ay - 8 - ceil_mag, ax - grn_ceil_dist, ay - 8 - ceil_mag);
DrawPrim((void *)&line);
// Ceiling sensor right
setRGB0(&line, 99, 94, 23);
setXY2(&line, ax + grn_ceil_dist, ay - 8, ax + grn_ceil_dist, ay - 8 - ceil_mag);
DrawPrim((void *)&line);
// (dot)
if(ev_ceil2.collided) setRGB0(&line, 255, 0, 0);
else setRGB0(&line, 255, 255, 255);
setXY2(&line, ax + grn_ceil_dist, ay - 8 - ceil_mag, ax + grn_ceil_dist, ay - 8 - ceil_mag);
DrawPrim((void *)&line);
// Left sensor
setRGB0(&line, 99, 23, 99);
setXY2(&line, ax, ay, ax - left_mag, ay);
DrawPrim((void *)&line);
// (dot)
if(ev_left.collided) setRGB0(&line, 255, 0, 0);
else setRGB0(&line, 255, 255, 255);
setXY2(&line, ax - left_mag, ay, ax - left_mag, ay);
DrawPrim((void *)&line);
// Right sensor
setRGB0(&line, 99, 23, 99);
setXY2(&line, ax, ay, ax + right_mag, ay);
DrawPrim((void *)&line);
// (dot)
if(ev_right.collided) setRGB0(&line, 255, 0, 0);
else setRGB0(&line, 255, 255, 255);
setXY2(&line, ax + right_mag, ay, ax + right_mag, ay);
DrawPrim((void *)&line);
if(debug_mode) {
LINE_F2 line;
setLineF2(&line);
// Player center (dot)
setRGB0(&line, 255, 255, 255);
setXY2(&line, ax, ay, ax, ay);
DrawPrim((void *)&line);
// Ground sensor left
setRGB0(&line, 0, 93, 0);
setXY2(&line, ax - grn_ceil_dist, ay + 8, ax - grn_ceil_dist, ay + 8 + grn_mag);
DrawPrim((void *)&line);
// (dot)
if(ev_grnd1.collided) setRGB0(&line, 255, 0, 0);
else setRGB0(&line, 255, 255, 255);
setXY2(&line, ax - grn_ceil_dist, ay + 8 + grn_mag, ax - grn_ceil_dist, ay + 8 + grn_mag);
DrawPrim((void *)&line);
// Ground sensor right
setRGB0(&line, 23, 99, 63);
setXY2(&line, ax + grn_ceil_dist, ay + 8, ax + grn_ceil_dist, ay + 8 + grn_mag);
DrawPrim((void *)&line);
// (dot)
if(ev_grnd2.collided) setRGB0(&line, 255, 0, 0);
else setRGB0(&line, 255, 255, 255);
setXY2(&line, ax + grn_ceil_dist, ay + 8 + grn_mag, ax + grn_ceil_dist, ay + 8 + grn_mag);
DrawPrim((void *)&line);
// Ceiling sensor left
setRGB0(&line, 0, 68, 93);
setXY2(&line, ax - grn_ceil_dist, ay - 8, ax - grn_ceil_dist, ay - 8 - ceil_mag);
DrawPrim((void *)&line);
// (dot)
if(ev_ceil1.collided) setRGB0(&line, 255, 0, 0);
else setRGB0(&line, 255, 255, 255);
setXY2(&line, ax - grn_ceil_dist, ay - 8 - ceil_mag, ax - grn_ceil_dist, ay - 8 - ceil_mag);
DrawPrim((void *)&line);
// Ceiling sensor right
setRGB0(&line, 99, 94, 23);
setXY2(&line, ax + grn_ceil_dist, ay - 8, ax + grn_ceil_dist, ay - 8 - ceil_mag);
DrawPrim((void *)&line);
// (dot)
if(ev_ceil2.collided) setRGB0(&line, 255, 0, 0);
else setRGB0(&line, 255, 255, 255);
setXY2(&line, ax + grn_ceil_dist, ay - 8 - ceil_mag, ax + grn_ceil_dist, ay - 8 - ceil_mag);
DrawPrim((void *)&line);
// Left sensor
setRGB0(&line, 99, 23, 99);
setXY2(&line, ax, ay, ax - left_mag, ay);
DrawPrim((void *)&line);
// (dot)
if(ev_left.collided) setRGB0(&line, 255, 0, 0);
else setRGB0(&line, 255, 255, 255);
setXY2(&line, ax - left_mag, ay, ax - left_mag, ay);
DrawPrim((void *)&line);
// Right sensor
setRGB0(&line, 99, 23, 99);
setXY2(&line, ax, ay, ax + right_mag, ay);
DrawPrim((void *)&line);
// (dot)
if(ev_right.collided) setRGB0(&line, 255, 0, 0);
else setRGB0(&line, 255, 255, 255);
setXY2(&line, ax + right_mag, ay, ax + right_mag, ay);
DrawPrim((void *)&line);
// Player center (dot)
setRGB0(&line, 255, 255, 255);
setXY2(&line, ax, ay, ax, ay);
DrawPrim((void *)&line);
}
/* Player collision detection */
if(ev_right.collided && player.vel.vx > 0) {
player.vel.vx = 0;
player.pos.vx = ((player.pos.vx >> 12) - (int32_t)(ev_right.pushback)) << 12;
}
if(ev_left.collided && player.vel.vx < 0) {
player.vel.vx = 0;
player.pos.vx = ((player.pos.vx >> 12) + (int32_t)(ev_left.pushback) - 4) << 12;
}
if(!player.grnd) {
if((ev_grnd1.collided || ev_grnd2.collided) && (player.vel.vy > 0)) {
player.vel.vy = 0;
int32_t pushback =
(ev_grnd1.pushback > ev_grnd2.pushback)
? ev_grnd1.pushback
: ev_grnd2.pushback;
player.pos.vy = ((player.pos.vy >> 12) - pushback) << 12;
player.grnd = 1;
player.jmp = 0;
}
} else {
if(!ev_grnd1.collided && !ev_grnd2.collided) {
player.grnd = 0;
}
}
player_update(&player);
}

View file

@ -10,7 +10,7 @@
#define TMP_ANIM_SPD 7
#define ANIM_IDLE_TIMER_MAX 180
#define DUMMY_GROUND ((432 - 64 - 8) << 12)
//#define DUMMY_GROUND ((432 - 64 - 8) << 12)
// Adler32 sums of animation names for ease of use
#define ANIM_STOPPED 0x08cd0220
@ -24,6 +24,8 @@
#define ANIM_CROUCHDOWN 0x104802fd
#define ANIM_LOOKUP 0x067001db
extern int debug_mode;
SoundEffect sfx_jump = { 0 };
void
@ -141,12 +143,12 @@ player_update(Player *player)
if(!player->grnd) {
player->vel.vy += Y_GRAVITY;
if(player->pos.vy >= DUMMY_GROUND) {
player->vel.vy = 0;
player->pos.vy = DUMMY_GROUND;
player->grnd = 1;
player->jmp = 0;
}
/* if(player->pos.vy >= DUMMY_GROUND) { */
/* player->vel.vy = 0; */
/* player->pos.vy = DUMMY_GROUND; */
/* player->grnd = 1; */
/* player->jmp = 0; */
/* } */
if(player->jmp
&& !pad_pressing(PAD_CROSS)