summaryrefslogtreecommitdiff
path: root/sdl3_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'sdl3_main.c')
-rw-r--r--sdl3_main.c41
1 files changed, 15 insertions, 26 deletions
diff --git a/sdl3_main.c b/sdl3_main.c
index 701dfe4..93df535 100644
--- a/sdl3_main.c
+++ b/sdl3_main.c
@@ -15,6 +15,7 @@ static bool running;
static Uint64 old_ticks, new_ticks;
static float camera_x, camera_y;
+static float camera_vx, camera_vy;
bool shot;
bool moveup, movedown, moveleft, moveright;
@@ -58,30 +59,6 @@ main()
void
render(void)
{
- {
- float plx, ply, minx, miny, maxx, maxy;
-
- plx = player->body.pos[0] - camera_x;
- ply = player->body.pos[1] - camera_y;
-
- minx = plx - 80;
- miny = ply - 80;
- maxx = plx + 80;
- maxy = ply + 80;
-
- if(minx < 0)
- camera_x += minx;
-
- if(miny < 0)
- camera_y += miny;
-
- if(maxx > 800)
- camera_x += (maxx - 800);
-
- if(maxy > 600)
- camera_y += (maxy - 600);
- }
-
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
SDL_RenderClear(renderer);
@@ -106,7 +83,10 @@ render(void)
switch (e->type) {
case EPLAYER:
- SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
+ if(e->alive)
+ SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
+ else
+ SDL_SetRenderDrawColor(renderer, 0x88, 0x00, 0x00, 0xFF);
SDL_RenderRect(renderer, &(SDL_FRect){
.x = e->body.pos[0] - ENTITY_SIZE - camera_x,
.y = e->body.pos[1] - ENTITY_SIZE - camera_y,
@@ -116,7 +96,10 @@ render(void)
break;
case EGHOST:
- SDL_SetRenderDrawColor(renderer, 0xAA, 0xAA, 0xAA, 0xFF);
+ if(e->alive)
+ SDL_SetRenderDrawColor(renderer, 0xAA, 0xAA, 0xAA, 0xFF);
+ else
+ SDL_SetRenderDrawColor(renderer, 0x88, 0x00, 0x00, 0xFF);
SDL_RenderRect(renderer, &(SDL_FRect){
.x = e->body.pos[0] - ENTITY_SIZE - camera_x,
.y = e->body.pos[1] - ENTITY_SIZE - camera_y,
@@ -143,6 +126,12 @@ update(float delta)
{
entphysics(delta);
entupdate(delta);
+
+ camera_vx = ((player->body.pos[0] - 400) - camera_x) * 2.0;
+ camera_vy = ((player->body.pos[1] - 300) - camera_y) * 2.0;
+
+ camera_x += delta * camera_vx;
+ camera_y += delta * camera_vy;
}
void