Improved collisions
Collide function should be ~2 times faster now, vertical collision now reset jump_hold.
This commit is contained in:
parent
7eef00a0e0
commit
6981f70a8f
BIN
platform.g3a
BIN
platform.g3a
Binary file not shown.
|
@ -6,11 +6,11 @@ char collide(int x, int y, char level[], char tile)
|
|||
if ((level[(int)(x/8) + (int)(y/8) * LEVEL_WIDTH] == tile) ||
|
||||
(level[(int)(x/8) + (int)((y+PLAYER_SIDES)/8) * LEVEL_WIDTH] == tile) ||
|
||||
(level[(int)((x+PLAYER_SIDES)/8) + (int)((y+PLAYER_SIDES)/8) * LEVEL_WIDTH] == tile) ||
|
||||
(level[(int)((x+PLAYER_SIDES)/8) + (int)(y/8) * LEVEL_WIDTH] == tile) ||
|
||||
(level[(int)((x+PLAYER_SIDES)/8) + (int)(y/8) * LEVEL_WIDTH] == tile) /*||
|
||||
(level[(int)(x/8) + (int)((y+PLAYER_SIDES/2)/8) * LEVEL_WIDTH] == tile) ||
|
||||
(level[(int)((x+PLAYER_SIDES/2)/8) + (int)(y/8) * LEVEL_WIDTH] == tile) ||
|
||||
(level[(int)((x+PLAYER_SIDES/2)/8) + (int)((y+PLAYER_SIDES)/8) * LEVEL_WIDTH] == tile) ||
|
||||
(level[(int)((x+PLAYER_SIDES)/8) + (int)((y+PLAYER_SIDES/2)/8) * LEVEL_WIDTH] == tile)) return 1;
|
||||
(level[(int)((x+PLAYER_SIDES)/8) + (int)((y+PLAYER_SIDES/2)/8) * LEVEL_WIDTH] == tile)*/) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ int main(void)
|
|||
}
|
||||
//vertical movement
|
||||
if (UG_CAN_JUMP) jump_test(&jump_pressed, &jump_buffer, &jump_hold);
|
||||
//if jump is pressed and on ground
|
||||
//jump
|
||||
if (jump_buffer && on_ground) {
|
||||
vspd = JUMP_SPD;
|
||||
on_ground = 0;
|
||||
|
@ -121,14 +121,15 @@ int main(void)
|
|||
{
|
||||
player_y += trunc_vspd;
|
||||
}
|
||||
else
|
||||
{
|
||||
else
|
||||
{
|
||||
int sign_vspd = sgn(trunc_vspd);
|
||||
while (!collide_solid(player_x, player_y + sign_vspd, level))
|
||||
{
|
||||
player_y += sign_vspd;
|
||||
}
|
||||
vspd = 0;
|
||||
jump_hold = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue