Commit b0b2af53 authored by Max Kobelt's avatar Max Kobelt
Browse files

Add movement to projectile

parent 2c877dfe
......@@ -37,10 +37,10 @@ void calcGame() {
}
}
if (IsKeyPressed(KEY_SPACE)) {
if (!playerProj) {
spawnPlayerProjectile();
}
if (playerProj) {
playerProj = projectileTick(playerProj);
} else if (IsKeyPressed(KEY_SPACE)) {
spawnPlayerProjectile();
}
// Update position of laserCanon
......
......@@ -3,16 +3,25 @@
#include <raylib.h>
#include <stdbool.h>
#include <stdlib.h>
#define PROJECTILE_SPEED 5
#define PROJECTILE_SPEED 3
#define PROJECTILE_HEIGHT 10
#define PROJECTILE_WIDTH 5
extern const int GAME_SCREEN_HEIGHT;
typedef struct {
bool movingUp;
Vector2 pos;
} Projectile;
void projectileTick(Projectile *proj) {
proj->pos.y += (proj->movingUp ? -1 : 1) * PROJECTILE_SPEED;
Projectile* projectileTick(Projectile *proj) {
int newY = proj->pos.y + (proj->movingUp ? -1 : 1) * PROJECTILE_SPEED;
if (newY < 0 || newY >= GAME_SCREEN_HEIGHT) {
free(proj);
return NULL;
}
proj->pos.y = newY;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment