|
|
|
@ -21,6 +21,7 @@ GlobWorld world;
@@ -21,6 +21,7 @@ GlobWorld world;
|
|
|
|
|
player_st *glob_player; |
|
|
|
|
SDL_Renderer *debug_ren; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool in_game; |
|
|
|
|
bool game_paused = false; |
|
|
|
|
extern bool mute; |
|
|
|
@ -31,6 +32,15 @@ long level_time;
@@ -31,6 +32,15 @@ long level_time;
|
|
|
|
|
int get_floor_ceiling();
|
|
|
|
|
|
|
|
|
|
struct sg_times_list save_times_lst; |
|
|
|
|
/* object that draw.c watches */ |
|
|
|
|
struct draw_watcher draw_watch = {}; |
|
|
|
|
/* object that handles ui interactions in game.c and which draw watches */ |
|
|
|
|
struct textbox_info textboxes[1]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct ui_state gameui = {}; |
|
|
|
|
|
|
|
|
|
struct timespec last_tick; |
|
|
|
|
double time_remaining = 0; |
|
|
|
@ -56,9 +66,25 @@ void set_motor_max_velocity(Body *thing, int motorID, double max);
@@ -56,9 +66,25 @@ void set_motor_max_velocity(Body *thing, int motorID, double max);
|
|
|
|
|
void get_new_physics(Body **phys);
|
|
|
|
|
void ratcheted_winch_motor_update(Motor* motor);
|
|
|
|
|
void winch_motor_update (struct motorstruct *motor);
|
|
|
|
|
void load_level();
|
|
|
|
|
|
|
|
|
|
/* object that draw.c watches */ |
|
|
|
|
struct draw_watcher draw_watch; |
|
|
|
|
void reset_textbox(struct textbox_info *tb) { |
|
|
|
|
tb->text_input_bufpos = 0; |
|
|
|
|
memset(tb->text_input, 0, sizeof(tb->text_input)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void write_to_textbox(struct textbox_info *tb, char c) { |
|
|
|
|
if (tb->text_input_bufpos >= sizeof(tb->text_input)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
tb->text_input[tb->text_input_bufpos++] = c; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void delete_from_textbox(struct textbox_info *tb) { |
|
|
|
|
if (tb->text_input_bufpos > 0) |
|
|
|
|
tb->text_input[--tb->text_input_bufpos] = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// move the collision poly to the position of the player
|
|
|
|
|
void default_update_collision_poly(Body *body) { |
|
|
|
@ -72,6 +98,17 @@ void default_update_collision_poly(Body *body) {
@@ -72,6 +98,17 @@ void default_update_collision_poly(Body *body) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void new_level_tb_close_callback(struct textbox_info*textbox, void*callback) { |
|
|
|
|
for (int i = 0; i < textbox->text_input_bufpos; i++) { |
|
|
|
|
if (textbox->text_input[i] < '0' || textbox->text_input[i] > '9') |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int lid = atoi(textbox->text_input); |
|
|
|
|
|
|
|
|
|
gameui.goto_new_level = lid; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void level_timer_update(bool reset) { |
|
|
|
|
static int start_point = 0; |
|
|
|
@ -698,7 +735,13 @@ void destroy_physics_collection(struct physics_collection *s) {
@@ -698,7 +735,13 @@ void destroy_physics_collection(struct physics_collection *s) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void next_level() { |
|
|
|
|
|
|
|
|
|
void next_level(int lvl) { |
|
|
|
|
level = lvl; |
|
|
|
|
load_level(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void load_level() { |
|
|
|
|
SDL_LockMutex(player.physics->lock); |
|
|
|
|
Vect v; |
|
|
|
|
v.x = 0; |
|
|
|
@ -724,7 +767,6 @@ void next_level() {
@@ -724,7 +767,6 @@ void next_level() {
|
|
|
|
|
destroy_physics_collection(&world.uniques_index[ROOM_W]->room->floor); |
|
|
|
|
destroy_environment(&world.uniques_index[ROOM_W]->room->env); |
|
|
|
|
|
|
|
|
|
level += 1;; |
|
|
|
|
get_floor_ceiling(); |
|
|
|
|
draw_watch.best_time = get_best_time(); |
|
|
|
|
load_score_times("saves/times"); |
|
|
|
@ -737,6 +779,7 @@ void next_level() {
@@ -737,6 +779,7 @@ void next_level() {
|
|
|
|
|
|
|
|
|
|
quality = 100; |
|
|
|
|
level_timer_update(true); |
|
|
|
|
draw_watch.finish_level = false; |
|
|
|
|
|
|
|
|
|
viewport_pos.x = player.physics->position.x - width / 2; |
|
|
|
|
viewport_pos.y = player.physics->position.y - height / 2; |
|
|
|
@ -1604,6 +1647,8 @@ GlobWorld create_world() {
@@ -1604,6 +1647,8 @@ GlobWorld create_world() {
|
|
|
|
|
void startgame(SDL_Renderer * ren) { |
|
|
|
|
get_input_map(); |
|
|
|
|
|
|
|
|
|
textboxes[TB_LEVEL_CHOOSER].close_callback = new_level_tb_close_callback; |
|
|
|
|
|
|
|
|
|
debug_ren = ren; |
|
|
|
|
|
|
|
|
|
level = 0; |
|
|
|
@ -1685,7 +1730,6 @@ void handle_input_event(SDL_Event event) {
@@ -1685,7 +1730,6 @@ void handle_input_event(SDL_Event event) {
|
|
|
|
|
if (event.key.keysym.scancode == input_map.player_rope) { |
|
|
|
|
delete_rope(); |
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUGMODE |
|
|
|
|
if (sc == input_map.player_up || sc == input_map.player_down
|
|
|
|
|
|| sc == input_map.player_left
|
|
|
|
@ -1693,15 +1737,38 @@ void handle_input_event(SDL_Event event) {
@@ -1693,15 +1737,38 @@ void handle_input_event(SDL_Event event) {
|
|
|
|
|
set_motor_newtons(player.physics, M_PLAYER_WALK, 0, 0); |
|
|
|
|
set_motor_status(player.physics, M_PLAYER_WALK, false); |
|
|
|
|
}
|
|
|
|
|
if (event.key.keysym.scancode == SDL_SCANCODE_F10) { |
|
|
|
|
next_level(); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
if (sc == input_map.player_pull_rope) { |
|
|
|
|
stop_pull_rope(); |
|
|
|
|
}
|
|
|
|
|
// DEBUGINFO
|
|
|
|
|
if (event.key.keysym.scancode == SDL_SCANCODE_F10) { |
|
|
|
|
next_level(); |
|
|
|
|
|
|
|
|
|
if (gameui.currently_bound_textbox) { |
|
|
|
|
if (event.key.keysym.scancode == SDL_SCANCODE_BACKSPACE |
|
|
|
|
|| event.key.keysym.scancode == SDL_SCANCODE_DELETE) { |
|
|
|
|
delete_from_textbox(gameui.currently_bound_textbox); |
|
|
|
|
} else if (event.key.keysym.scancode == SDL_SCANCODE_RETURN) {
|
|
|
|
|
if (gameui.currently_bound_textbox->close_callback) { |
|
|
|
|
gameui.currently_bound_textbox->close_callback( |
|
|
|
|
gameui.currently_bound_textbox, NULL); |
|
|
|
|
} |
|
|
|
|
gameui.currently_bound_textbox = NULL; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
write_to_textbox(gameui.currently_bound_textbox,
|
|
|
|
|
(char)event.key.keysym.sym); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (sc == input_map.goto_level) { |
|
|
|
|
gameui.level_chooser = !gameui.level_chooser; |
|
|
|
|
if (gameui.level_chooser) { |
|
|
|
|
gameui.currently_bound_textbox = textboxes + TB_LEVEL_CHOOSER; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
case SDL_MOUSEBUTTONDOWN: |
|
|
|
|
add_rope(event.button.x, event.button.y); |
|
|
|
@ -1746,10 +1813,16 @@ int step(void) {
@@ -1746,10 +1813,16 @@ int step(void) {
|
|
|
|
|
game_paused = 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (gameui.goto_new_level) { |
|
|
|
|
int nevl = gameui.goto_new_level; |
|
|
|
|
gameui.goto_new_level = 0; |
|
|
|
|
return nevl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (player.physics->position.x > world.uniques_index[ROOM_W]->room |
|
|
|
|
->floor.items[world.uniques_index[ROOM_W]->room->floor.numItems - 1]->position.x) { |
|
|
|
|
return 1; |
|
|
|
|
draw_watch.finish_level = true; |
|
|
|
|
return level + 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!game_paused) { |
|
|
|
|