Compare commits
No commits in common. "1ebbd622b5309e00743a06de6d2bcdefd1edc04d" and "69a16c4920707fcf2bfd784247e9face2d47eb69" have entirely different histories.
1ebbd622b5
...
69a16c4920
BIN
obj/base.o
BIN
obj/base.o
Binary file not shown.
BIN
obj/display.o
BIN
obj/display.o
Binary file not shown.
BIN
obj/generation.o
BIN
obj/generation.o
Binary file not shown.
BIN
obj/main.o
BIN
obj/main.o
Binary file not shown.
BIN
obj/move.o
BIN
obj/move.o
Binary file not shown.
48
src/base.c
48
src/base.c
|
@ -118,25 +118,25 @@ bool str_equal(char* s1, char* s2) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------ //
|
||||
|
||||
cube_0 create_cube_0(double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b) {
|
||||
cube_0* cb = malloc(sizeof(cube_0)) ;
|
||||
cb->red = r ;
|
||||
cb->green = g ;
|
||||
cb->blue = b ;
|
||||
cb->x = x ;
|
||||
cb->y = y ;
|
||||
cb->z = z ;
|
||||
cb->w = w ;
|
||||
cb->h = h ;
|
||||
cb->d = d ;
|
||||
cb->hz_angle = hz_a ;
|
||||
cb->vt_angle = vt_a ;
|
||||
return *cb ;
|
||||
cube_0 create_cube_0(double x, double y, double z, double w, double h, double d, int r, int g, int b) {
|
||||
cube_0 cb ;
|
||||
cb.red = r ;
|
||||
cb.green = g ;
|
||||
cb.blue = b ;
|
||||
cb.x = x ;
|
||||
cb.y = y ;
|
||||
cb.z = z ;
|
||||
cb.w = w ;
|
||||
cb.h = h ;
|
||||
cb.d = d ;
|
||||
cb.hz_angle = 0.0 ;
|
||||
cb.vt_angle = 0.0 ;
|
||||
return cb ;
|
||||
}
|
||||
|
||||
cube create_cube(double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b) {
|
||||
cube create_cube(double x, double y, double z, double w, double h, double d, int r, int g, int b) {
|
||||
cube cb = malloc(sizeof(cube_0));
|
||||
*cb = create_cube_0(x, y, z, w, h, d, hz_a, vt_a, r, g, b) ;
|
||||
*cb = create_cube_0(x, y, z, w, d, h, r, g, b) ;
|
||||
return cb;
|
||||
}
|
||||
|
||||
|
@ -144,20 +144,6 @@ void free_cube(cube c) {
|
|||
free(c) ;
|
||||
}
|
||||
|
||||
teleporter create_teleporter(
|
||||
double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b,
|
||||
int chx_dest, int chy_dest, double x_dest, double y_dest, double z_dest
|
||||
) {
|
||||
teleporter* tp = malloc(sizeof(teleporter)) ;
|
||||
tp->dest_chx = chx_dest ;
|
||||
tp->dest_chy = chy_dest ;
|
||||
tp->dest_x = x_dest ;
|
||||
tp->dest_y = y_dest ;
|
||||
tp->dest_z = z_dest ;
|
||||
tp->hitbox = create_cube_0(x, y, z, w, h, d, hz_a, vt_a, r, g, b);
|
||||
return *tp ;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------ //
|
||||
|
||||
double convex_pt(double a, double b, double theta) {
|
||||
|
@ -212,7 +198,7 @@ double distance_pt_cube_0_3d(double x0, double y0, double z0, cube_0 c) {
|
|||
double zrx = zry*cos(c.vt_angle) + yry*sin(c.vt_angle) ;
|
||||
|
||||
// now the cube and pt are aligned, and (0, 0, 0) is at the cube's (bary)center
|
||||
return distance_pt_cube_aligned_3d(xrx, yrx, zrx, -c.w/2.0, -c.h/2.0, -c.d/2.0, c.w, c.h, c.d) ;
|
||||
return distance_pt_cube_aligned_3d(xrx, yrx, zrx, -c.w/2.0, -c.h/2.0, -c.d/2.0, c.w/2.0, c.h/2.0, c.d/2.0) ;
|
||||
}
|
||||
|
||||
double distance_pt_cube_3d(double x0, double y0, double z0, cube cb) {
|
||||
|
|
|
@ -15,14 +15,9 @@ int line_count(char* filename);
|
|||
int str_to_int(char* s);
|
||||
bool str_equal(char* s1, char* s2);
|
||||
|
||||
cube_0 create_cube_0(double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b);
|
||||
cube create_cube(double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b);
|
||||
cube_0 create_cube_0(double x, double y, double z, double w, double h, double d, int r, int g, int b);
|
||||
cube create_cube(double x, double y, double z, double w, double h, double d, int r, int g, int b);
|
||||
void free_cube(cube c);
|
||||
teleporter create_teleporter(
|
||||
double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b,
|
||||
int chx_dest, int chy_dest, double x_dest, double y_dest, double z_dest
|
||||
);
|
||||
|
||||
double convex_pt(double a, double b, double theta);
|
||||
double distance_pt_pt_3d(double x0, double y0, double z0, double x1, double y1, double z1);
|
||||
double distance_pt_seg_3d(double x, double y, double z, double sx, double sy, double sz, double ex, double ey, double ez);
|
||||
|
|
|
@ -214,93 +214,25 @@ void draw_segment(SDL_Renderer* renderer, double sx, double sy, double sz, doubl
|
|||
} // else : not visible (behind camera)
|
||||
}
|
||||
|
||||
void axialRotation_X0(double* y, double* z, double theta) {
|
||||
double y0 = *y ;
|
||||
*y = (*y)*cos(theta) - (*z)*sin(theta) ;
|
||||
*z = (*z)*cos(theta) + y0*sin(theta) ;
|
||||
}
|
||||
|
||||
void axialRotation_X(double* y, double* z, double theta, double cst_y, double cst_z) {
|
||||
// project the space onto the (y, z) plane to get cst_y and cst_z
|
||||
double y1 = *y - cst_y;
|
||||
double z1 = *z - cst_z;
|
||||
axialRotation_X0(&y1, &z1, theta);
|
||||
*y = y1 + cst_y ;
|
||||
*z = z1 + cst_z ;
|
||||
}
|
||||
|
||||
void axialRotation_Y0(double* x, double* z, double theta) {
|
||||
double x0 = *x ;
|
||||
*x = (*x)*cos(theta) + (*z)*sin(theta) ;
|
||||
*z = (*z)*cos(theta) - x0*sin(theta) ;
|
||||
}
|
||||
|
||||
void axialRotation_Y(double* x, double* z, double theta, double cst_x, double cst_z) {
|
||||
// project the space onto the (y, z) plane to get cst_y and cst_z
|
||||
double x1 = *x - cst_x;
|
||||
double z1 = *z - cst_z;
|
||||
axialRotation_Y0(&x1, &z1, theta);
|
||||
*x = x1 + cst_x ;
|
||||
*z = z1 + cst_z ;
|
||||
}
|
||||
|
||||
void axialRotation_Z0(double* x, double* y, double theta) {
|
||||
double x0 = *x ;
|
||||
*x = (*x)*cos(theta) - (*y)*sin(theta) ;
|
||||
*y = (*y)*cos(theta) + x0*sin(theta) ;
|
||||
}
|
||||
|
||||
void axialRotation_Z(double* x, double* y, double theta, double cst_x, double cst_y) {
|
||||
// project the space onto the (y, z) plane to get cst_y and cst_z
|
||||
double x1 = *x - cst_x;
|
||||
double y1 = *y - cst_y;
|
||||
axialRotation_Z0(&x1, &y1, theta);
|
||||
*x = x1 + cst_x ;
|
||||
*y = y1 + cst_y ;
|
||||
}
|
||||
|
||||
void drawSegmentRotated(SDL_Renderer* renderer, double sx, double sy, double sz, double ex, double ey, double ez, double hz_angle, double vt_angle, double center_x, double center_y, double center_z) {
|
||||
double psx = sx;
|
||||
double psy = sy;
|
||||
double psz = sz;
|
||||
double pex = ex;
|
||||
double pey = ey;
|
||||
double pez = ez;
|
||||
axialRotation_Y(&psx, &psz, hz_angle, center_x, center_z);
|
||||
axialRotation_Y(&pex, &pez, hz_angle, center_x, center_z);
|
||||
axialRotation_X(&psy, &psz, vt_angle, center_y, center_z);
|
||||
axialRotation_X(&pey, &pez, vt_angle, center_y, center_z);
|
||||
draw_segment(renderer, psx, psy, psz, pex, pey, pez);
|
||||
}
|
||||
|
||||
void drawOutlineOfCube_0(SDL_Renderer* renderer, cube_0 c) {
|
||||
SDL_SetRenderDrawColor(renderer, c.red, c.green, c.blue, 255) ;
|
||||
// x = constant
|
||||
drawSegmentRotated(renderer, c.x, c.y, c.z, c.x + c.w, c.y, c.z, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ;
|
||||
drawSegmentRotated(renderer, c.x, c.y + c.h, c.z, c.x + c.w, c.y + c.h, c.z, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ;
|
||||
drawSegmentRotated(renderer, c.x, c.y, c.z + c.d, c.x + c.w, c.y, c.z + c.d, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ;
|
||||
drawSegmentRotated(renderer, c.x, c.y + c.h, c.z + c.d, c.x + c.w, c.y + c.h, c.z + c.d, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ;
|
||||
draw_segment(renderer, c.x, c.y, c.z, c.x + c.w, c.y, c.z) ;
|
||||
draw_segment(renderer, c.x, c.y + c.h, c.z, c.x + c.w, c.y + c.h, c.z) ;
|
||||
draw_segment(renderer, c.x, c.y, c.z + c.d, c.x + c.w, c.y, c.z + c.d) ;
|
||||
draw_segment(renderer, c.x, c.y + c.h, c.z + c.d, c.x + c.w, c.y + c.h, c.z + c.d) ;
|
||||
|
||||
// y = constant
|
||||
drawSegmentRotated(renderer, c.x, c.y, c.z, c.x, c.y + c.h, c.z, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ;
|
||||
drawSegmentRotated(renderer, c.x + c.w, c.y, c.z, c.x + c.w, c.y + c.h, c.z, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ;
|
||||
drawSegmentRotated(renderer, c.x, c.y, c.z + c.d, c.x, c.y + c.h, c.z + c.d, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ;
|
||||
drawSegmentRotated(renderer, c.x + c.w, c.y, c.z + c.d, c.x + c.w, c.y + c.h, c.z + c.d, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ;
|
||||
draw_segment(renderer, c.x, c.y, c.z, c.x, c.y + c.h, c.z) ;
|
||||
draw_segment(renderer, c.x + c.w, c.y, c.z, c.x + c.w, c.y + c.h, c.z) ;
|
||||
draw_segment(renderer, c.x, c.y, c.z + c.d, c.x, c.y + c.h, c.z + c.d) ;
|
||||
draw_segment(renderer, c.x + c.w, c.y, c.z + c.d, c.x + c.w, c.y + c.h, c.z + c.d) ;
|
||||
|
||||
// z = constant
|
||||
drawSegmentRotated(renderer, c.x, c.y, c.z, c.x, c.y, c.z + c.d, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ;
|
||||
drawSegmentRotated(renderer, c.x + c.w, c.y, c.z, c.x + c.w, c.y, c.z + c.d, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ;
|
||||
drawSegmentRotated(renderer, c.x, c.y + c.h, c.z, c.x, c.y + c.h, c.z + c.d, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ;
|
||||
drawSegmentRotated(renderer, c.x + c.w, c.y + c.h, c.z, c.x + c.w, c.y + c.h, c.z + c.d, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ;
|
||||
}
|
||||
|
||||
void drawCurrentRoom(SDL_Renderer* renderer) {
|
||||
for(int k = 0; k < current_room->map_size; k++) {
|
||||
drawOutlineOfCube_0(renderer, current_room->map[k]);
|
||||
}
|
||||
for(int k = 0; k < current_room->tps_size; k++) {
|
||||
drawOutlineOfCube_0(renderer, current_room->tps[k].hitbox);
|
||||
}
|
||||
draw_segment(renderer, c.x, c.y, c.z, c.x, c.y, c.z + c.d) ;
|
||||
draw_segment(renderer, c.x + c.w, c.y, c.z, c.x + c.w, c.y, c.z + c.d) ;
|
||||
draw_segment(renderer, c.x, c.y + c.h, c.z, c.x, c.y + c.h, c.z + c.d) ;
|
||||
draw_segment(renderer, c.x + c.w, c.y + c.h, c.z, c.x + c.w, c.y + c.h, c.z + c.d) ;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------- //
|
||||
|
@ -309,10 +241,4 @@ void drawData(SDL_Renderer* renderer) {
|
|||
drawNumberToRenderer(renderer, digits, (int)camx, 10, 10, 75/2, 105/2, 0) ;
|
||||
drawNumberToRenderer(renderer, digits, (int)camy, 10, 60, 75/2, 105/2, 0) ;
|
||||
drawNumberToRenderer(renderer, digits, (int)camz, 10, 110, 75/2, 105/2, 0) ;
|
||||
|
||||
drawNumberToRenderer(renderer, digits, (int)(rot_hz*180.0/3.14159), 10, 160, 75/2, 105/2, 0) ;
|
||||
drawNumberToRenderer(renderer, digits, (int)(rot_vt*180.0/3.14159), 10, 210, 75/2, 105/2, 0) ;
|
||||
|
||||
drawNumberToRenderer(renderer, digits, player_chx, 310, 10, 75/2, 105/2, 0);
|
||||
drawNumberToRenderer(renderer, digits, player_chy, 310, 60, 75/2, 105/2, 0);
|
||||
}
|
|
@ -19,17 +19,9 @@ void drawCharToRenderer(SDL_Renderer* renderer, imgs data, char c, int X, int Y,
|
|||
void drawNumberToRenderer(SDL_Renderer* renderer, imgs data, int n, int X, int Y, int W, int H, int Woffset);
|
||||
void drawStringToRenderer(SDL_Renderer* renderer, imgs data, char* s, int X, int Y, int W, int H);
|
||||
|
||||
void axialRotation_X0(double* y, double* z, double theta);
|
||||
void axialRotation_X(double* y, double* z, double theta, double cst_y, double cst_z);
|
||||
void axialRotation_Y0(double* x, double* z, double theta);
|
||||
void axialRotation_Y(double* x, double* z, double theta, double cst_x, double cst_z);
|
||||
void axialRotation_Z0(double* x, double* y, double theta);
|
||||
void axialRotation_Z(double* x, double* z, double theta, double cst_x, double cst_z);
|
||||
|
||||
void project_to_camera(double x0, double y0, double z0, double* rx, double* ry, double* rz);
|
||||
void draw_segment(SDL_Renderer* renderer, double sx, double sy, double sz, double ex, double ey, double ez);
|
||||
void drawOutlineOfCube_0(SDL_Renderer* renderer, cube_0 c);
|
||||
void drawCurrentRoom(SDL_Renderer* renderer);
|
||||
|
||||
void drawData(SDL_Renderer* renderer);
|
||||
|
||||
|
|
|
@ -16,54 +16,4 @@
|
|||
#include "base.h"
|
||||
#include "generation.h"
|
||||
|
||||
hashtbl visited ;
|
||||
room* current_room ;
|
||||
|
||||
int player_chx ;
|
||||
int player_chy ;
|
||||
|
||||
void build_chunk_1(int chx, int chy) {
|
||||
room* new = malloc(sizeof(room));
|
||||
new->chunk_x = chx ;
|
||||
new->chunk_y = chy ;
|
||||
new->map = malloc(sizeof(cube_0)*6);
|
||||
new->map_size = 6 ;
|
||||
new->tps = malloc(sizeof(teleporter)*4);
|
||||
new->tps_size = 4 ;
|
||||
|
||||
new->map[0] = create_cube_0(0.0, 0.0, 0.0, 5.0, 1.0, 5.0, 0.0, 0.0, 255, 255, 255);
|
||||
new->map[1] = create_cube_0(0.0, 0.0, 0.0, 5.0, 1.0, 5.0, 3.14159/4.0, 0.0, 255, 255, 255);
|
||||
new->map[2] = create_cube_0(0.0, 1.0, 0.0, 1.0, 5.0, 1.0, 0.0, 0.0, 255, 255, 128);
|
||||
new->map[3] = create_cube_0(4.0, 1.0, 0.0, 1.0, 5.0, 1.0, 0.0, 0.0, 255, 255, 128);
|
||||
new->map[4] = create_cube_0(0.0, 1.0, 4.0, 1.0, 5.0, 1.0, 0.0, 0.0, 255, 255, 128);
|
||||
new->map[5] = create_cube_0(4.0, 1.0, 4.0, 1.0, 5.0, 1.0, 0.0, 0.0, 255, 255, 128);
|
||||
|
||||
new->tps[0] = create_teleporter(-1.0, 1.0, 2.0, 1.0, 2.0 + (double)(rand()%2), 1.0, 3.14159/4.0, 0.0, 255, 0, 0 , chx-1, chy , 2.5, 2.5, 2.5);
|
||||
new->tps[1] = create_teleporter(2.0, 1.0, -1.0, 1.0, 2.0 + (double)(rand()%2), 1.0, 3.14159/4.0, 0.0, 255, 255, 0, chx , chy+1, 2.5, 2.5, 2.5);
|
||||
new->tps[2] = create_teleporter(5.0, 1.0, 2.0, 1.0, 2.0 + (double)(rand()%2), 1.0, 3.14159/4.0, 0.0, 0, 255, 0 , chx+1, chy , 2.5, 2.5, 2.5);
|
||||
new->tps[3] = create_teleporter(2.0, 1.0, 5.0, 1.0, 2.0 + (double)(rand()%2), 1.0, 3.14159/4.0, 0.0, 0, 0, 255 , chx , chy-1, 2.5, 2.5, 2.5);
|
||||
|
||||
//printf("linked (%d, %d) to :\n", chx, chy);
|
||||
//printf(" {%d, %d}; {%d, %d}; {%d, %d}; {%d, %d}\n", chx-1, chy, chx, chy+1, chx+1, chy, chx, chy-1);
|
||||
|
||||
hashtbl_add(visited, chx, chy, new);
|
||||
}
|
||||
|
||||
void init_hashtbl() {
|
||||
visited = hashtbl_generate(1789);
|
||||
build_chunk_1(0, 0);
|
||||
current_room = hashtbl_find_opt(visited, 0, 0);
|
||||
player_chx = 0 ;
|
||||
player_chy = 0 ;
|
||||
}
|
||||
|
||||
void generate_nearby_chunks(int render_dist) {
|
||||
for(int w = -render_dist; w <= render_dist; w++) {
|
||||
for(int h = -render_dist; h <= render_dist; h++) {
|
||||
if(!hashtbl_mem(visited, player_chx + w, player_chy + h)) {
|
||||
//printf("generating (%d, %d)...\n", player_chx + w, player_chy + h);
|
||||
build_chunk_1(player_chx + w, player_chy + h);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// ------------------------------------------------------------------------ //
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef GEN_H
|
||||
#define GEN_H
|
||||
|
||||
void build_chunk_1(int chx, int chy);
|
||||
void init_hashtbl();
|
||||
void generate_nearby_chunks(int render_dist);
|
||||
|
||||
|
||||
#endif
|
|
@ -45,17 +45,17 @@ int main(int argc, char** argv) {
|
|||
|
||||
/* -------------------------------------------------------- */
|
||||
init_csts() ;
|
||||
init_hashtbl() ;
|
||||
import_digits(rend) ;
|
||||
import_letters(rend) ;
|
||||
cube_0 cb = create_cube_0(1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 255, 255, 255) ;
|
||||
while(true) {
|
||||
resetRenderer(rend) ;
|
||||
|
||||
SDL_SetRenderDrawColor(rend, 255, 255, 255, 255) ;
|
||||
playerActions() ;
|
||||
drawData(rend) ;
|
||||
generate_nearby_chunks(1);
|
||||
drawCurrentRoom(rend);
|
||||
drawOutlineOfCube_0(rend, cb) ;
|
||||
//draw_segment(rend, 1.0, 1.0, 1.0, 10.0, 2.0, -1.0) ;
|
||||
|
||||
updateRenderer(rend) ;
|
||||
usleep(1000000/60) ;
|
||||
|
|
93
src/move.c
93
src/move.c
|
@ -17,10 +17,9 @@
|
|||
#include "move.h"
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------- //
|
||||
double sensitivity = 0.22 ;
|
||||
double sensitivity = 0.3 ;
|
||||
double fov = 90.0 ;
|
||||
double speed = 1.0 ;
|
||||
double min_dist = 0.2 ;
|
||||
// ---------------------------------------------------------------------------------------------------- //
|
||||
|
||||
double camx ;
|
||||
|
@ -35,36 +34,14 @@ double tan_fov ;
|
|||
bool has_changed ;
|
||||
|
||||
void init_csts() {
|
||||
camx = 3.0 ;
|
||||
camy = 3.0 ;
|
||||
camz = 3.0 ;
|
||||
camx = 0.0 ;
|
||||
camy = 0.0 ;
|
||||
camz = 0.0 ;
|
||||
rot_hz = 0.0 ;
|
||||
rot_vt = 180.0 ;
|
||||
rot_vt = 0.0 ;
|
||||
tan_fov = tan((fov * 3.14159 / 180.0) / 2.0) ;
|
||||
}
|
||||
|
||||
bool is_colliding() {
|
||||
for(int k = 0; k < current_room->map_size; k++) {
|
||||
double dist = distance_pt_cube_0_3d(camx, camy, camz, current_room->map[k]) ;
|
||||
if(dist <= min_dist) {
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
for(int k = 0; k < current_room->tps_size; k++) {
|
||||
double dist = distance_pt_cube_0_3d(camx, camy, camz, current_room->tps[k].hitbox) ;
|
||||
if(dist <= min_dist) {
|
||||
player_chx = current_room->tps[k].dest_chx ;
|
||||
player_chy = current_room->tps[k].dest_chy ;
|
||||
camx = current_room->tps[k].dest_x ;
|
||||
camy = current_room->tps[k].dest_y ;
|
||||
camz = current_room->tps[k].dest_z ;
|
||||
current_room = hashtbl_find_opt(visited, player_chx, player_chy);
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
return false ;
|
||||
}
|
||||
|
||||
void playerActions() {
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event)) {
|
||||
|
@ -73,69 +50,39 @@ void playerActions() {
|
|||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
has_changed = true ;
|
||||
rot_hz += sensitivity * event.motion.xrel / 100.0 ;
|
||||
rot_hz -= sensitivity * event.motion.xrel / 100.0 ;
|
||||
rot_vt -= sensitivity * event.motion.yrel / 100.0 ;
|
||||
if(rot_hz >= 2*3.141592) {
|
||||
rot_hz -= 2*3.141592 ;
|
||||
} else if(rot_hz < 0.0) {
|
||||
rot_hz += 2*3.141592 ;
|
||||
}
|
||||
if(rot_vt <= 3.14159/2.0) {
|
||||
rot_vt = 3.14159/2.0;
|
||||
} else if(rot_vt >= 3.0*3.14159/2.0) {
|
||||
rot_vt = 3.0*3.14159/2.0 ;
|
||||
if(rot_vt >= 2*3.141592) {
|
||||
rot_vt -= 2*3.141592 ;
|
||||
} else if(rot_vt < 0.0) {
|
||||
rot_vt += 2*3.141592 ;
|
||||
}
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
has_changed = true ;
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_z:
|
||||
for(int k = 0; k < 10; k++) {
|
||||
camz += speed*cos(rot_hz)*cos(rot_vt)/10;
|
||||
camx -= speed*sin(rot_hz)*cos(rot_vt)/10;
|
||||
camy += speed*sin(rot_vt)/10;
|
||||
if(is_colliding()) {
|
||||
camz -= speed*cos(rot_hz)*cos(rot_vt)/10;
|
||||
camx += speed*sin(rot_hz)*cos(rot_vt)/10;
|
||||
camy -= speed*sin(rot_vt)/10;
|
||||
k=11;
|
||||
}
|
||||
}
|
||||
camz += speed*cos(rot_hz)*cos(rot_vt);
|
||||
camx -= speed*sin(rot_hz)*cos(rot_vt);
|
||||
camy += speed*sin(rot_vt);
|
||||
break;
|
||||
case SDLK_q:
|
||||
for(int k = 0; k < 10; k++) {
|
||||
camx -= speed*cos(rot_hz)/10;
|
||||
camz -= speed*sin(rot_hz)/10;
|
||||
if(is_colliding()) {
|
||||
camx += speed*cos(rot_hz)/10;
|
||||
camz += speed*sin(rot_hz)/10;
|
||||
k=11;
|
||||
}
|
||||
}
|
||||
camx -= speed*cos(rot_hz);
|
||||
camz -= speed*sin(rot_hz);
|
||||
break;
|
||||
case SDLK_s:
|
||||
for(int k = 0; k < 10; k++) {
|
||||
camz -= speed*cos(rot_hz)*cos(rot_vt)/10;
|
||||
camx += speed*sin(rot_hz)*cos(rot_vt)/10;
|
||||
camy -= speed*sin(rot_vt)/10;
|
||||
if(is_colliding()) {
|
||||
camz += speed*cos(rot_hz)*cos(rot_vt)/10;
|
||||
camx -= speed*sin(rot_hz)*cos(rot_vt)/10;
|
||||
camy += speed*sin(rot_vt)/10;
|
||||
k=11;
|
||||
}
|
||||
}
|
||||
camz -= speed*cos(rot_hz)*cos(rot_vt);
|
||||
camx += speed*sin(rot_hz)*cos(rot_vt);
|
||||
camy -= speed*sin(rot_vt);
|
||||
break;
|
||||
case SDLK_d:
|
||||
for(int k = 0; k < 10; k++) {
|
||||
camx += speed*cos(rot_hz)/10;
|
||||
camz += speed*sin(rot_hz)/10;
|
||||
if(is_colliding()) {
|
||||
camx -= speed*cos(rot_hz)/10;
|
||||
camz -= speed*sin(rot_hz)/10;
|
||||
k=11;
|
||||
}
|
||||
}
|
||||
camx += speed*cos(rot_hz);
|
||||
camz += speed*sin(rot_hz);
|
||||
break;
|
||||
|
||||
case SDLK_t:
|
||||
|
|
|
@ -26,17 +26,13 @@ typedef struct teleporter {
|
|||
int dest_chy ;
|
||||
double dest_x ;
|
||||
double dest_y ;
|
||||
double dest_z ;
|
||||
} teleporter ;
|
||||
|
||||
struct room {
|
||||
// (0, 0, 0) = bottom, left and down
|
||||
int chunk_x ;
|
||||
int chunk_y ;
|
||||
cube_0* map ;
|
||||
int map_size ;
|
||||
teleporter* tps ;
|
||||
int tps_size ;
|
||||
cube* map ;
|
||||
} ;
|
||||
typedef struct room room ;
|
||||
|
||||
|
@ -76,9 +72,5 @@ extern double tan_fov ;
|
|||
extern bool has_changed ;
|
||||
|
||||
extern hashtbl visited ;
|
||||
extern room* current_room ;
|
||||
|
||||
extern int player_chx ;
|
||||
extern int player_chy ;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue