Skip to content

Commit

Permalink
Remove "ugly hack" in playerTick(), tidy up a few things
Browse files Browse the repository at this point in the history
The hack which cancelled collisions with "non-solid" objects
is no longer needed as all objects write empty bounding
boxes (as part of their tick routines) when they are not considered solid.
  • Loading branch information
bl0ckeduser committed Dec 5, 2011
1 parent c5d0579 commit 6f966b7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
Binary file modified clown3d-DS.elf
Binary file not shown.
Binary file modified clown3d-DS.nds
Binary file not shown.
6 changes: 3 additions & 3 deletions collisions.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ void resolveCollisions(game_obj* objs, void (*handler)(void*, void*))
node->box.min.x += react.x;
node->box.max.x += react.x;

node->box.min.z += react.z;
node->box.max.z += react.z;

if(node->type==PLAYER && stair){
/* player hit a stair-mode object while
moving on X and Z axes; walk the player
Expand All @@ -266,9 +269,6 @@ void resolveCollisions(game_obj* objs, void (*handler)(void*, void*))
node->box.max.y += react.y;
}

node->box.min.z += react.z;
node->box.max.z += react.z;

if(react.x || react.y || react.z) {
(*handler)(node, node2);
(*handler)(node2, node);
Expand Down
26 changes: 5 additions & 21 deletions player.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ void playerTick(game_obj* player)

void playerCollide(game_obj* a, game_obj* b)
{
/* First check if the player hit something solid,
and adpapt its coordinates and "physics state"
/* If the player hit something solid,
update its coordinates and "physics state"
in consequence */
if(b->type == SOLID || b->type==DOOR) {

Expand All @@ -188,28 +188,12 @@ void playerCollide(game_obj* a, game_obj* b)
a->data[PLAYER_Z] = a->box.min.z + 10;

} else if(b->type == KEY && b->data[KEY_EXISTS]) {
/* pick up a key */
/* Pick up a key */
b->data[KEY_EXISTS] = 0;
a->data[PLAYER_KEYS]++;
} else {
/* UGLY HACK: cancel out collisions with
objects which are not considered "solid".
This should probably be handled in the
collision system itself */

/* rewrite original player collision box and movement vector */
player->box.min.x = (float)(player->data[PLAYER_X] - 10);
player->box.min.y = (float)(player->data[PLAYER_Y] - 10);
player->box.min.z = (float)(player->data[PLAYER_Z] - 10);
player->box.max.x = (float)(player->data[PLAYER_X] + 10);
player->box.max.y = (float)(player->data[PLAYER_Y] + 10);
player->box.max.z = (float)(player->data[PLAYER_Z] + 10);
player->box.move.x = (float)player->data[PLAYER_MOVEX];
player->box.move.y = (float)player->data[PLAYER_MOVEY];
player->box.move.z = (float)player->data[PLAYER_MOVEZ];
}
}

/* If the player hits the door and has a key,
/* If the player hits a door and has a key,
open the door and get rid of the key */
if(b->type == DOOR && b->data[DOOR_CLOSED])
{
Expand Down

0 comments on commit 6f966b7

Please sign in to comment.