Commit 3b49aadd authored by Max Kobelt's avatar Max Kobelt
Browse files
parents 0a850637 834fbda8
build/
.vscode/settings.json
# Space Intruders
## Development Setup
1. Download [CMake](https://cmake.org/)
2. At the project root, create a `build/` folder
3. In the `build/` folder, execute
```shell
cmake .. -G <YOUR_GENERATOR>
```
where `<YOUR_GENERATOR>` is one of the generators shown by invoking
```shell
cmake --help
```
......@@ -6,4 +6,6 @@ target_sources(${PROJECT_NAME}
main.c
menu.h
menu.c
game.h
game.c
)
#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
#pragma once
void initGame();
void drawGame();
void calcGame();
#include "menu.h"
#include "game.h"
#include <raylib.h>
......@@ -20,18 +21,27 @@ int main() {
enum { MENU, GAME } state = MENU;
initMenu();
initGame();
while (!WindowShouldClose()) {
if (IsKeyPressed(KEY_F11)) {
ToggleFullscreen();
}
if (IsKeyPressed(KEY_ENTER) && state == MENU) {
state = GAME;
} // Enter to start the game when in menu
if (IsKeyPressed(KEY_BACKSPACE) && state == GAME) {
state = MENU;
} // Backspace to go back to the menu
float scale = min((float) GetScreenWidth() / GAME_SCREEN_WIDTH, (float) GetScreenHeight() / GAME_SCREEN_HEIGHT);
if (state == MENU) {
calcMenu();
} else if (state == GAME) {
// todo
calcGame();
}
BeginDrawing();
......@@ -40,7 +50,7 @@ int main() {
if (state == MENU) {
drawMenu();
} else if (state == GAME) {
// todo
drawGame();
}
EndTextureMode();
......
......@@ -33,9 +33,11 @@ void calcMenu() {
if (IsKeyPressed(KEY_BACKSPACE) && letterCount > 0) {
name[--letterCount] = 0;
}
}
void drawMenu() {
ClearBackground(BLACK); // To clear the screen when you go back into the menu
DrawText("PLAY", playBtnPos.x, playBtnPos.y, PLAY_FONT_SIZE, RED);
DrawRectangleRec(inputBox, LIGHTGRAY);
DrawRectangleLines(inputBox.x, inputBox.y, inputBox.width, inputBox.height, RED);
......
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