maze is mazing
This commit is contained in:
parent
5de76322de
commit
4a27948ead
69
maze.c
69
maze.c
@ -87,9 +87,9 @@ mfloat_t dirtoyaw(uint8_t dir) {
|
||||
case DIRWEST:
|
||||
return -MPI_2;
|
||||
case DIRNORTH:
|
||||
return 0;
|
||||
case DIRSOUTH:
|
||||
return MPI;
|
||||
case DIRSOUTH:
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@ -135,6 +135,7 @@ uint8_t maze_longesthallway(uint8_t *maze, int size, int x, int y) {
|
||||
}
|
||||
face >>= 1;
|
||||
}
|
||||
eprintf("MAXFACE: %d\n", maxface);
|
||||
return maxface;
|
||||
}
|
||||
|
||||
@ -219,6 +220,8 @@ void maze_generate(uint8_t *maze, int size, struct vec2i *start,
|
||||
}
|
||||
|
||||
void maze_wall_generate(uint8_t *maze, int size, haloo3d_obj *obj) {
|
||||
// Reset ALL walls
|
||||
obj->numfaces = 0;
|
||||
// Simple: for each cell, we check if north or east is a wall. If so,
|
||||
// generate it. Also, generate walls for the south and west global wall
|
||||
for (int y = 0; y < size; y++) {
|
||||
@ -298,11 +301,15 @@ typedef struct {
|
||||
worldstate *state;
|
||||
} ecs_worldstate;
|
||||
|
||||
#define MAXGROWERS 10
|
||||
|
||||
// A component which holds onto data specifically for world
|
||||
// entities. You can think of it as private data so people
|
||||
// can't poke at the worldstate data
|
||||
typedef struct {
|
||||
worldstate *state;
|
||||
int numgrowers;
|
||||
haloo3d_obj_instance *growers[MAXGROWERS];
|
||||
haloo3d_obj_instance *walls;
|
||||
uint16_t timer;
|
||||
} ecs_world;
|
||||
@ -360,8 +367,10 @@ void sys_world(ecs_world *w) {
|
||||
break;
|
||||
case WSTATE_SPINUP:
|
||||
// Bring walls up, timer down
|
||||
scaleleft = 1 - w->walls->scale.y;
|
||||
w->walls->scale.y += scaleleft / w->timer;
|
||||
for (int i = 0; i < w->numgrowers; i++) {
|
||||
scaleleft = 1 - w->growers[i]->scale.y;
|
||||
w->growers[i]->scale.y += scaleleft / w->timer;
|
||||
}
|
||||
w->timer--;
|
||||
if (w->timer == 0) {
|
||||
eprintf("SPINUP COMPLETE, starting gameplay\n");
|
||||
@ -372,13 +381,15 @@ void sys_world(ecs_world *w) {
|
||||
break;
|
||||
case WSTATE_GAMEOVER:
|
||||
w->timer = spinspeed;
|
||||
eprintf("GAME OVER, spinning down\n");
|
||||
w->state->state = WSTATE_SPINDOWN;
|
||||
eprintf("GAME OVER, spinning down\n");
|
||||
break;
|
||||
case WSTATE_SPINDOWN:
|
||||
// Bring walls sown, timer down
|
||||
scaleleft = w->walls->scale.y;
|
||||
w->walls->scale.y -= scaleleft / w->timer;
|
||||
// Bring walls down, timer down
|
||||
for (int i = 0; i < w->numgrowers; i++) {
|
||||
scaleleft = w->growers[i]->scale.y;
|
||||
w->growers[i]->scale.y -= scaleleft / w->timer;
|
||||
}
|
||||
w->timer--;
|
||||
if (w->timer == 0) {
|
||||
eprintf("SPINDOWN COMPLETE, reinitializing\n");
|
||||
@ -465,6 +476,13 @@ static void sys_smartai(ecs_smartai *smartai, ecs_worldstate *ws,
|
||||
eprintf("SMARTAI: %d TIMER: %d DIR: %d POS: (%f, %f)\n",
|
||||
smartai->rotstate, smartai->timer, smartai->dir, anav->dest.x,
|
||||
anav->dest.z);
|
||||
if (smartai->mpos.x == ws->state->end.x &&
|
||||
smartai->mpos.y == ws->state->end.y) {
|
||||
eprintf("YOU WIN\n");
|
||||
ws->state->state = WSTATE_GAMEOVER;
|
||||
smartai->state = SAI_INIT;
|
||||
return;
|
||||
}
|
||||
// Player can only move forward if there's nothing in front of them
|
||||
if (maze_connected(ws->state->maze, smartai->mpos.x, smartai->mpos.y,
|
||||
MAZESIZE, smartai->dir)) {
|
||||
@ -559,6 +577,12 @@ void init_walltexture(haloo3d_fb *wallt) {
|
||||
haloo3d_apply_noise(wallt, NULL, 1.0 / 8);
|
||||
}
|
||||
|
||||
void init_starttexture(haloo3d_fb *startt) {
|
||||
haloo3d_fb_init_tex(startt, 64, 64);
|
||||
haloo3d_recti rect = {.x1 = 20, .x2 = 44, .y1 = 24, .y2 = 40};
|
||||
haloo3d_apply_rect(startt, &rect, 0xF777, 1);
|
||||
}
|
||||
|
||||
int main() { // int argc, char **argv) {
|
||||
|
||||
haloo3d_easystore storage;
|
||||
@ -582,9 +606,11 @@ int main() { // int argc, char **argv) {
|
||||
haloo3d_obj *flooro = haloo3d_easystore_addobj(&storage, "floor");
|
||||
haloo3d_obj *ceilo = haloo3d_easystore_addobj(&storage, "ceiling");
|
||||
haloo3d_obj *wallo = haloo3d_easystore_addobj(&storage, "walls");
|
||||
haloo3d_obj *starto = haloo3d_easystore_addobj(&storage, "start");
|
||||
haloo3d_fb *floort = haloo3d_easystore_addtex(&storage, "floor");
|
||||
haloo3d_fb *ceilt = haloo3d_easystore_addtex(&storage, "ceiling");
|
||||
haloo3d_fb *wallt = haloo3d_easystore_addtex(&storage, "walls");
|
||||
haloo3d_fb *startt = haloo3d_easystore_addtex(&storage, "start");
|
||||
|
||||
haloo3d_gen_plane(flooro, MAZESIZE);
|
||||
haloo3d_gen_plane(ceilo, MAZESIZE);
|
||||
@ -592,6 +618,8 @@ int main() { // int argc, char **argv) {
|
||||
init_floortexture(floort);
|
||||
init_ceilingtexture(ceilt);
|
||||
init_walltexture(wallt);
|
||||
init_starttexture(startt);
|
||||
haloo3d_gen_quad(starto, startt);
|
||||
|
||||
eprintf("Initialized models and textures\n");
|
||||
|
||||
@ -615,9 +643,12 @@ int main() { // int argc, char **argv) {
|
||||
haloo3d_easyrender_addinstance(&render, wallo, wallt);
|
||||
haloo3d_obj_instance *ceili =
|
||||
haloo3d_easyrender_addinstance(&render, ceilo, ceilt);
|
||||
haloo3d_obj_instance *starti =
|
||||
haloo3d_easyrender_addinstance(&render, starto, startt);
|
||||
floori->cullbackface = 0;
|
||||
ceili->cullbackface = 0;
|
||||
walli->cullbackface = 0;
|
||||
starti->cullbackface = 0;
|
||||
vec3(floori->scale.v, HSCALE, 1, HSCALE);
|
||||
vec3(ceili->scale.v, HSCALE, 1, HSCALE);
|
||||
vec3(walli->scale.v, HSCALE, 1, HSCALE);
|
||||
@ -671,6 +702,10 @@ int main() { // int argc, char **argv) {
|
||||
eprintf("World eid: %d\n", worldid);
|
||||
ECS_SETCOMPONENT(&ecs, worldid,
|
||||
ecs_world){.state = &wstate, .walls = walli, .timer = 0};
|
||||
// THis is horrible but whatever. The yshould be entities
|
||||
ecs.c_ecs_world[worldid].growers[0] = walli;
|
||||
ecs.c_ecs_world[worldid].growers[1] = starti;
|
||||
ecs.c_ecs_world[worldid].numgrowers = 2;
|
||||
|
||||
ecs_eid playerid = mecs_newentity(&ecs, 0);
|
||||
eprintf("Player eid: %d\n", playerid);
|
||||
@ -684,21 +719,6 @@ int main() { // int argc, char **argv) {
|
||||
ECS_SETCOMPONENT(&ecs, playerid,
|
||||
ecs_smartai){.state = SAI_INIT, .rotstate = 0, .timer = 0};
|
||||
|
||||
// // System is setup such that camera position matches maze index
|
||||
// render.camera.pos.x = 1.5 * HSCALE;
|
||||
// render.camera.pos.z = 0.5 * HSCALE;
|
||||
|
||||
// struct vec2i playerstart = {.x = 0, .y = 0};
|
||||
// struct vec2 playerrotation = {.x = render.camera.yaw,
|
||||
// .y = render.camera.pitch};
|
||||
// ECS_SETCOMPONENT(&ecs, playerid, ecs_rotateto){
|
||||
// .rot = playerrotation, .dstrot = playerrotation, .timer = 0};
|
||||
// ECS_SETCOMPONENT(&ecs, playerid, ecs_maze){
|
||||
// .maze = maze, .pos = playerstart, .size = MAZESIZE, .dir = DIRSOUTH};
|
||||
// ECS_SETCOMPONENT(&ecs, playerid, ecs_camera) & render.camera;
|
||||
// ECS_SETCOMPONENT(&ecs, playerid, ecs_smartai){.state = 0, .timer = 0};
|
||||
// eprintf("Player component mask: %lx\n", ecs.entities[playerid]);
|
||||
|
||||
// -----------------------------------
|
||||
// Actual rendering
|
||||
// -----------------------------------
|
||||
@ -747,6 +767,9 @@ int main() { // int argc, char **argv) {
|
||||
sys_camera_run(&ecs, i);
|
||||
}
|
||||
|
||||
starti->pos = render.camera.pos;
|
||||
starti->pos.z -= 1;
|
||||
|
||||
totaldrawn = 0;
|
||||
|
||||
haloo3d_obj_instance *object = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user