Still tentatively sort of working maze
This commit is contained in:
parent
67cbfb0329
commit
21894acdb0
35
ecs_comps.h
35
ecs_comps.h
@ -40,23 +40,24 @@ typedef struct {
|
|||||||
// mt->pos = (*oi)->pos;
|
// mt->pos = (*oi)->pos;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Move camera position into moveto
|
// // Move camera position into moveto
|
||||||
static void sys_ecs_camera_moveto(haloo_ecs *ecs, hecs_eidt id, hecs_cidt camid,
|
// static void sys_ecs_camera_moveto(haloo_ecs *ecs, hecs_eidt id, hecs_cidt
|
||||||
hecs_cidt mtid) {
|
// camid,
|
||||||
// eprintf("Camera moveto %ld, %ld\n", camid, mtid);
|
// hecs_cidt mtid) {
|
||||||
ecs_moveto *mt = HECS_ENTITYCOMPONENT(ecs_moveto *, id, mtid, ecs);
|
// // eprintf("Camera moveto %ld, %ld\n", camid, mtid);
|
||||||
ecs_camera *cam = HECS_ENTITYCOMPONENT(ecs_camera *, id, camid, ecs);
|
// ecs_moveto *mt = HECS_ENTITYCOMPONENT(ecs_moveto *, id, mtid, ecs);
|
||||||
// eprintf("Camera moveto END\n");
|
// ecs_camera *cam = HECS_ENTITYCOMPONENT(ecs_camera *, id, camid, ecs);
|
||||||
mt->pos = (*cam)->pos;
|
// // eprintf("Camera moveto END\n");
|
||||||
}
|
// mt->pos = (*cam)->pos;
|
||||||
|
// }
|
||||||
static void sys_ecs_camera_rotateto(haloo_ecs *ecs, hecs_eidt id,
|
//
|
||||||
hecs_cidt camid, hecs_cidt rtid) {
|
// static void sys_ecs_camera_rotateto(haloo_ecs *ecs, hecs_eidt id,
|
||||||
ecs_rotateto *rt = HECS_ENTITYCOMPONENT(ecs_rotateto *, id, rtid, ecs);
|
// hecs_cidt camid, hecs_cidt rtid) {
|
||||||
ecs_camera *cam = HECS_ENTITYCOMPONENT(ecs_camera *, id, camid, ecs);
|
// ecs_rotateto *rt = HECS_ENTITYCOMPONENT(ecs_rotateto *, id, rtid, ecs);
|
||||||
rt->rot.x = (*cam)->yaw;
|
// ecs_camera *cam = HECS_ENTITYCOMPONENT(ecs_camera *, id, camid, ecs);
|
||||||
rt->rot.y = (*cam)->pitch;
|
// rt->rot.x = (*cam)->yaw;
|
||||||
}
|
// rt->rot.y = (*cam)->pitch;
|
||||||
|
// }
|
||||||
|
|
||||||
static void sys_ecs_moveto(haloo_ecs *ecs, hecs_eidt id, hecs_cidt mtid) {
|
static void sys_ecs_moveto(haloo_ecs *ecs, hecs_eidt id, hecs_cidt mtid) {
|
||||||
ecs_moveto *mt = HECS_ENTITYCOMPONENT(ecs_moveto *, id, mtid, ecs);
|
ecs_moveto *mt = HECS_ENTITYCOMPONENT(ecs_moveto *, id, mtid, ecs);
|
||||||
|
59
maze.c
59
maze.c
@ -18,10 +18,10 @@
|
|||||||
// INteresting flags for performance comparisons
|
// INteresting flags for performance comparisons
|
||||||
#define FASTFILL
|
#define FASTFILL
|
||||||
|
|
||||||
#define WIDTH 320
|
#define WIDTH 480
|
||||||
#define HEIGHT 200
|
#define HEIGHT 300
|
||||||
#define ASPECT ((float)WIDTH / HEIGHT)
|
#define ASPECT ((float)WIDTH / HEIGHT)
|
||||||
#define SCREENSCALE 3
|
#define SCREENSCALE 2
|
||||||
#define SWIDTH (WIDTH * SCREENSCALE)
|
#define SWIDTH (WIDTH * SCREENSCALE)
|
||||||
#define SHEIGHT (HEIGHT * SCREENSCALE)
|
#define SHEIGHT (HEIGHT * SCREENSCALE)
|
||||||
#define NEARCLIP 0.01
|
#define NEARCLIP 0.01
|
||||||
@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
// Game options
|
// Game options
|
||||||
#define MAZESIZE 15
|
#define MAZESIZE 15
|
||||||
#define HSCALE 1.0
|
#define HSCALE 1.5
|
||||||
|
|
||||||
// Maze grows in the positive direction
|
// Maze grows in the positive direction
|
||||||
#define MAZENORTH 1
|
#define MAZENORTH 1
|
||||||
@ -99,8 +99,8 @@ int maze_visited(uint8_t *maze, int x, int y, int size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int maze_connected(uint8_t *maze, int x, int y, int size, uint8_t move) {
|
int maze_connected(uint8_t *maze, int x, int y, int size, uint8_t move) {
|
||||||
eprintf("CHECKING DIR %d at (%d,%d), it is %d\n", move, x, y,
|
// eprintf("CHECKING DIR %d at (%d,%d), it is %d\n", move, x, y,
|
||||||
maze[x + y * size]);
|
// maze[x + y * size]);
|
||||||
if (move == DIREAST) {
|
if (move == DIREAST) {
|
||||||
return (maze[x + y * size] & MAZEEAST) == 0;
|
return (maze[x + y * size] & MAZEEAST) == 0;
|
||||||
} else if (move == DIRWEST) {
|
} else if (move == DIRWEST) {
|
||||||
@ -131,7 +131,6 @@ void maze_generate(uint8_t *maze, int size) {
|
|||||||
int mazetop = 0;
|
int mazetop = 0;
|
||||||
STACKPUSH(mazestack, mazetop, x + y * size);
|
STACKPUSH(mazestack, mazetop, x + y * size);
|
||||||
maze[x + y * size] |= MAZEVISIT;
|
maze[x + y * size] |= MAZEVISIT;
|
||||||
// struct vec2i visitable[4];
|
|
||||||
uint8_t visitable[4];
|
uint8_t visitable[4];
|
||||||
int visittop = 0;
|
int visittop = 0;
|
||||||
|
|
||||||
@ -208,9 +207,25 @@ static void sys_ecs_smartai(haloo_ecs *ecs, hecs_eidt id, hecs_cidt said,
|
|||||||
ecs_maze *maze = HECS_ENTITYCOMPONENT(ecs_maze *, id, mzid, ecs);
|
ecs_maze *maze = HECS_ENTITYCOMPONENT(ecs_maze *, id, mzid, ecs);
|
||||||
ecs_moveto *mt = HECS_ENTITYCOMPONENT(ecs_moveto *, id, mtid, ecs);
|
ecs_moveto *mt = HECS_ENTITYCOMPONENT(ecs_moveto *, id, mtid, ecs);
|
||||||
ecs_rotateto *rt = HECS_ENTITYCOMPONENT(ecs_rotateto *, id, rtid, ecs);
|
ecs_rotateto *rt = HECS_ENTITYCOMPONENT(ecs_rotateto *, id, rtid, ecs);
|
||||||
|
// Player can only move if the previous timer expired
|
||||||
|
// if (mt->timer == 0) {
|
||||||
|
// // Player can only move forward if they can't turn right
|
||||||
|
// uint8_t rightdir = TURNRIGHT(maze->dir);
|
||||||
|
// if (!maze_connected(maze->maze, maze->pos.x, maze->pos.y, maze->size,
|
||||||
|
// rightdir)) {
|
||||||
|
// struct vec2i movement = dirtovec(maze->dir);
|
||||||
|
// maze->pos.x += movement.x;
|
||||||
|
// maze->pos.y += movement.y;
|
||||||
|
// mt->timer = fps / 2;
|
||||||
|
// mt->dst.x += HSCALE * movement.x;
|
||||||
|
// mt->dst.z += HSCALE * movement.y;
|
||||||
|
// // smartai->state = 0; // We are no longer stuck, you can turn right
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// At this point,
|
||||||
if (mt->timer == 0) { // && rt->timer == 0) {
|
if (mt->timer == 0) { // && rt->timer == 0) {
|
||||||
eprintf("SMARTAI: %d DIR: %d POS: (%f, %f)\n", smartai->state, maze->dir,
|
// eprintf("SMARTAI: %d DIR: %d POS: (%f, %f)\n", smartai->state, maze->dir,
|
||||||
mt->pos.x, mt->pos.z);
|
// mt->pos.x, mt->pos.z);
|
||||||
// We can only do things if we're not moving and not rotating
|
// We can only do things if we're not moving and not rotating
|
||||||
// First, we see if we can turn right. If so, go for it.
|
// First, we see if we can turn right. If so, go for it.
|
||||||
uint8_t newdir = TURNRIGHT(maze->dir);
|
uint8_t newdir = TURNRIGHT(maze->dir);
|
||||||
@ -230,7 +245,7 @@ static void sys_ecs_smartai(haloo_ecs *ecs, hecs_eidt id, hecs_cidt said,
|
|||||||
// begin an animation to move there. Otherwise, turn left
|
// begin an animation to move there. Otherwise, turn left
|
||||||
if (!maze_connected(maze->maze, maze->pos.x, maze->pos.y, maze->size,
|
if (!maze_connected(maze->maze, maze->pos.x, maze->pos.y, maze->size,
|
||||||
maze->dir)) {
|
maze->dir)) {
|
||||||
if (rt->timer == 0) {
|
if (rt->timer <= 0) {
|
||||||
rt->dstrot.x = rt->rot.x - MPI_2;
|
rt->dstrot.x = rt->rot.x - MPI_2;
|
||||||
rt->timer = fps / 2;
|
rt->timer = fps / 2;
|
||||||
maze->dir = TURNLEFT(maze->dir);
|
maze->dir = TURNLEFT(maze->dir);
|
||||||
@ -243,8 +258,8 @@ static void sys_ecs_smartai(haloo_ecs *ecs, hecs_eidt id, hecs_cidt said,
|
|||||||
maze->pos.x += movement.x;
|
maze->pos.x += movement.x;
|
||||||
maze->pos.y += movement.y;
|
maze->pos.y += movement.y;
|
||||||
mt->timer = fps / 2;
|
mt->timer = fps / 2;
|
||||||
mt->dst.x += movement.x;
|
mt->dst.x += HSCALE * movement.x;
|
||||||
mt->dst.z += movement.y;
|
mt->dst.z += HSCALE * movement.y;
|
||||||
smartai->state = 0; // We are no longer stuck, you can turn right
|
smartai->state = 0; // We are no longer stuck, you can turn right
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -312,7 +327,7 @@ int main() { // int argc, char **argv) {
|
|||||||
uint16_t wallcols[] = {0xFA22};
|
uint16_t wallcols[] = {0xFA22};
|
||||||
haloo3d_apply_alternating(wallt, wallcols, 1);
|
haloo3d_apply_alternating(wallt, wallcols, 1);
|
||||||
haloo3d_apply_noise(wallt, NULL, 1.0 / 8);
|
haloo3d_apply_noise(wallt, NULL, 1.0 / 8);
|
||||||
haloo3d_apply_brick(wallt, 16, 11, 0xFEEE);
|
haloo3d_apply_brick(wallt, 18, 13, 0xFEEE);
|
||||||
// haloo3d_apply_brick(wallt, 14, 8, 0xFD94);
|
// haloo3d_apply_brick(wallt, 14, 8, 0xFD94);
|
||||||
haloo3d_apply_noise(wallt, NULL, 1.0 / 8);
|
haloo3d_apply_noise(wallt, NULL, 1.0 / 8);
|
||||||
eprintf("Initialized models and textures\n");
|
eprintf("Initialized models and textures\n");
|
||||||
@ -337,6 +352,12 @@ int main() { // int argc, char **argv) {
|
|||||||
vec3(floori->scale.v, HSCALE, 1, HSCALE);
|
vec3(floori->scale.v, HSCALE, 1, HSCALE);
|
||||||
vec3(ceili->scale.v, HSCALE, 1, HSCALE);
|
vec3(ceili->scale.v, HSCALE, 1, HSCALE);
|
||||||
vec3(walli->scale.v, HSCALE, 1, HSCALE);
|
vec3(walli->scale.v, HSCALE, 1, HSCALE);
|
||||||
|
floori->pos.x += MAZESIZE / 2.0 * HSCALE;
|
||||||
|
floori->pos.z += MAZESIZE / 2.0 * HSCALE;
|
||||||
|
ceili->pos.x += MAZESIZE / 2.0 * HSCALE;
|
||||||
|
ceili->pos.z += MAZESIZE / 2.0 * HSCALE;
|
||||||
|
walli->pos.x += MAZESIZE / 2.0 * HSCALE;
|
||||||
|
walli->pos.z += MAZESIZE / 2.0 * HSCALE;
|
||||||
// vec3(walli->scale.v, HSCALE, 0, HSCALE);
|
// vec3(walli->scale.v, HSCALE, 0, HSCALE);
|
||||||
ceili->pos.y = 1; //-1;
|
ceili->pos.y = 1; //-1;
|
||||||
eprintf("Setup all object instances\n");
|
eprintf("Setup all object instances\n");
|
||||||
@ -382,7 +403,10 @@ int main() { // int argc, char **argv) {
|
|||||||
|
|
||||||
// This is VERY critical: the player start is at 0 0 but in the maze that's
|
// This is VERY critical: the player start is at 0 0 but in the maze that's
|
||||||
// the center of the maze! This should probably be fixed or something!
|
// the center of the maze! This should probably be fixed or something!
|
||||||
struct vec2i playerstart = {.x = MAZESIZE / 2, .y = MAZESIZE / 2};
|
render.camera.pos.x = 0.5 * HSCALE;
|
||||||
|
render.camera.pos.z = 0.5 * HSCALE;
|
||||||
|
struct vec2i playerstart = {.x = 0,
|
||||||
|
.y = 0}; // MAZESIZE / 2, .y = MAZESIZE / 2};
|
||||||
struct vec2 playerrotation = {.x = render.camera.yaw,
|
struct vec2 playerrotation = {.x = render.camera.yaw,
|
||||||
.y = render.camera.pitch};
|
.y = render.camera.pitch};
|
||||||
HECS_SETCOMPONENT(ecs_moveto, &ecs, playerid){
|
HECS_SETCOMPONENT(ecs_moveto, &ecs, playerid){
|
||||||
@ -435,9 +459,10 @@ int main() { // int argc, char **argv) {
|
|||||||
// eprintf("CHECKING EID %d\n", i);
|
// eprintf("CHECKING EID %d\n", i);
|
||||||
// HECS_RUNSYS(&ecs, i, sys_ecs_objin_moveto, ecs_objin_id,
|
// HECS_RUNSYS(&ecs, i, sys_ecs_objin_moveto, ecs_objin_id,
|
||||||
// ecs_moveto_id);
|
// ecs_moveto_id);
|
||||||
HECS_RUNSYS(&ecs, i, sys_ecs_camera_rotateto, ecs_camera_id,
|
// HECS_RUNSYS(&ecs, i, sys_ecs_camera_rotateto, ecs_camera_id,
|
||||||
ecs_rotateto_id);
|
// ecs_rotateto_id);
|
||||||
HECS_RUNSYS(&ecs, i, sys_ecs_camera_moveto, ecs_camera_id, ecs_moveto_id);
|
// HECS_RUNSYS(&ecs, i, sys_ecs_camera_moveto, ecs_camera_id,
|
||||||
|
// ecs_moveto_id);
|
||||||
HECS_RUNSYS(&ecs, i, sys_ecs_smartai, ecs_smartai_id, ecs_maze_id,
|
HECS_RUNSYS(&ecs, i, sys_ecs_smartai, ecs_smartai_id, ecs_maze_id,
|
||||||
ecs_moveto_id, ecs_rotateto_id);
|
ecs_moveto_id, ecs_rotateto_id);
|
||||||
HECS_RUNSYS(&ecs, i, sys_ecs_moveto, ecs_moveto_id);
|
HECS_RUNSYS(&ecs, i, sys_ecs_moveto, ecs_moveto_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user