changed polling for math + added mathBlock
This commit is contained in:
parent
92159059dc
commit
c46555e108
|
@ -75,4 +75,10 @@ entities:
|
|||
[.. freq, defaultState] with
|
||||
freq = int[0 - 15]
|
||||
defaultState = {0, 1}
|
||||
|
||||
-> 13 (math block)
|
||||
[.. defaultState, timeOff] with
|
||||
defaultState = {0, 1}
|
||||
dtime = double([>0.0] for time-limited press, or use -1.0 if no deactivation)
|
||||
|
||||
```
|
|
@ -0,0 +1,20 @@
|
|||
100.0 0.0 0.0 0.0
|
||||
95.0 5.0 0.0 0.0
|
||||
87.0 13.0 0.0 0.0
|
||||
80.0 20.0 0.0 0.0
|
||||
72.0 28.0 0.0 0.0
|
||||
70.0 25.0 5.0 0.0
|
||||
70.0 18.0 12.0 0.0
|
||||
65.0 20.0 15.0 0.0
|
||||
65.0 16.0 19.0 0.0
|
||||
60.0 18.0 22.0 0.0
|
||||
95.0 0.0 0.0 5.0
|
||||
90.0 5.0 0.0 5.0
|
||||
83.0 12.0 0.0 5.0
|
||||
72.0 18.0 0.0 10.0
|
||||
69.0 21.0 0.0 10.0
|
||||
64.0 21.0 5.0 10.0
|
||||
61.0 16.0 10.0 13.0
|
||||
55.0 18.0 14.0 13.0
|
||||
56.0 12.0 16.0 16.0
|
||||
50.0 14.0 17.0 19.0
|
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/entities.o
BIN
obj/entities.o
Binary file not shown.
BIN
obj/generation.o
BIN
obj/generation.o
Binary file not shown.
BIN
obj/maeth.o
BIN
obj/maeth.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.
66
src/base.c
66
src/base.c
|
@ -428,4 +428,70 @@ void add_entity(entity** arr, int* memlen, int* len, entity* ent) {
|
|||
free(arr[*len]);
|
||||
arr[*len] = ent;
|
||||
*len += 1;
|
||||
}
|
||||
|
||||
int is_neg0 = 1;
|
||||
int read_int(FILE* ptr) {
|
||||
bool is_reading = false;
|
||||
int buffer = 0;
|
||||
int sign = 1;
|
||||
char c = fgetc(ptr);
|
||||
while(c != EOF) {
|
||||
if(c == '-') {
|
||||
sign = -1;
|
||||
} else if((int)c >= 48 && (int)c <= 57) {
|
||||
is_reading = true;
|
||||
buffer = 10*buffer + (int)c - 48;
|
||||
} else if(is_reading) {
|
||||
if(sign == -1 && buffer == 0) {
|
||||
is_neg0 = -1;
|
||||
} else {
|
||||
is_neg0 = 1;
|
||||
}
|
||||
return buffer*sign;
|
||||
}
|
||||
c = fgetc(ptr);
|
||||
}
|
||||
if(sign == -1 && buffer == 0) {
|
||||
is_neg0 = -1;
|
||||
} else {
|
||||
is_neg0 = 1;
|
||||
}
|
||||
return buffer*sign;
|
||||
}
|
||||
|
||||
char* read_string(FILE* ptr) {
|
||||
char* res0 = malloc(sizeof(char)*52);
|
||||
char c = fgetc(ptr);
|
||||
int i = 0;
|
||||
while(c != EOF && c == ' ') { // ignore initial spaces
|
||||
c = fgetc(ptr);
|
||||
}
|
||||
while(c != EOF && c != ',') {
|
||||
res0[i] = c;
|
||||
i += 1;
|
||||
c = fgetc(ptr);
|
||||
}
|
||||
res0[i] = '\0';
|
||||
return res0;
|
||||
}
|
||||
|
||||
double sign(double __x) {
|
||||
if(__x >= 0.0) {
|
||||
return 1.0;
|
||||
}
|
||||
return -1.0;
|
||||
}
|
||||
|
||||
double read_float(FILE* ptr) {
|
||||
int ent = read_int(ptr);
|
||||
int sn0 = is_neg0;
|
||||
int frac = read_int(ptr);
|
||||
//printf("%d.%d; ", ent, frac);
|
||||
if(ent != 0.0) {
|
||||
return sn0*(ent/abs(ent))*(absf((double)ent) + ((double)frac)/(pow(10.0, (double)ln_baseN(frac, 10))));
|
||||
} else {
|
||||
//printf("%d, %d\n", ent, frac);
|
||||
return sn0*((double)frac)/(pow(10.0, (double)ln_baseN(frac, 10)));
|
||||
}
|
||||
}
|
|
@ -24,10 +24,10 @@ int to_int(double n);
|
|||
int line_count(char* filename);
|
||||
int str_to_int(char* s);
|
||||
bool str_equal(char* s1, char* s2);
|
||||
bool pt_equal_3D(pt_2d p1, pt_2d p2);
|
||||
bool pt_equal_2D(pt_2d p1, pt_2d p2);
|
||||
bool pt_equal_3D_eps(pt_2d p1, pt_2d p2, double epsilon);
|
||||
bool pt_equal_2D_eps(pt_2d p1, pt_2d p2, double epsilon, bool debug0);
|
||||
|
||||
int read_int(FILE* ptr);
|
||||
double read_float(FILE* ptr);
|
||||
char* read_string(FILE* ptr);
|
||||
|
||||
pt_2d vect_diff(pt_2d p1, pt_2d p2);
|
||||
double dot2D(pt_2d p1, pt_2d p2);
|
||||
|
|
|
@ -182,6 +182,10 @@ bool is_button_block_on(entity* ent) {
|
|||
);
|
||||
}
|
||||
|
||||
bool is_math_block_unsolved(entity* ent) {
|
||||
return (ent->entity_type != 13 || ent->metad1 == 0.0);
|
||||
}
|
||||
|
||||
void gl_renderAll(room* rtd, double offx, double offy, double offz) {
|
||||
//printf("------------------------\n");
|
||||
if(rtd != NULL) {
|
||||
|
@ -200,7 +204,7 @@ void gl_renderAll(room* rtd, double offx, double offy, double offz) {
|
|||
}
|
||||
for(int k = 0; k < rtd->ent_len; k++) {
|
||||
if(is_visible(rtd->ents[k]->pos, offx, offy, offz)) {
|
||||
if(is_button_block_on(rtd->ents[k]) && (rtd->ents[k]->entity_type != 9 || rtd->ents[k]->metai1)) {
|
||||
if(is_math_block_unsolved(rtd->ents[k]) && is_button_block_on(rtd->ents[k]) && (rtd->ents[k]->entity_type != 9 || rtd->ents[k]->metai1)) {
|
||||
glBindTexture(GL_TEXTURE_2D, textures[rtd->ents[k]->tex]);
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, textures[rtd->ents[k]->tex2]);
|
||||
|
|
|
@ -175,8 +175,24 @@ void spinning_platform(double x, double y, double z, double w, double h, double
|
|||
ret->vt_angle += ent->metad2*dtime;
|
||||
}
|
||||
|
||||
// metai1 = default state
|
||||
// metad1 = remaining time
|
||||
// metad2 = activation time
|
||||
void math_block(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret) {
|
||||
if(ent->metad1 > -0.9) {
|
||||
ent->metad1 = maxd(ent->metad1 - (double)dtime, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
void active_math(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {
|
||||
if(ent->metad1 == 0.0) {
|
||||
mathSignal = true;
|
||||
ent->metad1 = ent->metad2;
|
||||
}
|
||||
}
|
||||
|
||||
void spinning_translate(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {
|
||||
|
||||
// ye
|
||||
}
|
||||
|
||||
// metai1 = button freq (same for blocks)
|
||||
|
|
|
@ -19,7 +19,9 @@ void go_to_player(double x, double y, double z, double w, double h, double d, do
|
|||
void subtitle_text_box(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret);
|
||||
void beating_block(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret);
|
||||
void spinning_platform(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret);
|
||||
void math_block(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret) ;
|
||||
|
||||
void active_math(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret);
|
||||
void update_button(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret);
|
||||
void spinning_translate(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret);
|
||||
void detectHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret);
|
||||
|
|
|
@ -145,6 +145,14 @@ void init_ent_generator(int n) {
|
|||
hashtbl_entities[12].updatePos = NULL;
|
||||
hashtbl_entities[12].onHit = NULL;
|
||||
hashtbl_entities[12].onDeath = NULL;
|
||||
|
||||
hashtbl_entities[13].id = 13;
|
||||
hashtbl_entities[13].tex = 7;
|
||||
hashtbl_entities[13].tex2 = 9;
|
||||
hashtbl_entities[13].name = "mathBlock";
|
||||
hashtbl_entities[13].updatePos = &math_block;
|
||||
hashtbl_entities[13].onHit = &active_math;
|
||||
hashtbl_entities[13].onDeath = NULL;
|
||||
}
|
||||
|
||||
fct_entry* get_entry(int k0) {
|
||||
|
@ -322,72 +330,6 @@ void align_to(FILE* ptr, char ch) {
|
|||
}
|
||||
}
|
||||
|
||||
int is_neg0 = 1;
|
||||
int read_int(FILE* ptr) {
|
||||
bool is_reading = false;
|
||||
int buffer = 0;
|
||||
int sign = 1;
|
||||
char c = fgetc(ptr);
|
||||
while(c != EOF) {
|
||||
if(c == '-') {
|
||||
sign = -1;
|
||||
} else if((int)c >= 48 && (int)c <= 57) {
|
||||
is_reading = true;
|
||||
buffer = 10*buffer + (int)c - 48;
|
||||
} else if(is_reading) {
|
||||
if(sign == -1 && buffer == 0) {
|
||||
is_neg0 = -1;
|
||||
} else {
|
||||
is_neg0 = 1;
|
||||
}
|
||||
return buffer*sign;
|
||||
}
|
||||
c = fgetc(ptr);
|
||||
}
|
||||
if(sign == -1 && buffer == 0) {
|
||||
is_neg0 = -1;
|
||||
} else {
|
||||
is_neg0 = 1;
|
||||
}
|
||||
return buffer*sign;
|
||||
}
|
||||
|
||||
char* read_string(FILE* ptr) {
|
||||
char* res0 = malloc(sizeof(char)*52);
|
||||
char c = fgetc(ptr);
|
||||
int i = 0;
|
||||
while(c != EOF && c == ' ') { // ignore initial spaces
|
||||
c = fgetc(ptr);
|
||||
}
|
||||
while(c != EOF && c != ',') {
|
||||
res0[i] = c;
|
||||
i += 1;
|
||||
c = fgetc(ptr);
|
||||
}
|
||||
res0[i] = '\0';
|
||||
return res0;
|
||||
}
|
||||
|
||||
double sign(double __x) {
|
||||
if(__x >= 0.0) {
|
||||
return 1.0;
|
||||
}
|
||||
return -1.0;
|
||||
}
|
||||
|
||||
double read_float(FILE* ptr) {
|
||||
int ent = read_int(ptr);
|
||||
int sn0 = is_neg0;
|
||||
int frac = read_int(ptr);
|
||||
//printf("%d.%d; ", ent, frac);
|
||||
if(ent != 0.0) {
|
||||
return sn0*(ent/abs(ent))*(absf((double)ent) + ((double)frac)/(pow(10.0, (double)ln_baseN(frac, 10))));
|
||||
} else {
|
||||
//printf("%d, %d\n", ent, frac);
|
||||
return sn0*((double)frac)/(pow(10.0, (double)ln_baseN(frac, 10)));
|
||||
}
|
||||
}
|
||||
|
||||
void parse_one_room(int id, char* filename) {
|
||||
//printf(" parsing %s...", filename);
|
||||
FILE* ptr = fopen(filename, "r");
|
||||
|
@ -670,6 +612,13 @@ void parse_one_room(int id, char* filename) {
|
|||
|
||||
pool[id].area->ents[k]->metai1 = freq;
|
||||
pool[id].area->ents[k]->metai2 = offstate;
|
||||
} else if(entry->id == 13) {
|
||||
int defaultState = read_int(ptr);
|
||||
double activeTime = read_float(ptr);
|
||||
|
||||
pool[id].area->ents[k]->metai1 = defaultState;
|
||||
pool[id].area->ents[k]->metad1 = 0.0;
|
||||
pool[id].area->ents[k]->metad2 = activeTime;
|
||||
} else {
|
||||
pool[id].area->ents[k]->metai3 = 0;
|
||||
}
|
||||
|
|
|
@ -2,18 +2,18 @@
|
|||
#define GEN_H
|
||||
|
||||
typedef struct entry {
|
||||
room* area ;
|
||||
int weight ;
|
||||
} entry ;
|
||||
room* area;
|
||||
int weight;
|
||||
} entry;
|
||||
|
||||
typedef struct fct_entry {
|
||||
int id ;
|
||||
char* name ;
|
||||
void (*updatePos)(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret) ;
|
||||
int id;
|
||||
char* name;
|
||||
void (*updatePos)(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret);
|
||||
// act as velocity function
|
||||
void (*onHit)(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) ;
|
||||
void (*onHit)(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret);
|
||||
// triggers when object is hit
|
||||
void (*onDeath)(float dtime) ;
|
||||
void (*onDeath)(float dtime);
|
||||
|
||||
// metadata //
|
||||
int metai1;
|
||||
|
@ -36,27 +36,24 @@ typedef struct fct_entry {
|
|||
|
||||
int tex;
|
||||
int tex2;
|
||||
} fct_entry ;
|
||||
} fct_entry;
|
||||
|
||||
extern int build_text_box(char* msg, int red, int green, int blue);
|
||||
extern int build_lock_box(char* msg, int red, int green, int blue);
|
||||
|
||||
void init_ent_generator(int n);
|
||||
|
||||
void copy_room(room* src, room* dest, int chx, int chy) ;
|
||||
void build_starting_chunk(int chx, int chy) ;
|
||||
void copy_room(room* src, room* dest, int chx, int chy);
|
||||
void build_starting_chunk(int chx, int chy);
|
||||
|
||||
void init_hashtbl() ;
|
||||
void init_hashtbl();
|
||||
|
||||
void get_number_blocks(int* ret_cubes, int* ret_tps, int* ret_ent, FILE* ptr) ;
|
||||
void align_to(FILE* ptr, char ch) ;
|
||||
int read_int(FILE* ptr) ;
|
||||
double read_float(FILE* ptr) ;
|
||||
char* read_string(FILE* ptr);
|
||||
void parse_one_room(int id, char* filename) ;
|
||||
void parse_rooms(int n_rooms, char* folder) ;
|
||||
void get_number_blocks(int* ret_cubes, int* ret_tps, int* ret_ent, FILE* ptr);
|
||||
void align_to(FILE* ptr, char ch);
|
||||
void parse_one_room(int id, char* filename);
|
||||
void parse_rooms(int n_rooms, char* folder);
|
||||
|
||||
void generate_nearby_chunks(int render_dist) ;
|
||||
void generate_nearby_chunks(int render_dist);
|
||||
|
||||
void free_pool();
|
||||
void free_ent_generator();
|
||||
|
|
132
src/maeth.c
132
src/maeth.c
|
@ -18,6 +18,8 @@
|
|||
#include "music.h"
|
||||
#include "maeth.h"
|
||||
|
||||
mathRes mathResult;
|
||||
|
||||
formula current_formula = NULL;
|
||||
// --------------------------------------------------------------------- //
|
||||
// between 1 and 20
|
||||
|
@ -83,15 +85,37 @@ void init_math_interfaces() {
|
|||
interface_link_button(mthInterface, mthExitSetting);
|
||||
}
|
||||
|
||||
// [diff][operation]
|
||||
float operationDistr[20][4];
|
||||
|
||||
void init_maeth() {
|
||||
mthAllow[0] = true;
|
||||
mthAllow[1] = true;
|
||||
mthAllow[2] = true;
|
||||
|
||||
mathResult = IDLE;
|
||||
|
||||
FILE* ptr = fopen("levels/math/distr.txt", "r");
|
||||
for(int p = 0; p < 20; p++) {
|
||||
for(int k = 0; k < 4/*number of operations*/; k++) {
|
||||
operationDistr[p][k] = read_float(ptr);
|
||||
printf("%f ", operationDistr[p][k]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
fclose(ptr);
|
||||
}
|
||||
|
||||
ctype get_ctype() {
|
||||
int r = rand()%3;
|
||||
return (ctype)(1+r);
|
||||
int r = rand()%100;
|
||||
double cur = 0.0;
|
||||
int i = 0;
|
||||
while(cur <= (double)r) {
|
||||
cur += operationDistr[mathDiff-1][i];
|
||||
i += 1;
|
||||
}
|
||||
return (ctype)(i);
|
||||
}
|
||||
|
||||
formula create_formula_aux(int leng) {
|
||||
|
@ -103,7 +127,7 @@ formula create_formula_aux(int leng) {
|
|||
newF->val = mthInf + rand()%(mthSup-mthInf);
|
||||
} else {
|
||||
newF->calc1 = create_formula_aux(leng/2);
|
||||
newF->calc2 = create_formula_aux(leng/2);
|
||||
newF->calc2 = create_formula_aux(leng/2+(leng%2==1));
|
||||
newF->operation = get_ctype();
|
||||
newF->val = 0; // irrelevant
|
||||
}
|
||||
|
@ -215,6 +239,7 @@ void generate_new_formula() {
|
|||
}
|
||||
|
||||
void the_actual_main_math_function(GLFWwindow* window) {
|
||||
mathResult = IN_MATH;
|
||||
generate_new_formula();
|
||||
int correct_answer = solve_formula(current_formula);
|
||||
while(correct_answer == 0) {
|
||||
|
@ -227,7 +252,10 @@ void the_actual_main_math_function(GLFWwindow* window) {
|
|||
bool solved = false;
|
||||
int player_answer = 0;
|
||||
int sign = 1;
|
||||
bool mPress = false;
|
||||
bool mPress[12];
|
||||
for(int k = 0; k < 12; k++) {
|
||||
mPress[k] = false;
|
||||
}
|
||||
float ratio = 0.0f;
|
||||
play_sound("sound/audio/kahoot_theme.wav");
|
||||
while(!solved && ratio < 1.0f) {
|
||||
|
@ -238,46 +266,64 @@ void the_actual_main_math_function(GLFWwindow* window) {
|
|||
|
||||
// ----------------------------------------------------------- //
|
||||
if(glfwGetKey(window, GLFW_KEY_0) == GLFW_PRESS) {
|
||||
if(!mPress) {player_answer = 10*player_answer ;}
|
||||
mPress = true;
|
||||
} else if(glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS) {
|
||||
if(!mPress) {player_answer = 10*player_answer+1;}
|
||||
mPress = true;
|
||||
} else if(glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS) {
|
||||
if(!mPress) {player_answer = 10*player_answer+2;}
|
||||
mPress = true;
|
||||
} else if(glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS) {
|
||||
if(!mPress) {player_answer = 10*player_answer+3;}
|
||||
mPress = true;
|
||||
} else if(glfwGetKey(window, GLFW_KEY_4) == GLFW_PRESS) {
|
||||
if(!mPress) {player_answer = 10*player_answer+4;}
|
||||
mPress = true;
|
||||
} else if(glfwGetKey(window, GLFW_KEY_5) == GLFW_PRESS) {
|
||||
if(!mPress) {player_answer = 10*player_answer+5;}
|
||||
mPress = true;
|
||||
} else if(glfwGetKey(window, GLFW_KEY_6) == GLFW_PRESS) {
|
||||
if(!mPress) {player_answer = 10*player_answer+6;}
|
||||
mPress = true;
|
||||
} else if(glfwGetKey(window, GLFW_KEY_7) == GLFW_PRESS) {
|
||||
if(!mPress) {player_answer = 10*player_answer+7;}
|
||||
mPress = true;
|
||||
} else if(glfwGetKey(window, GLFW_KEY_8) == GLFW_PRESS) {
|
||||
if(!mPress) {player_answer = 10*player_answer+8;}
|
||||
mPress = true;
|
||||
} else if(glfwGetKey(window, GLFW_KEY_9) == GLFW_PRESS) {
|
||||
if(!mPress) {player_answer = 10*player_answer+9;}
|
||||
mPress = true;
|
||||
} else
|
||||
if(!mPress[0]) {player_answer = 10*player_answer ;}
|
||||
mPress[0] = true;
|
||||
} else {mPress[0] = false;}
|
||||
|
||||
if(glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS) {
|
||||
if(!mPress[1]) {player_answer = 10*player_answer+1;}
|
||||
mPress[1] = true;
|
||||
} else {mPress[1] = false;}
|
||||
|
||||
if(glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS) {
|
||||
if(!mPress[2]) {player_answer = 10*player_answer+2;}
|
||||
mPress[2] = true;
|
||||
} else {mPress[2] = false;}
|
||||
|
||||
if(glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS) {
|
||||
if(!mPress[3]) {player_answer = 10*player_answer+3;}
|
||||
mPress[3] = true;
|
||||
} else {mPress[3] = false;}
|
||||
|
||||
if(glfwGetKey(window, GLFW_KEY_4) == GLFW_PRESS) {
|
||||
if(!mPress[4]) {player_answer = 10*player_answer+4;}
|
||||
mPress[4] = true;
|
||||
} else {mPress[4] = false;}
|
||||
|
||||
if(glfwGetKey(window, GLFW_KEY_5) == GLFW_PRESS) {
|
||||
if(!mPress[5]) {player_answer = 10*player_answer+5;}
|
||||
mPress[5] = true;
|
||||
} else {mPress[5] = false;}
|
||||
|
||||
if(glfwGetKey(window, GLFW_KEY_6) == GLFW_PRESS) {
|
||||
if(!mPress[6]) {player_answer = 10*player_answer+6;}
|
||||
mPress[6] = true;
|
||||
} else {mPress[6] = false;}
|
||||
|
||||
if(glfwGetKey(window, GLFW_KEY_7) == GLFW_PRESS) {
|
||||
if(!mPress[7]) {player_answer = 10*player_answer+7;}
|
||||
mPress[7] = true;
|
||||
} else {mPress[7] = false;}
|
||||
|
||||
if(glfwGetKey(window, GLFW_KEY_8) == GLFW_PRESS) {
|
||||
if(!mPress[8]) {player_answer = 10*player_answer+8;}
|
||||
mPress[8] = true;
|
||||
} else {mPress[8] = false;}
|
||||
|
||||
if(glfwGetKey(window, GLFW_KEY_9) == GLFW_PRESS) {
|
||||
if(!mPress[9]) {player_answer = 10*player_answer+9;}
|
||||
mPress[9] = true;
|
||||
} else {mPress[9] = false;}
|
||||
// ----------------------------------------------------------- //
|
||||
if(glfwGetKey(window, GLFW_KEY_ENTER) == GLFW_PRESS) {
|
||||
if(!mPress) {sign *= (-1);}
|
||||
mPress = true;
|
||||
} else if(glfwGetKey(window, GLFW_KEY_BACKSPACE) == GLFW_PRESS) {
|
||||
if(!mPress) {player_answer /= 10;}
|
||||
mPress = true;
|
||||
} else {
|
||||
mPress = false;
|
||||
}
|
||||
if(!mPress[10]) {sign *= (-1);}
|
||||
mPress[10] = true;
|
||||
} else {mPress[10] = false;}
|
||||
|
||||
if(glfwGetKey(window, GLFW_KEY_BACKSPACE) == GLFW_PRESS) {
|
||||
if(!mPress[11]) {player_answer /= 10;}
|
||||
mPress[11] = true;
|
||||
} else {mPress[11] = false;}
|
||||
// ----------------------------------------------------------- //
|
||||
if(glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) {
|
||||
player_answer = correct_answer;
|
||||
|
@ -306,7 +352,9 @@ void the_actual_main_math_function(GLFWwindow* window) {
|
|||
reset_music();
|
||||
if(solved) {
|
||||
player_hp += 100;
|
||||
mathResult = SUCCESS;
|
||||
} else {
|
||||
player_hp -= mathDmg*mathDoDmg;
|
||||
mathResult = FAILURE;
|
||||
}
|
||||
}
|
26
src/main.c
26
src/main.c
|
@ -45,11 +45,9 @@ unsigned int textures[16];
|
|||
bool paused = false;
|
||||
bool hardReset = true;
|
||||
|
||||
bool math_test = true;
|
||||
int math_test_cd = 10;
|
||||
|
||||
double oldx, oldy, oldz;
|
||||
int oldchx, oldchy;
|
||||
|
||||
void reset_everything(GLFWwindow *window, int count, char* folder) {
|
||||
oldx = camx;
|
||||
oldy = camy;
|
||||
|
@ -613,6 +611,8 @@ int main_alt() {
|
|||
glUseProgram(shaderProgram);
|
||||
glUniform1i(loc_tex, 0);
|
||||
|
||||
mathSignal = true;
|
||||
|
||||
while(!glfwWindowShouldClose(window) && player_hp > 0) {
|
||||
// input
|
||||
// -----
|
||||
|
@ -651,10 +651,7 @@ int main_alt() {
|
|||
gl_drawButtonTimers(shaderProgramR);
|
||||
|
||||
bool isinmenu = isInMenu(window, shaderProgramR);
|
||||
if(!isinmenu) {
|
||||
math_test_cd = max(math_test_cd-1, 0);
|
||||
}
|
||||
if(!isinmenu && !math_test) {
|
||||
if(!isinmenu && !mathSignal) {
|
||||
processInput(window, delta);
|
||||
if(!paused) {
|
||||
if(gamemode == 0) {
|
||||
|
@ -670,11 +667,16 @@ int main_alt() {
|
|||
gl_drawString(shaderProgramR, "press u to resume", 0.0f, -0.1f, 0.08f, 128, 128, 255, 0.005f, 0);
|
||||
}
|
||||
}
|
||||
if(math_test_cd == 0 && math_test) {
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
the_actual_main_math_function(window);
|
||||
math_test = false;
|
||||
|
||||
if(!isinmenu && mathSignal) {
|
||||
mathSigCD -= 1;
|
||||
if(mathSigCD == 0) {
|
||||
mathSigCD = 4;
|
||||
mathSignal = false;
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
the_actual_main_math_function(window);
|
||||
}
|
||||
}
|
||||
|
||||
finish = clock();
|
||||
|
|
16
src/move.c
16
src/move.c
|
@ -69,6 +69,9 @@ bool buttonSwitch[16];
|
|||
float buttonTimes[16];
|
||||
float buttonMaxT[16];
|
||||
|
||||
bool mathSignal;
|
||||
int mathSigCD;
|
||||
|
||||
void init_csts() {
|
||||
camx = 2.0;
|
||||
camy = 5.0;
|
||||
|
@ -91,6 +94,9 @@ void init_csts() {
|
|||
draw_type = 0;
|
||||
fade_dmg = 0;
|
||||
|
||||
mathSignal = false;
|
||||
mathSigCD = 4;
|
||||
|
||||
for(int k = 0; k < 16; k++) {
|
||||
buttonTimes[k] = 0.0f;
|
||||
buttonSwitch[k] = false;
|
||||
|
@ -275,7 +281,8 @@ bool is_colliding(float dtime) {
|
|||
//printf("%d -> %d\n", k, vstd->ents[k]->entity_type);
|
||||
if(
|
||||
(vstd->ents[k]->entity_type != 12 || xor(buttonSwitch[vstd->ents[k]->metai1], vstd->ents[k]->metai2)) &&
|
||||
(vstd->ents[k]->entity_type != 9 || vstd->ents[k]->metai1)
|
||||
(vstd->ents[k]->entity_type != 9 || vstd->ents[k]->metai1) &&
|
||||
(vstd->ents[k]->entity_type != 13 || (vstd->ents[k]->metad1 == 0.0 || vstd->ents[k]->metai1 == 0))
|
||||
) {
|
||||
double dist = distance_pt_cube_0_3d_infinite(camx-2*room_width*w, camy, camz-2*room_depth*h, vstd->ents[k]->pos);
|
||||
//printf("%lf vs %lf\n", dist, min_dist);
|
||||
|
@ -299,7 +306,12 @@ bool is_colliding(float dtime) {
|
|||
if(exists && updateForces && vstd->ents[k]->entity_type != 0) {
|
||||
updateF(vstd->ents[k]->pos, (double)dtime);
|
||||
}
|
||||
if(exists && (vstd->ents[k]->entity_type == 9 || vstd->ents[k]->entity_type == 4 || vstd->ents[k]->entity_type == 5)) {
|
||||
if(exists && (
|
||||
vstd->ents[k]->entity_type == 13 ||
|
||||
vstd->ents[k]->entity_type == 9 ||
|
||||
vstd->ents[k]->entity_type == 4 ||
|
||||
vstd->ents[k]->entity_type == 5
|
||||
)) {
|
||||
is_clipping = false;
|
||||
}
|
||||
globalCollision = true;
|
||||
|
|
|
@ -100,6 +100,8 @@ struct hashtbl_0 {
|
|||
typedef struct hashtbl_0 hashtbl_0;
|
||||
typedef hashtbl_0* hashtbl;
|
||||
|
||||
typedef enum mathRes {IDLE, IN_MATH, SUCCESS, FAILURE} mathRes;
|
||||
|
||||
// ------------------------------------------------ //
|
||||
|
||||
extern double sim_time;
|
||||
|
@ -198,4 +200,8 @@ extern int mthInterface;
|
|||
extern int welcome_start_i;
|
||||
extern int settings_i;
|
||||
|
||||
extern bool mathSignal;
|
||||
extern int mathSigCD;
|
||||
extern mathRes mathResult;
|
||||
|
||||
#endif
|
|
@ -1,5 +1,5 @@
|
|||
Blocks :
|
||||
[0.0, 0.0, 0.0, 10.0, 1.0, 10.0, 0.0, 0.0, 255, 255, 255]
|
||||
[-5.0, 0.0, -5.0, 15.0, 1.0, 15.0, 0.0, 0.0, 255, 255, 255]
|
||||
[0.0, 9.0, 0.0, 10.0, 1.0, 10.0, 0.0, 0.0, 255, 255, 255]
|
||||
[0.0, 1.0, 0.0, 1.0, 8.0, 1.0, 0.0, 0.0, 128, 128, 128]
|
||||
[9.0, 1.0, 0.0, 1.0, 8.0, 1.0, 0.0, 0.0, 128, 128, 128]
|
||||
|
@ -16,6 +16,7 @@ Entities :
|
|||
[-1.0, 13.0, -1.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 255, 255, 1, 0, 9, 1.5, 1.5, 0]
|
||||
[-1.0, 16.0, -1.0, 2.0, 1.0, 2.0, 0.0, 0.0, 128, 128, 128, 1, 0, 11, 4, 1.75]
|
||||
[-1.0, 19.0, -1.0, 2.0, 1.0, 2.0, 0.0, 0.0, 128, 128, 128, 1, 0, 12, 4, 1]
|
||||
[-5.0, 1.0 , -5.0, 1.0, 1.0, 1.0, 0.0, 0.0, 222, 222, 222, 1, 0, 13, 1, 1.0]
|
||||
|
||||
Weight :
|
||||
50
|
||||
|
|
Loading…
Reference in New Issue