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

Add basic projectile

parent 07886302
......@@ -10,4 +10,5 @@ target_sources(${PROJECT_NAME}
game.c
position.h
alien.h
projectile.h
)
#include "projectile.h"
#include "raylib.h"
#include <stddef.h>
#include <stdlib.h>
#include <stdbool.h>
extern const int GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT, FRAME_RATE;
Projectile *playerProj;
Rectangle laserCanon;
Rectangle gameBorder;
Vector2 laserCanonPos;
......@@ -30,18 +35,29 @@ void calcGame() {
laserCanonPos.x += laserCanonSize;
}
}
// Space for shooting or something
if (IsKeyPressed(KEY_SPACE)) {
// todo
if (!playerProj) {
spawnPlayerProjectile();
}
}
// Update position of laserCanon
laserCanon = (Rectangle) {(float) laserCanonPos.x, (float) laserCanonPos.y, (float) laserCanonSize, (float) laserCanonSize};
laserCanon = (Rectangle) {(float) laserCanonPos.x, (float) laserCanonPos.y, (float) laserCanonSize, (float) laserCanonSize};
}
void drawGame() {
ClearBackground(BLACK);
DrawRectangleRec(laserCanon, WHITE);
DrawRectangleLines((int) gameBorder.x, (int) gameBorder.y, (int) gameBorder.width, (int) gameBorder.height, WHITE);
}
\ No newline at end of file
if (playerProj) {
DrawRectangleRec((Rectangle) { playerProj->pos.x, playerProj->pos.y, 5, 10 }, WHITE);
}
}
void spawnPlayerProjectile() {
playerProj = malloc(sizeof *playerProj);
playerProj->movingUp = true;
playerProj->pos = (Vector2) { laserCanonPos.x, laserCanonPos.y };
}
......@@ -3,3 +3,5 @@
void initGame();
void drawGame();
void calcGame();
void spawnPlayerProjectile();
#pragma once
#include <raylib.h>
#include <stdbool.h>
#define PROJECTILE_SPEED 5
typedef struct {
bool movingUp;
Vector2 pos;
} Projectile;
void projectileTick(Projectile *proj) {
proj->pos.y += (proj->movingUp ? -1 : 1) * PROJECTILE_SPEED;
}
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