Skip to content

Commit

Permalink
#definema
Browse files Browse the repository at this point in the history
  • Loading branch information
s4Ys369 committed Jun 27, 2024
1 parent 403fa62 commit 86d127d
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 71 deletions.
10 changes: 5 additions & 5 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
#include <t3d/t3d.h>

// SEED is used to place objects at random
#define SEED 6969
#define SEED 69
#define NUM_PLAYERS 1
#define NUM_HILLS 5
#define NUM_LILYPADS 5
#define NUM_SPRINGS 5
#define NUM_FLYS 20
#define NUM_HILLS 0
#define NUM_LILYPADS 0
#define NUM_SPRINGS 1
#define NUM_FLYS 0
#define FLY_DRAW_DIST 150

#endif // CONFIG_H
2 changes: 2 additions & 0 deletions include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef struct {
float length;
} TongueParams;

#if NUM_FLYS > 0
typedef struct {
T3DVec3 pos;
T3DVec3 dir;
Expand All @@ -61,6 +62,7 @@ typedef struct {
bool isActive;
int pointValue;
} FlyParams;
#endif

typedef struct {
T3DVec3 moveDir;
Expand Down
100 changes: 74 additions & 26 deletions src/actors.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,28 @@
#include "player.h"
#include "utils.h"


#if NUM_HILLS > 0
T3DMat4FP* hillMatFP[NUM_HILLS];
T3DVec3 hillPos[NUM_HILLS];
AABB hillBox[NUM_HILLS];
rspq_block_t *dplHill[NUM_HILLS];
T3DModel *modelHill;
#endif

#if NUM_LILYPADS > 0
T3DMat4FP* lilypadMatFP[NUM_LILYPADS];
T3DMat4FP* boxMatFP[NUM_LILYPADS];
T3DVec3 lilypadPos[NUM_LILYPADS];
AABB lilypadBox[NUM_LILYPADS];
rspq_block_t *dplLilypad[NUM_LILYPADS];
rspq_block_t *dplDebugBox[NUM_LILYPADS];
T3DModel *modelLilyPad;
#endif

#if NUM_SPRINGS > 0
T3DMat4FP* springMatFP[NUM_SPRINGS];
T3DMat4FP* boxMatFP[NUM_SPRINGS];
T3DVec3 springPos[NUM_SPRINGS];
AABB springBox[NUM_SPRINGS];
rspq_block_t *dplSpring[NUM_SPRINGS];
Expand All @@ -40,7 +47,9 @@ T3DSkeleton springSkelBlends[NUM_SPRINGS];
T3DAnim animsSpring[NUM_SPRINGS];
bool springActive[NUM_SPRINGS];
float springForce;
#endif

#if NUM_FLYS > 0
T3DMat4FP* flyMatFP[NUM_FLYS];
T3DMat4FP* sphereFlyMatFP[NUM_FLYS];
T3DVec3 flyPos[NUM_FLYS];
Expand All @@ -60,6 +69,7 @@ T3DSkeleton flySkelBlends[NUM_FLYS];
T3DAnim animsFlying[NUM_FLYS];
T3DAnim animsDeath[NUM_FLYS];
int flyHide[NUM_FLYS];
#endif

float xValues[] = {
150.0f,
Expand Down Expand Up @@ -104,16 +114,33 @@ void check_actor_collisions(T3DVec3 *posA, T3DVec3 *posB, AABB *boxA, AABB *boxB
void actors_init(void){
shuffle_array(xValues, 10);
shuffle_array(zValues, 10);
#if NUM_HILLS > 0
modelHill = t3d_model_load("rom:/hill.t3dm");
#endif
#if NUM_LILYPADS > 0
modelLilyPad = t3d_model_load("rom:/lily_pad.t3dm");
#endif
#if NUM_SPRINGS > 0
modelSpring = t3d_model_load("rom:/spring.t3dm");
#endif
#if NUM_FLYS > 0
modelFly = t3d_model_load("rom:/fly.t3dm");
#endif
#if NUM_HILLS > 0
hills_init();
#endif
#if NUM_LILYPADS > 0
lilypads_init();
#endif
#if NUM_SPRINGS > 0
springs_init();
#endif
#if NUM_FLYS > 0
flys_init();
#endif
}

#if NUM_HILLS > 0
// Initialize hills
void hills_init(void){
for (int i = 0; i < NUM_HILLS; ++i) {
Expand All @@ -132,17 +159,22 @@ void hills_init(void){
t3d_model_draw(modelHill);
dplHill[i] = rspq_block_end();

#if NUM_LILYPADS > 0
check_actor_collisions(&hillPos[i], lilypadPos, &hillBox[i], lilypadBox, NUM_LILYPADS);
hillBox[i] = (AABB){{{hillPos[i].v[0] - 64.0f, -1.0f, hillPos[i].v[2] - 64.0f }},
{{hillPos[i].v[0] + 64.0f, hillPos[i].v[1] + 25.0f, hillPos[i].v[2] + 64.0f}}};
#endif

#if NUM_SPRINGS > 0
check_actor_collisions(&hillPos[i], springPos, &hillBox[i], springBox, NUM_SPRINGS);
hillBox[i] = (AABB){{{hillPos[i].v[0] - 64.0f, -1.0f, hillPos[i].v[2] - 64.0f }},
{{hillPos[i].v[0] + 64.0f, hillPos[i].v[1] + 25.0f, hillPos[i].v[2] + 64.0f}}};
#endif
}
}
#endif


#if NUM_LILYPADS > 0
// Initialize lily pads
void lilypads_init(void){
for (int i = 0; i < NUM_LILYPADS; ++i) {
Expand All @@ -162,13 +194,17 @@ void lilypads_init(void){
dplLilypad[i] = rspq_block_end();

// Check and resolve collisions for each actor, then reset hitbox
#if NUM_HILLS > 0
check_actor_collisions(&lilypadPos[i], hillPos, &lilypadBox[i], hillBox, NUM_HILLS);
lilypadBox[i] = (AABB){{{lilypadPos[i].v[0] - 20.0f, -1.0f, lilypadPos[i].v[2] - 20.0f}},
{{lilypadPos[i].v[0] + 20.0f, 38.0f, lilypadPos[i].v[2] + 20.0f}}};
#endif

#if NUM_SPRINGS > 0
check_actor_collisions(&lilypadPos[i], springPos, &lilypadBox[i], springBox, NUM_SPRINGS);
lilypadBox[i] = (AABB){{{lilypadPos[i].v[0] - 20.0f, -1.0f, lilypadPos[i].v[2] - 20.0f}},
{{lilypadPos[i].v[0] + 20.0f, 38.0f, lilypadPos[i].v[2] + 20.0f}}};
#endif

t3d_mat4fp_from_srt_euler(lilypadMatFP[i], (float[3]){0.25f, 0.25f, 0.25f}, (float[3]){0, 0, 0}, lilypadPos[i].v);
t3d_mat4fp_from_srt_euler(boxMatFP[i], (float[3]){0.25f, 0.25f, 0.25f}, (float[3]){0, 0, 0}, lilypadPos[i].v);
Expand All @@ -179,7 +215,9 @@ void lilypads_init(void){
dplDebugBox[i] = rspq_block_end();
}
}
#endif

#if NUM_SPRINGS > 0
// Initialize springs
void springs_init(void){
for (int i = 0; i < NUM_SPRINGS; ++i) {
Expand All @@ -192,64 +230,61 @@ void springs_init(void){
springSkels[i] = t3d_skeleton_create(modelSpring);
springSkelBlends[i] = t3d_skeleton_clone(&springSkels[i], false);
animsSpring[i] = t3d_anim_create(modelSpring, "spring");
t3d_anim_set_looping(&animsSpring[i], false);
t3d_anim_set_playing(&animsSpring[i], false);
t3d_anim_set_time(&animsSpring[i], 0.0f);
t3d_anim_set_speed(&animsSpring[i], 2.5f);
t3d_anim_set_speed(&animsSpring[i], 50.0f);
t3d_anim_attach(&animsSpring[i], &springSkels[i]);

springActive[i] = false;
springActive[i] = true;
springForce = 120.0f;

springPos[i] = (T3DVec3){{x, y, z}};
springBox[i] = (AABB){{{x - 20.0f, -1.0f, z - 20.0f}}, {{x + 20.0f, 38.0f, z + 20.0f}}};

t3d_mat4fp_from_srt_euler(springMatFP[i], (float[3]){0.25f, 0.25f, 0.25f}, (float[3]){0, 0, 0}, springPos[i].v);

// Create gfx call to draw spring
rspq_block_begin();
t3d_matrix_set(springMatFP[i], true);
t3d_matrix_push(springMatFP[i]);
rdpq_set_prim_color(RGBA16(255, 255, 255, 255));
t3d_model_draw_skinned(modelSpring, &springSkels[i]);
t3d_matrix_pop(1);
dplSpring[i] = rspq_block_end();

// Check and resolve collisions for each actor, then reset hitbox
#if NUM_HILLS > 0
check_actor_collisions(&springPos[i], hillPos, &springBox[i], hillBox, NUM_HILLS);
springBox[i] = (AABB){{{springPos[i].v[0] - 20.0f, -1.0f, springPos[i].v[2] - 20.0f}},
{{springPos[i].v[0] + 20.0f, 38.0f, springPos[i].v[2] + 20.0f}}};
#endif

#if NUM_LILYPADS > 0
check_actor_collisions(&springPos[i], lilypadPos, &springBox[i], lilypadBox, NUM_LILYPADS);
springBox[i] = (AABB){{{springPos[i].v[0] - 20.0f, -1.0f, springPos[i].v[2] - 20.0f}},
{{springPos[i].v[0] + 20.0f, 38.0f, springPos[i].v[2] + 20.0f}}};
#endif

t3d_mat4fp_from_srt_euler(boxMatFP[i], (float[3]){0.25f, 0.25f, 0.25f}, (float[3]){0, 0, 0}, springPos[i].v);
rspq_block_begin();
t3d_matrix_set(boxMatFP[i], true);
t3d_matrix_push(boxMatFP[i]);
rdpq_set_prim_color(RGBA32(255, 0, 0, 120));
t3d_model_draw(modelDebugBox);
t3d_matrix_pop(1);
dplDebugBox2[i] = rspq_block_end();
}
}

void spring_update(void){
for (int i = 0; i < NUM_SPRINGS; ++i) {
t3d_mat4fp_from_srt_euler(springMatFP[i], (float[3]){0.25f, 0.25f, 0.25f}, (float[3]){0, 0, 0}, springPos[i].v);
if(player->activateSpring[i]){
springActive[i] = true;
player->activateSpring[i] = false;
}

if(springActive[i]) {
t3d_anim_set_playing(&animsSpring[i], true);
t3d_anim_update(&animsSpring[i], jumpTime);
}

if(!animsSpring[i].isPlaying) {
t3d_anim_set_time(&animsSpring[i], 0.0f);
springActive[i] = false;
t3d_anim_update(&animsSpring[i], deltaTime);
}
}
}
#endif

// Initialize flys
#if NUM_FLYS > 0
void flys_init(void){
for (int i = 0; i < NUM_FLYS; ++i) {
fly->pos = flyPos[i];
Expand All @@ -264,7 +299,7 @@ void flys_init(void){
sphereFlyMatFP[i] = malloc_uncached(sizeof(T3DMat4FP));

flySkels[i] = t3d_skeleton_create(modelFly);
flySkelBlends[i] = t3d_skeleton_clone(&flySkels[i], false);
flySkelBlends[i] = t3d_skeleton_clone(&flySkels[i], true);

animsFlying[i] = t3d_anim_create(modelFly, "flying");
t3d_anim_set_speed(&animsFlying[i], 10.0f);
Expand Down Expand Up @@ -297,7 +332,6 @@ void flys_init(void){
}
}


int closestPlayer = -1;
int closestHill = -1;
int closestLP = -1;
Expand Down Expand Up @@ -338,37 +372,54 @@ void fly_update(void){

Sphere *currPlayerBox;
closestPlayer = find_closest_actor(flyPos[i], &player->playerPos, NUM_PLAYERS);
#if NUM_HILLS > 0
AABB *currHill;
closestHill = find_closest_actor(flyPos[i], hillPos, NUM_HILLS);
#endif

#if NUM_LILYPADS > 0
AABB *currLP;
closestLP = find_closest_actor(flyPos[i], lilypadPos, NUM_LILYPADS);
#endif

#if NUM_SPRINGS > 0
AABB *currSpring;
closestSpring = find_closest_actor(flyPos[i], springPos, NUM_SPRINGS);
#endif

if (closestPlayer != -1){
currPlayerBox = &player[closestPlayer].playerBox;
if (check_sphere_collision(flyBox[i], *currPlayerBox)) {
resolve_sphere_collision(*currPlayerBox, &flyPos[i]);
}
}

#if NUM_HILLS > 0
if (closestHill != -1){
currHill = &hillBox[closestHill];
if (check_sphere_box_collision(flyBox[i], *currHill)) {
resolve_box_collision(*currHill, &flyPos[i], flyBox[i].radius);
}
}
#endif

#if NUM_LILYPADS > 0
if (closestLP != -1){
currLP = &lilypadBox[closestLP];
if (check_sphere_box_collision(flyBox[i], *currLP)) {
resolve_box_collision(*currLP, &flyPos[i], flyBox[i].radius);
}
}
#endif

#if NUM_SPRINGS > 0
if (closestSpring != -1){
currSpring = &springBox[closestHill];
currSpring = &springBox[closestSpring];
if (check_sphere_box_collision(flyBox[i], *currSpring)) {
resolve_box_collision(*currSpring, &flyPos[i], flyBox[i].radius);
}
}
#endif
}

float distanceFromPlayer = t3d_vec3_distance(&player->playerPos, &flyPos[i]);
Expand All @@ -379,8 +430,5 @@ void fly_update(void){
}
}
}
#endif

void actors_update(void){
spring_update();
fly_update();
}
21 changes: 14 additions & 7 deletions src/actors.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
#include "player.h"
#include "utils.h"

#if NUM_HILLS > 0
//Hills
extern T3DMat4FP* hillMatFP[NUM_HILLS];
extern T3DVec3 hillPos[NUM_HILLS];
extern AABB hillBox[NUM_HILLS];
extern rspq_block_t *dplHill[NUM_HILLS];
extern T3DModel *modelHill;
void hills_init(void);
#endif

#if NUM_LILYPADS > 0
//Lilypads
extern T3DMat4FP* lilypadMatFP[NUM_LILYPADS];
extern T3DMat4FP* boxMatFP[NUM_LILYPADS];
Expand All @@ -32,7 +36,10 @@ extern AABB lilypadBox[NUM_LILYPADS];
extern rspq_block_t *dplLilypad[NUM_LILYPADS];
extern rspq_block_t *dplDebugBox[NUM_LILYPADS];
extern T3DModel *modelLilyPad;
void lilypads_init(void);
#endif

#if NUM_SPRINGS > 0
// Springs
extern T3DMat4FP* springMatFP[NUM_SPRINGS];
extern T3DVec3 springPos[NUM_SPRINGS];
Expand All @@ -45,7 +52,11 @@ extern T3DSkeleton springSkelBlends[NUM_SPRINGS];
extern T3DAnim animsSpring[NUM_SPRINGS];
extern bool springActive[NUM_SPRINGS];
extern float springForce;
void springs_init(void);
void spring_update(void);
#endif

#if NUM_FLYS > 0
// Flys
extern T3DMat4FP* flyMatFP[NUM_FLYS];
extern T3DMat4FP* sphereFlyMatFP[NUM_FLYS];
Expand All @@ -66,16 +77,12 @@ extern T3DSkeleton flySkelBlends[NUM_FLYS];
extern T3DAnim animsFlying[NUM_FLYS];
extern T3DAnim animsDeath[NUM_FLYS];
extern int flyHide[NUM_FLYS];
void flys_init(void);
void fly_update(void);
#endif

void check_actor_collisions(T3DVec3 *posA, T3DVec3 *posB, AABB *boxA, AABB *boxB, int targetCount);
void actors_init(void);
void hills_init(void);
void lilypads_init(void);
void springs_init(void);
void spring_update(void);
void flys_init(void);
void fly_update(void);
void actors_update(void);


#endif // ACTORS_H
Loading

0 comments on commit 86d127d

Please sign in to comment.