Add collision.h and start using its enum

This commit is contained in:
Elliptic Ellipsis 2022-03-24 22:18:39 +00:00
parent 5a9bf6dd82
commit 6eea9aace2
4 changed files with 50 additions and 43 deletions

35
include/collision.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef COLLISION_H
#define COLLISION_H
#include "global.h"
#include "entity.h"
/** Collisions. */
typedef enum {
COL_NONE = 0x0,
COL_NORTH_WEST = 0x2,
COL_NORTH_EAST = 0x4,
COL_NORTH_FULL = 0x6,
COL_NORTH_ANY = 0xe,
COL_SOUTH_WEST = 0x20,
COL_SOUTH_EAST = 0x40,
COL_SOUTH_FULL = 0x60,
COL_SOUTH_ANY = 0xe0,
COL_WEST_SOUTH = 0x200,
COL_WEST_NORTH = 0x400,
COL_WEST_FULL = 0x600,
COL_WEST_ANY = 0xe00,
COL_EAST_SOUTH = 0x2000,
COL_EAST_NORTH = 0x4000,
COL_EAST_FULL = 0x6000,
COL_EAST_ANY = 0xe000,
} Collisions;
bool32 IsTileCollision(const u8*, s32, s32, u32);
void CalculateEntityTileCollisions(Entity*, u32, u32);
bool32 ProcessMovementInternal(Entity*, s32, s32, u32);
#endif

View File

@ -5,6 +5,7 @@
* @brief Flying pot enemy
*/
#define NENT_DEPRECATED
#include "collision.h"
#include "functions.h"
#include "enemy.h"
#include "player.h"
@ -234,7 +235,7 @@ void FlyingPot_Action4(FlyingPotEntity* this) {
void FlyingPot_Action5(FlyingPotEntity* this) {
ProcessMovement2(super);
if (super->collisions != 0) {
if (super->collisions != COL_NONE) {
sub_08037408(this);
}
}

View File

@ -1,4 +1,5 @@
#include "global.h"
#include "collision.h"
#include "entity.h"
#include "room.h"
#include "area.h"
@ -9,30 +10,6 @@
#include "transitions.h"
#include "functions.h"
/** Collisions. */
typedef enum {
COL_NONE = 0x0,
COL_NORTH_WEST = 0x2,
COL_NORTH_EAST = 0x4,
COL_NORTH_FULL = 0x6,
COL_NORTH_ANY = 0xe,
COL_SOUTH_WEST = 0x20,
COL_SOUTH_EAST = 0x40,
COL_SOUTH_FULL = 0x60,
COL_SOUTH_ANY = 0xe0,
COL_WEST_SOUTH = 0x200,
COL_WEST_NORTH = 0x400,
COL_WEST_FULL = 0x600,
COL_WEST_ANY = 0xe00,
COL_EAST_SOUTH = 0x2000,
COL_EAST_NORTH = 0x4000,
COL_EAST_FULL = 0x6000,
COL_EAST_ANY = 0xe000,
} Collisions;
bool32 IsTileCollision(const u8*, s32, s32, u32);
void CalculateEntityTileCollisions(Entity*, u32, u32);
bool32 ProcessMovementInternal(Entity*, s32, s32, u32);
bool32 sub_080AF0C8(Entity*);
/** The type of the movement/collision? that is done. */

View File

@ -1,4 +1,5 @@
#define NENT_DEPRECATED
#include "collision.h"
#include "entity.h"
#include "asm.h"
#include "functions.h"
@ -6,15 +7,8 @@
#include "projectile.h"
#include "projectile/winder.h"
// #define WINDER_NUM_SEGMENTS 8
extern s16 gUnk_080B4488[];
// typedef struct {
// Entity base;
// u16 positions[2 * WINDER_NUM_SEGMENTS];
// } WinderEntity;
typedef enum {
/* 0 */ WINDER_TYPE_HEAD,
/* 4 */ WINDER_TYPE_4 = 4,
@ -24,7 +18,7 @@ void Winder_Init(WinderEntity* this);
void sub_080AB950(WinderEntity* this);
void Winder_SetPositions(WinderEntity*);
bool32 sub_080AB9FC(WinderEntity* this, u32 dir);
bool32 Winder_CheckNextTileCollision(WinderEntity* this, u32 dir);
void Winder(Entity* thisx) {
static void (*const Winder_Actions[])(WinderEntity*) = {
@ -72,7 +66,7 @@ void sub_080AB950(WinderEntity* this) {
{ DirectionEast, DirectionWest },
{ DirectionNorth, DirectionSouth },
};
static const u16 gUnk_0812A6C4[] = { 0x000E, 0xE000, 0x00E0, 0x0E00 };
static const u16 collisionChecks[] = { COL_NORTH_ANY, COL_EAST_ANY, COL_SOUTH_ANY, COL_WEST_ANY };
if (super->type == 0) {
u8 dir;
@ -80,7 +74,7 @@ void sub_080AB950(WinderEntity* this) {
ProcessMovement0(super);
dir = super->direction >> 3;
if ((gUnk_0812A6C4[dir] & super->collisions) || sub_080AB9FC(this, super->direction)) {
if ((collisionChecks[dir] & super->collisions) || Winder_CheckNextTileCollision(this, super->direction)) {
super->direction = nextDirections[dir][Random() & 0x1];
}
} else {
@ -117,21 +111,21 @@ void Winder_SetPositions(WinderEntity* this) {
this->positions[2 * (WINDER_NUM_SEGMENTS - 1) + 1] = super->y.HALF.HI;
}
bool32 sub_080AB9FC(WinderEntity* this, u32 dir) {
bool32 Winder_CheckNextTileCollision(WinderEntity* this, u32 dir) {
u32 tile;
u32 val;
LayerStruct* layer = GetLayerByIndex(super->collisionLayer);
u32 tmp;
u32 collisionData;
val = (((super->x.HALF.HI - gRoomControls.origin_x) >> 4) & 0x3F) |
((((super->y.HALF.HI - gRoomControls.origin_y) >> 4) & 0x3F) << 6);
val += gUnk_080B4488[dir >> 3];
tmp = layer->collisionData[val];
tile = TILE(super->x.HALF.HI, super->y.HALF.HI);
tile += gUnk_080B4488[dir >> 3];
collisionData = layer->collisionData[tile];
if (tmp <= 0x1F) {
if (collisionData <= 0x1F) {
return FALSE;
}
if (tmp > 0x3F) {
if (collisionData > 0x3F) {
return FALSE;
}