Compare commits
2 Commits
e161db3807
...
30717e9c1f
Author | SHA1 | Date |
---|---|---|
|
30717e9c1f | |
|
cf9e278068 |
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
||||||
CC = gcc
|
CC = gcc
|
||||||
FLAGS = -O2 -Wall -Wextra -g
|
FLAGS = -Wall -Wextra -g
|
||||||
LFLAGS = -lm src/glad.c -ldl -lglfw -lcglm
|
LFLAGS = -lm src/glad.c -ldl -lglfw -lcglm
|
||||||
|
|
||||||
all: bin/back
|
all: bin/back
|
||||||
|
|
BIN
obj/base.o
BIN
obj/base.o
Binary file not shown.
BIN
obj/bullets.o
BIN
obj/bullets.o
Binary file not shown.
BIN
obj/display.o
BIN
obj/display.o
Binary file not shown.
BIN
obj/entities.o
BIN
obj/entities.o
Binary file not shown.
BIN
obj/generation.o
BIN
obj/generation.o
Binary file not shown.
BIN
obj/hash.o
BIN
obj/hash.o
Binary file not shown.
BIN
obj/main.o
BIN
obj/main.o
Binary file not shown.
BIN
obj/menus.o
BIN
obj/menus.o
Binary file not shown.
BIN
obj/move.o
BIN
obj/move.o
Binary file not shown.
BIN
obj/proj.o
BIN
obj/proj.o
Binary file not shown.
26
src/base.c
26
src/base.c
|
@ -289,6 +289,13 @@ double distance_pt_cube_aligned_3d(double x0, double y0, double z0, double cx, d
|
||||||
return sqrt((x0-clx)*(x0-clx) + (y0-cly)*(y0-cly) + (z0-clz)*(z0-clz));
|
return sqrt((x0-clx)*(x0-clx) + (y0-cly)*(y0-cly) + (z0-clz)*(z0-clz));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double distance_pt_cube_aligned_3d_infinite(double x0, double y0, double z0, double cx, double cy, double cz, double cw, double ch, double cd) {
|
||||||
|
double clx = distance_pt_cube_axis(x0, cx, cx+cw);
|
||||||
|
double cly = distance_pt_cube_axis(y0, cy, cy+ch);
|
||||||
|
double clz = distance_pt_cube_axis(z0, cz, cz+cd);
|
||||||
|
return maxd(maxd(absf(clx-x0), absf(cly-y0)), absf(clz-z0));
|
||||||
|
}
|
||||||
|
|
||||||
double distance_pt_cube_0_3d(double x0, double y0, double z0, cube_0* c) {
|
double distance_pt_cube_0_3d(double x0, double y0, double z0, cube_0* c) {
|
||||||
// places the origin at the center of the cube
|
// places the origin at the center of the cube
|
||||||
double x = x0 - (c->x + c->w/2.0);
|
double x = x0 - (c->x + c->w/2.0);
|
||||||
|
@ -308,6 +315,25 @@ double distance_pt_cube_0_3d(double x0, double y0, double z0, cube_0* c) {
|
||||||
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, c->h, c->d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double distance_pt_cube_0_3d_infinite(double x0, double y0, double z0, cube_0* c) {
|
||||||
|
// places the origin at the center of the cube
|
||||||
|
double x = x0 - (c->x + c->w/2.0);
|
||||||
|
double y = y0 - (c->y + c->h/2.0);
|
||||||
|
double z = z0 - (c->z + c->d/2.0);
|
||||||
|
|
||||||
|
// rotate the point : y then x
|
||||||
|
double xry = x*cos(c->hz_angle) + z*sin(c->hz_angle);
|
||||||
|
double yry = y;
|
||||||
|
double zry = z*cos(c->hz_angle) - x*sin(c->hz_angle);
|
||||||
|
|
||||||
|
double xrx = xry;
|
||||||
|
double yrx = yry*cos(c->vt_angle) - zry*sin(c->vt_angle);
|
||||||
|
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_infinite(xrx, yrx, zrx, -c->w/2.0, -c->h/2.0, -c->d/2.0, c->w, c->h, c->d);
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------ //
|
// ------------------------------------------------------------------------------------------------ //
|
||||||
|
|
||||||
void project_to_camera(double x0, double y0, double z0, double* rx, double* ry, double* rz) {
|
void project_to_camera(double x0, double y0, double z0, double* rx, double* ry, double* rz) {
|
||||||
|
|
|
@ -49,6 +49,7 @@ double distance_pt_pt_2d_sq(double x0, double y0, double x1, double y1);
|
||||||
double distance_pt_pt_3d_sq(double x0, double y0, double z0, double x1, double y1, double z1);
|
double distance_pt_pt_3d_sq(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);
|
double distance_pt_seg_3d(double x, double y, double z, double sx, double sy, double sz, double ex, double ey, double ez);
|
||||||
double distance_pt_cube_0_3d(double x0, double y0, double z0, cube_0* c);
|
double distance_pt_cube_0_3d(double x0, double y0, double z0, cube_0* c);
|
||||||
|
double distance_pt_cube_0_3d_infinite(double x0, double y0, double z0, cube_0* c);
|
||||||
|
|
||||||
void remove_entity(entity** arr, int* memlen, int* len, int index);
|
void remove_entity(entity** arr, int* memlen, int* len, int index);
|
||||||
void add_entity(entity** arr, int* memlen, int* len, entity* ent);
|
void add_entity(entity** arr, int* memlen, int* len, entity* ent);
|
||||||
|
|
|
@ -220,5 +220,8 @@ void gl_drawData(unsigned int shaderProg) {
|
||||||
gl_drawInteger(shaderProg, (int)10.0*camvy, 0.95f, -0.75f, 0.05f, 255, 255, 255, 0.005, -1);
|
gl_drawInteger(shaderProg, (int)10.0*camvy, 0.95f, -0.75f, 0.05f, 255, 255, 255, 0.005, -1);
|
||||||
gl_drawInteger(shaderProg, (int)10.0*camvz, 0.95f, -0.9f, 0.05f, 255, 255, 255, 0.005, -1);
|
gl_drawInteger(shaderProg, (int)10.0*camvz, 0.95f, -0.9f, 0.05f, 255, 255, 255, 0.005, -1);
|
||||||
|
|
||||||
|
gl_drawInteger(shaderProg, njumps, 0.0f, 0.80f, 0.04f, 255, 255, 128, 0.005f, 1);
|
||||||
|
|
||||||
|
gl_drawString(shaderProg, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", -0.95f, 0.7f, 0.03f, 255-player_hp/4, player_hp/4, 0, 0.003f, 1);
|
||||||
gl_drawInteger(shaderProg, player_hp, -0.95f, 0.9f, 0.05f, 255-player_hp/4, player_hp/4, 0, 0.005f, 1);
|
gl_drawInteger(shaderProg, player_hp, -0.95f, 0.9f, 0.05f, 255-player_hp/4, player_hp/4, 0, 0.005f, 1);
|
||||||
}
|
}
|
|
@ -118,9 +118,9 @@ void go_to_player(double x, double y, double z, double w, double h, double d, do
|
||||||
double dy = (y+h/2 - camy);
|
double dy = (y+h/2 - camy);
|
||||||
double dz = (z+d/2 - camz);
|
double dz = (z+d/2 - camz);
|
||||||
double total = sqrt(dx*dx + dy*dy + dz*dz);
|
double total = sqrt(dx*dx + dy*dy + dz*dz);
|
||||||
dx = 110.0*dx/total;
|
dx = 11.0*dx/total;
|
||||||
dy = 110.0*dy/total;
|
dy = 11.0*dy/total;
|
||||||
dz = 110.0*dz/total;
|
dz = 11.0*dz/total;
|
||||||
ret->x -= dtime*dx;
|
ret->x -= dtime*dx;
|
||||||
if(is_colliding_with_map(ret) || is_colliding_with_tp(ret)) {
|
if(is_colliding_with_map(ret) || is_colliding_with_tp(ret)) {
|
||||||
ret->x += dtime*dx;
|
ret->x += dtime*dx;
|
||||||
|
|
|
@ -150,9 +150,9 @@ void build_starting_chunk(int chx, int chy) {
|
||||||
new->tps_size = 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[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, 0.0, 0.0, 255, 255, 255);
|
new->map[1] = create_cube_0(0.0, 15.0, 0.0, 5.0, 1.0, 5.0, 0.0, 0.0, 255, 255, 255);
|
||||||
new->map[2] = create_cube_0(0.0, 0.0, 0.0, 5.0, 1.0, 5.0, 0.0, 0.0, 255, 255, 255);
|
new->map[2] = create_cube_0(0.0, 30.0, 0.0, 5.0, 1.0, 5.0, 0.0, 0.0, 255, 255, 255);
|
||||||
new->map[3] = create_cube_0(0.0, 0.0, 0.0, 5.0, 1.0, 5.0, 0.0, 0.0, 255, 255, 255);
|
new->map[3] = create_cube_0(0.0, 45.0, 0.0, 5.0, 1.0, 5.0, 0.0, 0.0, 255, 255, 255);
|
||||||
new->map[4] = create_cube_0(0.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, 0.0, 1.0, 5.0, 1.0, 0.0, 0.0, 255, 255, 128);
|
||||||
new->map[5] = create_cube_0(4.0, 1.0, 0.0, 1.0, 5.0, 1.0, 0.0, 0.0, 255, 255, 128);
|
new->map[5] = create_cube_0(4.0, 1.0, 0.0, 1.0, 5.0, 1.0, 0.0, 0.0, 255, 255, 128);
|
||||||
new->map[6] = create_cube_0(0.0, 1.0, 4.0, 1.0, 5.0, 1.0, 0.0, 0.0, 255, 255, 128);
|
new->map[6] = create_cube_0(0.0, 1.0, 4.0, 1.0, 5.0, 1.0, 0.0, 0.0, 255, 255, 128);
|
||||||
|
|
37
src/main.c
37
src/main.c
|
@ -22,11 +22,14 @@
|
||||||
|
|
||||||
double sim_time;
|
double sim_time;
|
||||||
int triCount;
|
int triCount;
|
||||||
|
unsigned int fffff;
|
||||||
|
|
||||||
|
double jPress = false;
|
||||||
void processInput(GLFWwindow *window, float dtime) {
|
void processInput(GLFWwindow *window, float dtime) {
|
||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
}
|
}
|
||||||
|
bool pressed = false;
|
||||||
if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
|
if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
|
||||||
/*
|
/*
|
||||||
for(int k = 0; k < 10; k++) {
|
for(int k = 0; k < 10; k++) {
|
||||||
|
@ -41,9 +44,10 @@ void processInput(GLFWwindow *window, float dtime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
camvz = -speed*cos(rot_hz)*cos(rot_vt);
|
camvz = -speed*cos(rot_hz);
|
||||||
camvx = -speed*sin(rot_hz)*cos(rot_vt);
|
camvx = -speed*sin(rot_hz);
|
||||||
camvy = vtmult*speed*sin(rot_vt);
|
pressed = true;
|
||||||
|
//camvy = vtmult*speed*sin(rot_vt);
|
||||||
}
|
}
|
||||||
if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
|
if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
|
||||||
/*
|
/*
|
||||||
|
@ -58,6 +62,7 @@ void processInput(GLFWwindow *window, float dtime) {
|
||||||
}*/
|
}*/
|
||||||
camvx = -speed*cos(rot_hz);
|
camvx = -speed*cos(rot_hz);
|
||||||
camvz = speed*sin(rot_hz);
|
camvz = speed*sin(rot_hz);
|
||||||
|
pressed = true;
|
||||||
}
|
}
|
||||||
if(glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) {
|
if(glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) {
|
||||||
/*for(int k = 0; k < 10; k++) {
|
/*for(int k = 0; k < 10; k++) {
|
||||||
|
@ -71,9 +76,10 @@ void processInput(GLFWwindow *window, float dtime) {
|
||||||
k=11;
|
k=11;
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
camvz = speed*cos(rot_hz)*cos(rot_vt);
|
camvz = speed*cos(rot_hz);
|
||||||
camvx = speed*sin(rot_hz)*cos(rot_vt);
|
camvx = speed*sin(rot_hz);
|
||||||
camvy = -vtmult*speed*sin(rot_vt);
|
pressed = true;
|
||||||
|
//camvy = -vtmult*speed*sin(rot_vt);
|
||||||
}
|
}
|
||||||
if(glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) {
|
if(glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) {
|
||||||
/*for(int k = 0; k < 10; k++) {
|
/*for(int k = 0; k < 10; k++) {
|
||||||
|
@ -87,11 +93,21 @@ void processInput(GLFWwindow *window, float dtime) {
|
||||||
}*/
|
}*/
|
||||||
camvx = speed*cos(rot_hz);
|
camvx = speed*cos(rot_hz);
|
||||||
camvz = -speed*sin(rot_hz);
|
camvz = -speed*sin(rot_hz);
|
||||||
|
pressed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) {
|
if(njumps > 0 && glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) {
|
||||||
camvx = 0.0;
|
if(jPress) {
|
||||||
camvz = 0.0;
|
camvy = vtmult*speed;
|
||||||
|
njumps -= 1;
|
||||||
|
jPress = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
jPress = true;
|
||||||
|
}
|
||||||
|
if(!pressed) {
|
||||||
|
camvx *= (1.0-1.0*5.0*((double)dtime));
|
||||||
|
camvz *= (1.0-1.0*5.0*((double)dtime));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) {
|
if(glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) {
|
||||||
|
@ -301,8 +317,9 @@ int main_alt() {
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------------------------------------------------------- //
|
// ---------------------------------------------------------------------------------------------------------------------------------------------- //
|
||||||
// ---------------------------------------------------------------------------------------------------------------------------------------------- //
|
// ---------------------------------------------------------------------------------------------------------------------------------------------- //
|
||||||
|
fffff = shaderProgram;
|
||||||
|
|
||||||
int fps = 60;
|
int fps = 90;
|
||||||
int interval = 1000000/fps;
|
int interval = 1000000/fps;
|
||||||
double slp_time = 1.0/fps;
|
double slp_time = 1.0/fps;
|
||||||
|
|
||||||
|
|
169
src/menus.c
169
src/menus.c
|
@ -1,5 +1,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
@ -129,6 +130,174 @@ void gl_drawInteger(unsigned int fragShader, int n, float x, float y, float size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gl_drawChar(unsigned int fragShader, char ch, float x, float y, float size, int r, int g, int b, float width) {
|
||||||
|
if(ch == 'a' || ch == 'A') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
} else if(ch == 'b' || ch == 'B') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-size+width, 2*width, 2*size-width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, size, 2*width, r, g, b);
|
||||||
|
} else if(ch == 'c' || ch == 'C') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
} else if(ch == 'd' || ch == 'D') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2+width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
} else if(ch == 'e' || ch == 'E') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
} else if(ch == 'f' || ch == 'F') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-width, size+2*width, 2*width, r, g, b);
|
||||||
|
} else if(ch == 'g' || ch == 'G') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-width, y-width, size/2+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-size-width, 2*width, size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
} else if(ch == 'h' || ch == 'H') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
} else if(ch == 'i' || ch == 'I') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
} else if(ch == 'j' || ch == 'J') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, size/2+2*width, 2*width, r, g, b);
|
||||||
|
} else if(ch == 'k' || ch == 'K') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-width, size/2+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-width, y-size/2-width, 2*width, size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y+size/2-width, 2*width, size/2+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-size-width, 2*width, size/2+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-width, y+size/2-width, size/2+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-width, y-size/2-width, size/2+2*width, 2*width, r, g, b);
|
||||||
|
} else if(ch == 'l' || ch == 'L') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
} else if(ch == 'm' || ch == 'M') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-width, y-width, 2*width, size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
} else if(ch == 'n' || ch == 'N') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
} else if(ch == 'o' || ch == 'O') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
} else if(ch == 'p' || ch == 'P') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-width, 2*width, size+2*width, r, g, b);
|
||||||
|
} else if(ch == 'q' || ch == 'Q') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size/2-width, 2*width, 3*size/2+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-size/2-width, 2*width, 3*size/2+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size/2-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/4-width, y-size-width, 2*width, size/2+2*width, r, g, b);
|
||||||
|
} else if(ch == 'r' || ch == 'R') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-width, 2*width, size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/4-width, y-size-width, 2*width, size+2*width, r, g, b);
|
||||||
|
} else if(ch == 's' || ch == 'S') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-width, 2*width, size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-size-width, 2*width, size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
} else if(ch == 't' || ch == 'T') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
} else if(ch == 'u' || ch == 'U') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
} else if(ch == 'v' || ch == 'V') {
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-width, 2*width, size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-width, 2*width, size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/4-width, y-size-width, 2*width, size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/4-width, y-size-width, 2*width, size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-width, size/4+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/4-width, y-width, size/4+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/4-width, y-size-width, size/2+2*width, 2*width, r, g, b);
|
||||||
|
} else if(ch == 'w' || ch == 'W') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-width, y-size-width, 2*width, size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-size-width, 2*width, 2*size+2*width, r, g, b);
|
||||||
|
} else if(ch == 'x' || ch == 'X') {
|
||||||
|
gl_drawRect(fragShader, x-width, y-size/2-width, 2*width, size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y+size/2-width, 2*width, size/2+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-size-width, 2*width, size/2+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size/2-width, 2*width, size/2+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, size/2+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size/2-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size/2-width, size+2*width, 2*width, r, g, b);
|
||||||
|
} else if(ch == 'y' || ch == 'Y') {
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-width, 2*width, size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-width, y-size-width, 2*width, size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-width, 2*width, size+2*width, r, g, b);
|
||||||
|
} else if(ch == 'z' || ch == 'Z') {
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y+size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x+size/2-width, y-width, 2*width, size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-width, size+2*width, 2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, 2*width, size+2*width, r, g, b);
|
||||||
|
gl_drawRect(fragShader, x-size/2-width, y-size-width, size+2*width, 2*width, r, g, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_string_len(char* s) {
|
||||||
|
int k = 0;
|
||||||
|
while(s[k] != '\0') {
|
||||||
|
k+=1;
|
||||||
|
}
|
||||||
|
return k;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7-segment display
|
||||||
|
// side can be -1 (aligned right) or 1 (aligned left)
|
||||||
|
void gl_drawString(unsigned int fragShader, char* str, float x, float y, float size, int r, int g, int b, float width, int side) {
|
||||||
|
float curx = x;
|
||||||
|
int len = get_string_len(str);
|
||||||
|
if(side == 1) {
|
||||||
|
curx += ((len)*(size+4*width));
|
||||||
|
}
|
||||||
|
char c = str[len-1];
|
||||||
|
int i = len-1;
|
||||||
|
while(i >= 0) {
|
||||||
|
gl_drawChar(fragShader, c, curx, y, size, r, g, b, width);
|
||||||
|
curx -= (size+4*width);
|
||||||
|
i -= 1;
|
||||||
|
c = str[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void gl_printf(unsigned int fragShader, int count, ...) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void gl_initDrawRect(unsigned int shaderProgram) {
|
void gl_initDrawRect(unsigned int shaderProgram) {
|
||||||
glUseProgram(shaderProgram);
|
glUseProgram(shaderProgram);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ void gl_drawRect(unsigned int fragShader, float x, float y, float w, float h, in
|
||||||
void gl_initDrawRect(unsigned int shaderProgram);
|
void gl_initDrawRect(unsigned int shaderProgram);
|
||||||
|
|
||||||
void gl_drawInteger(unsigned int fragShader, int n, float x, float y, float size, int r, int g, int b, float width, int side);
|
void gl_drawInteger(unsigned int fragShader, int n, float x, float y, float size, int r, int g, int b, float width, int side);
|
||||||
|
void gl_drawString(unsigned int fragShader, char* str, float x, float y, float size, int r, int g, int b, float width, int side);
|
||||||
|
|
||||||
void init_interf();
|
void init_interf();
|
||||||
void free_interf();
|
void free_interf();
|
||||||
|
|
50
src/move.c
50
src/move.c
|
@ -21,11 +21,15 @@ double fov = 90.0;
|
||||||
double creative_speed = 0.3;
|
double creative_speed = 0.3;
|
||||||
double speed = 8.0;
|
double speed = 8.0;
|
||||||
double vtmult = 1.5;
|
double vtmult = 1.5;
|
||||||
double min_dist = 0.1;
|
double min_dist = 0.4;
|
||||||
double friction = 0.8;
|
double friction = 0.3;
|
||||||
double gravity_factor = 9.8;
|
double gravity_factor = 9.8;
|
||||||
// ---------------------------------------------------------------------------------------------------- //
|
// ---------------------------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
bool is_clipping = false;
|
||||||
|
int clip_dps = 500;
|
||||||
|
|
||||||
|
int njumps;
|
||||||
double fx;
|
double fx;
|
||||||
double fy;
|
double fy;
|
||||||
double fz;
|
double fz;
|
||||||
|
@ -73,6 +77,7 @@ void init_csts() {
|
||||||
room_width = 16.0;
|
room_width = 16.0;
|
||||||
room_depth = 16.0;
|
room_depth = 16.0;
|
||||||
sq2 = sqrt(2);
|
sq2 = sqrt(2);
|
||||||
|
njumps = 3;
|
||||||
stop_evetything = false;
|
stop_evetything = false;
|
||||||
tan_fov = tan((fov * 3.14159 / 180.0) / 2.0);
|
tan_fov = tan((fov * 3.14159 / 180.0) / 2.0);
|
||||||
}
|
}
|
||||||
|
@ -143,11 +148,19 @@ void normalize(pt_2d* p) {
|
||||||
|
|
||||||
void updateF(cube_0* cb, double dtime) {
|
void updateF(cube_0* cb, double dtime) {
|
||||||
for(int d = 0; d < 6; d++) {
|
for(int d = 0; d < 6; d++) {
|
||||||
cb->x -= min_dist; cb->y -= min_dist; cb->z -= min_dist;
|
cb->x -= min_dist;
|
||||||
cb->w += 2*min_dist; cb->h += 2*min_dist; cb->d += 2*min_dist;
|
cb->y -= min_dist;
|
||||||
|
cb->z -= min_dist;
|
||||||
|
cb->w += 2*min_dist;
|
||||||
|
cb->h += 2*min_dist;
|
||||||
|
cb->d += 2*min_dist;
|
||||||
getSF(cb, d);
|
getSF(cb, d);
|
||||||
cb->x += min_dist; cb->y += min_dist; cb->z += min_dist;
|
cb->x += min_dist;
|
||||||
cb->w -= 2*min_dist; cb->h -= 2*min_dist; cb->d -= 2*min_dist;
|
cb->y += min_dist;
|
||||||
|
cb->z += min_dist;
|
||||||
|
cb->w -= 2*min_dist;
|
||||||
|
cb->h -= 2*min_dist;
|
||||||
|
cb->d -= 2*min_dist;
|
||||||
getDirectors();
|
getDirectors();
|
||||||
getNormal();
|
getNormal();
|
||||||
if(d%2==1) {
|
if(d%2==1) {
|
||||||
|
@ -175,13 +188,19 @@ void updateF(cube_0* cb, double dtime) {
|
||||||
camvx += u.x;
|
camvx += u.x;
|
||||||
camvy += u.y;
|
camvy += u.y;
|
||||||
camvz += u.z;
|
camvz += u.z;
|
||||||
|
|
||||||
|
camvx /= 1.41;
|
||||||
|
camvy /= 1.41;
|
||||||
|
camvz /= 1.41;
|
||||||
|
|
||||||
|
is_clipping = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_colliding(float dtime) {
|
bool is_colliding(float dtime) {
|
||||||
for(int k = 0; k < current_room->map_size; k++) {
|
for(int k = 0; k < current_room->map_size; k++) {
|
||||||
double dist = distance_pt_cube_0_3d(camx, camy, camz, current_room->map[k]);
|
double dist = distance_pt_cube_0_3d_infinite(camx, camy, camz, current_room->map[k]);
|
||||||
if(dist <= min_dist) {
|
if(dist <= min_dist) {
|
||||||
if(updateForces) {
|
if(updateForces) {
|
||||||
updateF(current_room->map[k], (double)dtime);
|
updateF(current_room->map[k], (double)dtime);
|
||||||
|
@ -190,7 +209,7 @@ bool is_colliding(float dtime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(int k = 0; k < current_room->tps_size; k++) {
|
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);
|
double dist = distance_pt_cube_0_3d_infinite(camx, camy, camz, current_room->tps[k]->hitbox);
|
||||||
if(dist <= min_dist) {
|
if(dist <= min_dist) {
|
||||||
if(updateForces) {
|
if(updateForces) {
|
||||||
updateF(current_room->tps[k]->hitbox, (double)dtime);
|
updateF(current_room->tps[k]->hitbox, (double)dtime);
|
||||||
|
@ -206,7 +225,7 @@ bool is_colliding(float dtime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(int k = 0; k < current_room->ent_len; k++) {
|
for(int k = 0; k < current_room->ent_len; k++) {
|
||||||
double dist = distance_pt_cube_0_3d(camx, camy, camz, current_room->ents[k]->pos);
|
double dist = distance_pt_cube_0_3d_infinite(camx, camy, camz, current_room->ents[k]->pos);
|
||||||
if(dist <= min_dist) {
|
if(dist <= min_dist) {
|
||||||
if(current_room->ents[k]->onHit != NULL) {
|
if(current_room->ents[k]->onHit != NULL) {
|
||||||
(*current_room->ents[k]->onHit)(dtime, current_room->ents[k]->hitpoints, ¤t_room->ents[k]->damage, current_room->ents[k], &(*(current_room->ents[k]->pos)));
|
(*current_room->ents[k]->onHit)(dtime, current_room->ents[k]->hitpoints, ¤t_room->ents[k]->damage, current_room->ents[k], &(*(current_room->ents[k]->pos)));
|
||||||
|
@ -234,6 +253,7 @@ void movePlayerG(float dtime) {
|
||||||
fz = 0.0;
|
fz = 0.0;
|
||||||
|
|
||||||
camvy -= gravity_factor*dtime;
|
camvy -= gravity_factor*dtime;
|
||||||
|
bool isfalling = camvy < 0.0;
|
||||||
|
|
||||||
double delx = camvx*dtime;
|
double delx = camvx*dtime;
|
||||||
double dely = camvy*dtime;
|
double dely = camvy*dtime;
|
||||||
|
@ -241,8 +261,12 @@ void movePlayerG(float dtime) {
|
||||||
camx += delx;
|
camx += delx;
|
||||||
camy += dely;
|
camy += dely;
|
||||||
camz += delz;
|
camz += delz;
|
||||||
|
is_clipping = true;
|
||||||
if(is_colliding(dtime)) {
|
if(is_colliding(dtime)) {
|
||||||
printf("HIT\n");
|
if(is_clipping) {
|
||||||
|
player_hp -= (dtime)*clip_dps;
|
||||||
|
}
|
||||||
|
//printf("HIT\n");
|
||||||
//printf("[%lf, %lf, %lf]\n{%lf, %lf, %lf}\n\n", fx, fy, fz, camvx, camvy, camvz);
|
//printf("[%lf, %lf, %lf]\n{%lf, %lf, %lf}\n\n", fx, fy, fz, camvx, camvy, camvz);
|
||||||
}
|
}
|
||||||
camx -= delx;
|
camx -= delx;
|
||||||
|
@ -255,9 +279,15 @@ void movePlayerG(float dtime) {
|
||||||
camvy += fy*dtime;
|
camvy += fy*dtime;
|
||||||
camvz += fz*dtime;
|
camvz += fz*dtime;
|
||||||
//printf("%lf | %lf | %lf\n\n", camvx, camvy, camvz);
|
//printf("%lf | %lf | %lf\n\n", camvx, camvy, camvz);
|
||||||
|
if(isfalling && camvy > 0.0) {
|
||||||
|
njumps = 3;
|
||||||
|
}
|
||||||
camx += camvx*dtime;
|
camx += camvx*dtime;
|
||||||
camy += camvy*dtime;
|
camy += camvy*dtime;
|
||||||
camz += camvz*dtime;
|
camz += camvz*dtime;
|
||||||
|
|
||||||
|
camvx *= (1.0 - friction*((double)(dtime)));
|
||||||
|
camvz *= (1.0 - friction*((double)(dtime)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void teleport_on_edge() {
|
void teleport_on_edge() {
|
||||||
|
|
|
@ -153,4 +153,8 @@ extern double fx;
|
||||||
extern double fy;
|
extern double fy;
|
||||||
extern double fz;
|
extern double fz;
|
||||||
|
|
||||||
|
extern int njumps;
|
||||||
|
|
||||||
|
extern unsigned int fffff;
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -12,17 +12,7 @@ Teleporters :
|
||||||
[4.0, 1.0, 9.0, 2.0, 4.0, 1.0, 0.0, 0.0, 0, 255, 0; 0, 1]
|
[4.0, 1.0, 9.0, 2.0, 4.0, 1.0, 0.0, 0.0, 0, 255, 0; 0, 1]
|
||||||
[9.0, 1.0, 4.0, 1.0, 4.0, 2.0, 0.0, 0.0, 0, 0, 255; 1, 0]
|
[9.0, 1.0, 4.0, 1.0, 4.0, 2.0, 0.0, 0.0, 0, 0, 255; 1, 0]
|
||||||
|
|
||||||
Entities:
|
|
||||||
[0.0, 14.0, 0.0, 2.0, 1.0, 2.0, 0.0, 0.0, 193, 192, 0, 1, 0, 4, 0.0, 5.0, 0.0, 4, 1, 45]
|
|
||||||
|
|
||||||
Weight :
|
Weight :
|
||||||
50
|
50
|
||||||
|
|
||||||
$
|
$
|
||||||
entities:
|
|
||||||
[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..]
|
|
||||||
|
|
||||||
if entityType = 4
|
|
||||||
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd]
|
|
||||||
else
|
|
||||||
[..]
|
|
|
@ -24,11 +24,4 @@ Entities :
|
||||||
Weight :
|
Weight :
|
||||||
50
|
50
|
||||||
|
|
||||||
$
|
$
|
||||||
entities:
|
|
||||||
[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..]
|
|
||||||
|
|
||||||
if entityType = 4
|
|
||||||
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd]
|
|
||||||
else
|
|
||||||
[..]
|
|
|
@ -22,11 +22,4 @@ Entities :
|
||||||
Weight :
|
Weight :
|
||||||
50
|
50
|
||||||
|
|
||||||
$
|
$
|
||||||
entities:
|
|
||||||
[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..]
|
|
||||||
|
|
||||||
if entityType = 4
|
|
||||||
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd]
|
|
||||||
else
|
|
||||||
[..]
|
|
|
@ -13,11 +13,4 @@ Teleporters :
|
||||||
Weight :
|
Weight :
|
||||||
50
|
50
|
||||||
|
|
||||||
$
|
$
|
||||||
entities:
|
|
||||||
[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..]
|
|
||||||
|
|
||||||
if entityType = 4
|
|
||||||
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd]
|
|
||||||
else
|
|
||||||
[..]
|
|
|
@ -15,11 +15,4 @@ Entities :
|
||||||
Weight :
|
Weight :
|
||||||
50
|
50
|
||||||
|
|
||||||
$
|
$
|
||||||
entities:
|
|
||||||
[x, y, z, w, h, d, rhz, rvt, red, green, blue, hp, damage, entityType ..]
|
|
||||||
|
|
||||||
if entityType = 4
|
|
||||||
[.. amplitude_x, amplitude_y, amplitude_z, mult, divd]
|
|
||||||
else
|
|
||||||
[..]
|
|
Loading…
Reference in New Issue