Commit 0944f988 authored by Valentin Bartschies's avatar Valentin Bartschies
Browse files

Add game.c with very basic functionality

parent 1c8f87f8
#include "raylib.h"
#include <stddef.h>
extern const int GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT, FRAME_RATE;
Rectangle laserCanon;
Rectangle gameBorder;
Vector2 laserCanonPos;
int laserCanonSize;
void initGame() {
laserCanonSize = GAME_SCREEN_WIDTH / 20;
laserCanonPos = (Vector2) {GAME_SCREEN_WIDTH / 2, GAME_SCREEN_HEIGHT - (laserCanonSize * 2)};
laserCanon = (Rectangle) {laserCanonPos.x, laserCanonPos.y, laserCanonSize, laserCanonSize};
gameBorder = (Rectangle) {0, 0, GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT};
}
void calcGame() {
int key = GetKeyPressed();
// Control the laserCanon with left- and rightarrow
if (IsKeyPressed(KEY_LEFT)) {
if (laserCanonPos.x > 0) {
laserCanonPos.x -= laserCanonSize;
}
} else if (IsKeyPressed(KEY_RIGHT)) {
if (laserCanonPos.x < GAME_SCREEN_WIDTH - laserCanonSize) {
laserCanonPos.x += laserCanonSize;
}
}
// Space for shooting or something
if (IsKeyPressed(KEY_SPACE)) {
// todo
}
// Update position of laserCanon
laserCanon = (Rectangle) {laserCanonPos.x, laserCanonPos.y, laserCanonSize, laserCanonSize};
}
void drawGame() {
ClearBackground(BLACK);
DrawRectangleRec(laserCanon, WHITE);
DrawRectangleLines(gameBorder.x, gameBorder.y, gameBorder.width, gameBorder.height, WHITE);
}
\ No newline at end of file
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