@ -1,4 +1,5 @@
@@ -1,4 +1,5 @@
# include "draw.h"
# include <SDL2/SDL_mutex.h>
Vect viewport_pos ;
int width , height ;
@ -58,13 +59,9 @@ void draw_player(SDL_Renderer * ren, int x, int y, bool red) {
@@ -58,13 +59,9 @@ void draw_player(SDL_Renderer * ren, int x, int y, bool red) {
player_rect . w = 20 ;
player_rect . h = 20 ;
if ( red ) {
SDL_SetRenderDrawColor ( ren , 255 , 0 , 0 , 255 ) ;
} else {
struct colour c = get_scene_at ( viewport_pos , level ) . colours . bg ;
struct colour c = get_scene_at ( viewport_pos , level ) . colours . bg ;
SDL_SetRenderDrawColor ( ren , c . r , c . g , c . b , 255 ) ;
}
SDL_SetRenderDrawColor ( ren , c . r , c . g , c . b , 255 ) ;
SDL_RenderDrawRect ( ren , & player_rect ) ;
SDL_RenderFillRect ( ren , & player_rect ) ;
@ -73,8 +70,8 @@ void draw_player(SDL_Renderer * ren, int x, int y, bool red) {
@@ -73,8 +70,8 @@ void draw_player(SDL_Renderer * ren, int x, int y, bool red) {
if ( ! player . physics - > strings [ i ] . attached ) {
continue ;
}
Vect B ;
B = in_view ( player . physics - > position ) ;
Vect B = { x , y } ;
B = in_view ( B ) ;
Vect E ;
E = in_view ( player . physics - > strings [ i ] . end_point ) ;
SDL_RenderDrawLine ( ren , B . x , B . y , E . x , E . y ) ;
@ -393,9 +390,17 @@ void redraw_buffer(SDL_Renderer * ren) {
@@ -393,9 +390,17 @@ void redraw_buffer(SDL_Renderer * ren) {
/*}*/
int col = 0 ;
Body lplayer ;
if ( SDL_LockMutex ( player . physics - > lock ) = = 0 ) {
lplayer = * player . physics ;
SDL_UnlockMutex ( player . physics - > lock ) ;
} else {
return ;
}
//SDL_GetMouseState(&newmousex, &newmousey);
update_viewport ( player . physics - > position . x , player . physics - > position . y ) ;
update_viewport ( l player. position . x , l player. position . y ) ;
struct environment scene = get_scene_at ( viewport_pos , level ) ;
draw_environment ( ren , & scene ) ;
@ -405,11 +410,6 @@ void redraw_buffer(SDL_Renderer * ren) {
@@ -405,11 +410,6 @@ void redraw_buffer(SDL_Renderer * ren) {
thing = world . get ( i ) ;
switch ( thing . kind ) {
case PLAYER :
draw_player ( ren , ( * thing . player ) . physics - > position . x , ( * thing . player ) . physics - > position . y , thing . player - > colliding ) ;
draw_collision_poly ( ren , thing . player - > physics ) ;
draw_forces ( ren , thing . player - > physics ) ;
continue ;
case STATIC_WALL_W :
draw_wall ( ren , thing . wall ) ;
draw_collision_poly ( ren , thing . wall - > physics ) ;
@ -438,6 +438,12 @@ void redraw_buffer(SDL_Renderer * ren) {
@@ -438,6 +438,12 @@ void redraw_buffer(SDL_Renderer * ren) {
}
}
draw_player ( ren , lplayer . position . x , lplayer . position . y ,
lplayer . colliding ) ;
draw_collision_poly ( ren , & lplayer ) ;
draw_forces ( ren , & lplayer ) ;
/*if (newmousex != mousex || newmousey != mousey) {*/ /*mousey = newmousey;*/
/*mousex = newmousex;*/
/*for (int i = 0; i < 256; i++) {*/