|
|
|
@ -1,6 +1,7 @@
@@ -1,6 +1,7 @@
|
|
|
|
|
#include "draw.h" |
|
|
|
|
#include "game.h" |
|
|
|
|
#include <SDL2/SDL_mutex.h> |
|
|
|
|
#include <SDL2/SDL_render.h> |
|
|
|
|
#include <time.h> |
|
|
|
|
|
|
|
|
|
Vect viewport_pos; |
|
|
|
@ -280,7 +281,7 @@ void new_update_viewport(Body const * const pl) {
@@ -280,7 +281,7 @@ void new_update_viewport(Body const * const pl) {
|
|
|
|
|
static double dirchange = 0; |
|
|
|
|
static Vect last_plpos = {}; |
|
|
|
|
if (last_plpos.x == 0 && last_plpos.y == 0) |
|
|
|
|
last_plpos = player.physics->position; |
|
|
|
|
last_plpos = pl->position; |
|
|
|
|
|
|
|
|
|
static Vect lmove = {}; |
|
|
|
|
|
|
|
|
@ -296,15 +297,16 @@ void new_update_viewport(Body const * const pl) {
@@ -296,15 +297,16 @@ void new_update_viewport(Body const * const pl) {
|
|
|
|
|
|
|
|
|
|
Vect screen_dist = vect_add(in_view(pl->position), vect_scalar(lmove, -1)); |
|
|
|
|
|
|
|
|
|
static double swap = 0; |
|
|
|
|
if (iv.x > width
|
|
|
|
|
|| (iv.x < 0 |
|
|
|
|
|| iv.y > height |
|
|
|
|
|| iv.y < 0))
|
|
|
|
|
recover = true; |
|
|
|
|
|
|
|
|
|
Vect delta = vect_add(vect_scalar(player.physics->position, -1), last_plpos); |
|
|
|
|
Vect delta = vect_add(vect_scalar(pl->position, -1), last_plpos); |
|
|
|
|
double dist_change = vect_mag(delta); |
|
|
|
|
if (true || (recover) //|| vect_mag((Vect){pl->vel.x, 0}) > 0.4
|
|
|
|
|
if ((recover) //|| vect_mag((Vect){pl->vel.x, 0}) > 0.4
|
|
|
|
|
|| (dist_change > width / 100)) { |
|
|
|
|
if (iv.x < width / 6) { |
|
|
|
|
target = right_pos; |
|
|
|
@ -313,7 +315,7 @@ void new_update_viewport(Body const * const pl) {
@@ -313,7 +315,7 @@ void new_update_viewport(Body const * const pl) {
|
|
|
|
|
} |
|
|
|
|
lmove = target; |
|
|
|
|
|
|
|
|
|
last_plpos = player.physics->position; |
|
|
|
|
last_plpos = pl->position; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (recover) |
|
|
|
@ -352,11 +354,11 @@ void new_update_viewport(Body const * const pl) {
@@ -352,11 +354,11 @@ void new_update_viewport(Body const * const pl) {
|
|
|
|
|
v = -v; |
|
|
|
|
|
|
|
|
|
// move towards target a set proportion
|
|
|
|
|
Vect urgency = vect_add(target, vect_scalar(player.physics->position, -1)); |
|
|
|
|
Vect urgency = vect_add(target, vect_scalar(pl->position, -1)); |
|
|
|
|
Vect p = vect_add(target, vect_scalar(viewport_pos, -1)); |
|
|
|
|
|
|
|
|
|
double proportion = (sigmoid(time_delta) / 100); |
|
|
|
|
proportion = 2 * player.physics->vel.x / (width); |
|
|
|
|
proportion = 2 * (pl->vel.x * pl->vel.x / (width)); |
|
|
|
|
proportion = proportion < 0 ? -proportion : proportion; |
|
|
|
|
|
|
|
|
|
proportion > 0.4 ? proportion = 0.4 : 0; |
|
|
|
@ -496,7 +498,7 @@ void draw_text(SDL_Renderer *rend, Vect pos, struct colour colour, char *text) {
@@ -496,7 +498,7 @@ void draw_text(SDL_Renderer *rend, Vect pos, struct colour colour, char *text) {
|
|
|
|
|
static SDL_Renderer *ren = NULL; |
|
|
|
|
static TTF_Font* font = NULL; |
|
|
|
|
if (!font) { |
|
|
|
|
font = TTF_OpenFont("TerminusTTF.ttf", 18); |
|
|
|
|
font = TTF_OpenFont("TerminusTTF.ttf", 22); |
|
|
|
|
const char *err = SDL_GetError(); |
|
|
|
|
if (err) { |
|
|
|
|
printf("%s\n", err); |
|
|
|
@ -521,10 +523,45 @@ void draw_text(SDL_Renderer *rend, Vect pos, struct colour colour, char *text) {
@@ -521,10 +523,45 @@ void draw_text(SDL_Renderer *rend, Vect pos, struct colour colour, char *text) {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int draw_end_screen(SDL_Renderer *ren) { |
|
|
|
|
struct environment scene = get_scene_at(viewport_pos, level); |
|
|
|
|
|
|
|
|
|
struct colour bg = scene.colours.bg; |
|
|
|
|
struct colour colour = scene.colours.fg1; |
|
|
|
|
|
|
|
|
|
SDL_SetRenderDrawColor(ren, bg.r, bg.g, bg.b,255); |
|
|
|
|
SDL_RenderClear(ren); |
|
|
|
|
|
|
|
|
|
int margin = height / 10; |
|
|
|
|
// Vect position = {.x = width - width / 10, .y = height - margin};
|
|
|
|
|
|
|
|
|
|
int minutes = level_time / 60000; |
|
|
|
|
float seconds = level_time * 0.001; |
|
|
|
|
char time_string[250]; |
|
|
|
|
snprintf(time_string, 250, "TIME: %d:%.4f", minutes, seconds); |
|
|
|
|
char * end_str = "Level over."; |
|
|
|
|
char * ct_str = "Press any key to continue."; |
|
|
|
|
char qual_str[250]; |
|
|
|
|
snprintf(qual_str, 250, "Physics quality: %d", quality); |
|
|
|
|
|
|
|
|
|
Vect position = {.x = width/3, .y = height / 4}; |
|
|
|
|
draw_text(ren, position, colour, end_str); |
|
|
|
|
position.y += 40; |
|
|
|
|
draw_text(ren, position, colour, time_string); |
|
|
|
|
position.y += 40; |
|
|
|
|
draw_text(ren, position, colour, qual_str); |
|
|
|
|
position.y += 40; |
|
|
|
|
draw_text(ren, position, colour, ct_str); |
|
|
|
|
|
|
|
|
|
SDL_RenderPresent(ren); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void draw_level_time(SDL_Renderer *ren, struct environment * e) { |
|
|
|
|
|
|
|
|
|
int margin = height / 10; |
|
|
|
|
Vect position = {.x = margin, .y = height - margin}; |
|
|
|
|
Vect position = {.x = width - width / 10, .y = height - margin}; |
|
|
|
|
|
|
|
|
|
struct colour colour = e->colours.fg1; |
|
|
|
|
|
|
|
|
@ -558,8 +595,7 @@ void redraw_buffer(SDL_Renderer * ren) {
@@ -558,8 +595,7 @@ void redraw_buffer(SDL_Renderer * ren) {
|
|
|
|
|
|
|
|
|
|
if (SDL_LockMutex(player.physics->lock) == 0){ |
|
|
|
|
lplayer = *player.physics; |
|
|
|
|
new_update_viewport(&lplayer); |
|
|
|
|
SDL_UnlockMutex(player.physics->lock); |
|
|
|
|
update_viewport(&lplayer); |
|
|
|
|
} else { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -577,6 +613,7 @@ void redraw_buffer(SDL_Renderer * ren) {
@@ -577,6 +613,7 @@ void redraw_buffer(SDL_Renderer * ren) {
|
|
|
|
|
struct environment scene = get_scene_at(viewport_pos, level); |
|
|
|
|
draw_environment(ren, &scene); |
|
|
|
|
draw_level_time(ren, &scene); |
|
|
|
|
SDL_UnlockMutex(player.physics->lock); |
|
|
|
|
|
|
|
|
|
for (int i=0; i < world.items.size; i++) { |
|
|
|
|
world_thing thing; |
|
|
|
|