diff --git a/bullet.c b/bullet.c index 563a563..87efde8 100644 --- a/bullet.c +++ b/bullet.c @@ -14,7 +14,7 @@ #include "bullet.h" #include "entity.h" -Entity *spawn_bullet(Vector2 spawn_at, bool from_enemy) { +Entity *spawn_bullet(Vector2 spawn_at, Vector2 velocity, bool from_enemy) { Entity *e = malloc(sizeof(Entity)); e->name = "Bullet"; e->properties = malloc(sizeof(Entity)); @@ -25,7 +25,7 @@ Entity *spawn_bullet(Vector2 spawn_at, bool from_enemy) { props->position.width = 4; props->position.height = 10; props->velocity.x = 0; - props->velocity.y = from_enemy ? 10 : -10; + props->velocity.y = velocity.y + (from_enemy ? 10 : -10); props->from_enemy = from_enemy; e->draw = &draw_bullet; e->tick = &tick_bullet; @@ -35,7 +35,7 @@ Entity *spawn_bullet(Vector2 spawn_at, bool from_enemy) { void draw_bullet(Entity *e) { BulletProperties *props = e->properties; - DrawRectangleRec(props->position, props->from_enemy ? RED : BLACK); + DrawRectangleRec(props->position, props->from_enemy ? RED : ORANGE); } void tick_bullet(Game *g, Entity *e, float dt) { diff --git a/bullet.h b/bullet.h index e4834b9..d3b0b56 100644 --- a/bullet.h +++ b/bullet.h @@ -20,7 +20,7 @@ typedef struct BulletProperties { bool from_enemy; } BulletProperties; -Entity *spawn_bullet(Vector2 spawn_at, bool from_enemy); +Entity *spawn_bullet(Vector2 spawn_at, Vector2 velocity, bool from_enemy); void draw_bullet(Entity *e); void tick_bullet(Game *g, Entity *e, float dt); void free_bullet(Entity *e); diff --git a/enemy.c b/enemy.c index 971ecbe..f2e98af 100644 --- a/enemy.c +++ b/enemy.c @@ -62,7 +62,7 @@ void tick_enemy(Game *g, Entity *e, float dt) { if (props->bullet_timer < 0.) { props->bullet_timer = (float)(rand() % 4); - add_entity(g->bullets, spawn_bullet((Vector2) { props->position.x, props->position.y }, true)); + add_entity(g->bullets, spawn_bullet((Vector2) { props->position.x, props->position.y }, props->velocity, true)); } } diff --git a/game.c b/game.c index fed6d8e..e58377f 100644 --- a/game.c +++ b/game.c @@ -70,7 +70,7 @@ void handle_input(Game *g) { add_entity(g->enemies, spawn_enemy()); } if (IsKeyPressed(KEY_SPACE)) { - add_entity(g->bullets, spawn_bullet(g->player->position, false)); + add_entity(g->bullets, spawn_bullet(g->player->position, g->player->velocity, false)); } } diff --git a/level.c b/level.c index e938bb5..4fa9361 100644 --- a/level.c +++ b/level.c @@ -2,11 +2,11 @@ void init_level(Game *g, Level *l) { l->width = 50; - l->length = 30; + l->length = 300; 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] = rand() % 3; } l->game = g; } @@ -16,7 +16,7 @@ void draw_tile(Level *l, int x, int y) { size_t index = x + (y * l->width); size_t data = l->data[index] & 3; Color c = COLORS[data]; - DrawRectangle(x * 32, y * 32, 32, 32, c); + DrawRectangle(x * 32, -y * 32, 32, 32, c); } void draw_level(Level *l) { diff --git a/player.c b/player.c index 5cf6118..75c1933 100644 --- a/player.c +++ b/player.c @@ -46,9 +46,9 @@ void move_player(Player *p) { } switch (p->pitch) { - case PITCH_DESCENDING: p->acceleration.y = 4; break; + case PITCH_DESCENDING: p->acceleration.y = .4; break; case PITCH_NEUTRAL: p->acceleration.y = 0; break; - case PITCH_ASCENDING: p->acceleration.y = -4; break; + case PITCH_ASCENDING: p->acceleration.y = -.4; break; } p->velocity.x += p->acceleration.x; @@ -56,7 +56,7 @@ void move_player(Player *p) { p->velocity.x *= DAMPING_X; p->velocity.y += p->acceleration.y; - p->velocity.y = CLAMP(p->velocity.y, MAX_VEL_Y); + p->velocity.y = MAX(MIN(p->velocity.y, -MIN_VEL_Y), -MAX_VEL_Y); p->position.x += p->velocity.x; p->position.y += p->velocity.y; diff --git a/player.h b/player.h index 36d91d5..ee7bed9 100644 --- a/player.h +++ b/player.h @@ -15,7 +15,8 @@ #define ACCEL_X 0.7 #define MAX_VEL_X 5 #define DAMPING_X 0.85 -#define MAX_VEL_Y 2 +#define MAX_VEL_Y 20 +#define MIN_VEL_Y 1 #define MAX(a, b) ((a > b) ? a : b) #define MIN(a, b) ((a < b) ? a : b)