diff --git a/game.c b/game.c index 7d3e8dc..fed6d8e 100644 --- a/game.c +++ b/game.c @@ -24,7 +24,7 @@ void initialize_game(Game *g) { g->should_close = false; g->player = malloc(sizeof(Player)); - initialize_player(g->player); + initialize_player(g, g->player); g->enemies = malloc(sizeof(Entities)); g->enemies->entities = malloc(10 * sizeof(Entity*)); g->enemies->count = 0; @@ -34,6 +34,10 @@ void initialize_game(Game *g) { g->bullets->count = 0; g->bullets->capacity = 10; + g->camera = malloc(sizeof(Camera)); + g->camera->zoom = 1.; + g->camera->rotation = 0.; + g->level = malloc(sizeof(Level)); init_level(g, g->level); } @@ -116,6 +120,7 @@ void run_frame(Game *g) { void draw_frame(Game *g) { BeginDrawing(); ClearBackground(RAYWHITE); + BeginMode2D(*g->camera); draw_level(g->level); draw_player(g->player); FOREACH_ENEMY { @@ -126,6 +131,7 @@ void draw_frame(Game *g) { INIT_BULLET; e->draw(e); } + EndMode2D(); EndDrawing(); } diff --git a/game.h b/game.h index 6f3bbba..6f23e72 100644 --- a/game.h +++ b/game.h @@ -23,6 +23,7 @@ struct Game { Entities *enemies; Entities *bullets; Level *level; + Camera2D *camera; /* Levels levels; */ diff --git a/level.c b/level.c index 9489c66..e938bb5 100644 --- a/level.c +++ b/level.c @@ -6,7 +6,7 @@ void init_level(Game *g, Level *l) { l->data_size = l->width * l->length; l->data = malloc(l->data_size * sizeof(char)); for (int i = 0; i < l->data_size; i++) { - l->data[i] = 3; + //l->data[i] = 3; } l->game = g; } diff --git a/player.c b/player.c index 1a0440c..5cf6118 100644 --- a/player.c +++ b/player.c @@ -12,7 +12,7 @@ #include "player.h" -void initialize_player(Player *p) { +void initialize_player(Game *g, Player *p) { p->position = (Vector2) { 400, 300 }; p->velocity = (Vector2) { 0, 0 }; p->acceleration = (Vector2) { 0, 0 }; @@ -21,6 +21,7 @@ void initialize_player(Player *p) { Image sprite_img = LoadImage("img/player.png"); p->spritesheet = LoadTextureFromImage(sprite_img); UnloadImage(sprite_img); + p->game = g; } void handle_player_input(Player *p) { @@ -59,4 +60,8 @@ void move_player(Player *p) { p->position.x += p->velocity.x; p->position.y += p->velocity.y; + + p->game->camera->target = p->position; + p->game->camera->offset.x = 400; + p->game->camera->offset.y = 275; } diff --git a/player.h b/player.h index 62899dc..36d91d5 100644 --- a/player.h +++ b/player.h @@ -33,16 +33,21 @@ typedef enum PlayerRoll { ROLL_RIGHT, } PlayerRoll; -typedef struct Player { +typedef struct Player Player; + +#include "game.h" + +struct Player { Vector2 position; Vector2 velocity; Vector2 acceleration; PlayerPitch pitch; PlayerRoll roll; Texture2D spritesheet; -} Player; + Game *game; +}; -void initialize_player(Player *p); +void initialize_player(Game *g, Player *p); void handle_player_input(Player *p); void draw_player(Player *p); void move_player(Player *p);