Time to really fly
This commit is contained in:
parent
e2c82a5bcd
commit
98ed7634d4
6
bullet.c
6
bullet.c
@ -14,7 +14,7 @@
|
|||||||
#include "bullet.h"
|
#include "bullet.h"
|
||||||
#include "entity.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));
|
Entity *e = malloc(sizeof(Entity));
|
||||||
e->name = "Bullet";
|
e->name = "Bullet";
|
||||||
e->properties = malloc(sizeof(Entity));
|
e->properties = malloc(sizeof(Entity));
|
||||||
@ -25,7 +25,7 @@ Entity *spawn_bullet(Vector2 spawn_at, bool from_enemy) {
|
|||||||
props->position.width = 4;
|
props->position.width = 4;
|
||||||
props->position.height = 10;
|
props->position.height = 10;
|
||||||
props->velocity.x = 0;
|
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;
|
props->from_enemy = from_enemy;
|
||||||
e->draw = &draw_bullet;
|
e->draw = &draw_bullet;
|
||||||
e->tick = &tick_bullet;
|
e->tick = &tick_bullet;
|
||||||
@ -35,7 +35,7 @@ Entity *spawn_bullet(Vector2 spawn_at, bool from_enemy) {
|
|||||||
|
|
||||||
void draw_bullet(Entity *e) {
|
void draw_bullet(Entity *e) {
|
||||||
BulletProperties *props = e->properties;
|
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) {
|
void tick_bullet(Game *g, Entity *e, float dt) {
|
||||||
|
2
bullet.h
2
bullet.h
@ -20,7 +20,7 @@ typedef struct BulletProperties {
|
|||||||
bool from_enemy;
|
bool from_enemy;
|
||||||
} BulletProperties;
|
} 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 draw_bullet(Entity *e);
|
||||||
void tick_bullet(Game *g, Entity *e, float dt);
|
void tick_bullet(Game *g, Entity *e, float dt);
|
||||||
void free_bullet(Entity *e);
|
void free_bullet(Entity *e);
|
||||||
|
2
enemy.c
2
enemy.c
@ -62,7 +62,7 @@ void tick_enemy(Game *g, Entity *e, float dt) {
|
|||||||
if (props->bullet_timer < 0.) {
|
if (props->bullet_timer < 0.) {
|
||||||
props->bullet_timer = (float)(rand() % 4);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
game.c
2
game.c
@ -70,7 +70,7 @@ void handle_input(Game *g) {
|
|||||||
add_entity(g->enemies, spawn_enemy());
|
add_entity(g->enemies, spawn_enemy());
|
||||||
}
|
}
|
||||||
if (IsKeyPressed(KEY_SPACE)) {
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
level.c
6
level.c
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
void init_level(Game *g, Level *l) {
|
void init_level(Game *g, Level *l) {
|
||||||
l->width = 50;
|
l->width = 50;
|
||||||
l->length = 30;
|
l->length = 300;
|
||||||
l->data_size = l->width * l->length;
|
l->data_size = l->width * l->length;
|
||||||
l->data = malloc(l->data_size * sizeof(char));
|
l->data = malloc(l->data_size * sizeof(char));
|
||||||
for (int i = 0; i < l->data_size; i++) {
|
for (int i = 0; i < l->data_size; i++) {
|
||||||
//l->data[i] = 3;
|
l->data[i] = rand() % 3;
|
||||||
}
|
}
|
||||||
l->game = g;
|
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 index = x + (y * l->width);
|
||||||
size_t data = l->data[index] & 3;
|
size_t data = l->data[index] & 3;
|
||||||
Color c = COLORS[data];
|
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) {
|
void draw_level(Level *l) {
|
||||||
|
6
player.c
6
player.c
@ -46,9 +46,9 @@ void move_player(Player *p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (p->pitch) {
|
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_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;
|
p->velocity.x += p->acceleration.x;
|
||||||
@ -56,7 +56,7 @@ void move_player(Player *p) {
|
|||||||
p->velocity.x *= DAMPING_X;
|
p->velocity.x *= DAMPING_X;
|
||||||
|
|
||||||
p->velocity.y += p->acceleration.y;
|
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.x += p->velocity.x;
|
||||||
p->position.y += p->velocity.y;
|
p->position.y += p->velocity.y;
|
||||||
|
3
player.h
3
player.h
@ -15,7 +15,8 @@
|
|||||||
#define ACCEL_X 0.7
|
#define ACCEL_X 0.7
|
||||||
#define MAX_VEL_X 5
|
#define MAX_VEL_X 5
|
||||||
#define DAMPING_X 0.85
|
#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 MAX(a, b) ((a > b) ? a : b)
|
||||||
#define MIN(a, b) ((a < b) ? a : b)
|
#define MIN(a, b) ((a < b) ? a : b)
|
||||||
|
Loading…
Reference in New Issue
Block a user