first commit
This commit is contained in:
commit
54893bbc92
9 files changed
+10506
No files matched your search
@@ -0,0 +1,2 @@
|
||||
*.exe
|
||||
.vs
|
||||
@@ -0,0 +1,34 @@
|
||||
# Name der Ausgabedatei
|
||||
TARGET = stars.exe
|
||||
|
||||
# Quelldateien
|
||||
SRC = main.c
|
||||
|
||||
# Compiler
|
||||
CC = gcc
|
||||
|
||||
# Compiler-Flags
|
||||
# -Iinclude: Sagt dem Compiler, dass er im Ordner 'include' nach raylib.h suchen soll
|
||||
CFLAGS = -Wall -std=c99 -Iinclude
|
||||
|
||||
# Pfad zu den Bibliotheken (-Llib verweist auf den lokalen 'lib' Ordner)
|
||||
LDFLAGS = -Llib
|
||||
|
||||
# Linker-Bibliotheken
|
||||
# -lraylib bindet die lokale libraylib.a ein
|
||||
# Die restlichen sind Windows-Systembibliotheken
|
||||
LIBS = -lraylib -lopengl32 -lgdi32 -lwinmm
|
||||
|
||||
# Standard-Ziel zum Kompilieren
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(SRC)
|
||||
$(CC) $(CFLAGS) $(SRC) -o $(TARGET) $(LDFLAGS) $(LIBS)
|
||||
|
||||
# Programm ausführen
|
||||
run: all
|
||||
$(TARGET)
|
||||
|
||||
# Aufräumen (Windows-Befehl)
|
||||
clean:
|
||||
del /q $(TARGET)
|
||||
+1743
File diff suppressed because it is too large.
Load diff
+3139
File diff suppressed because it is too large.
Load diff
+5421
File diff suppressed because it is too large.
Load diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,167 @@
|
||||
#include "include/raylib.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define WIDTH 800
|
||||
#define HEIGHT 450
|
||||
|
||||
typedef struct {
|
||||
Vector2 pos;
|
||||
float radius;
|
||||
float speed;
|
||||
} Star;
|
||||
|
||||
|
||||
typedef struct {
|
||||
Vector2 pos;
|
||||
Vector2 size;
|
||||
float speed;
|
||||
Color color;
|
||||
} Player;
|
||||
|
||||
|
||||
void initStars(Star* star, int maxStars);
|
||||
void starMovement(int* activeStars, int maxStars, Star* star);
|
||||
void drawStars(Star* star, int activeStars);
|
||||
void initPlayer(Player* player);
|
||||
void playerMovement(Player* player, Star* star, int activeStars);
|
||||
void drawPlayer(Player* player);
|
||||
|
||||
|
||||
int main() {
|
||||
// Inits
|
||||
const char *title = "StarStruck";
|
||||
|
||||
// Window öffnen
|
||||
InitWindow(WIDTH, HEIGHT, title);
|
||||
|
||||
SetTargetFPS(60);
|
||||
|
||||
// Speicher für die Sterne reservieren und initialisieren
|
||||
int maxStars = 500;
|
||||
Star *star = MemAlloc(maxStars * sizeof(Star));
|
||||
|
||||
if (star == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
initStars(star, maxStars);
|
||||
|
||||
int activeStars = maxStars;
|
||||
|
||||
|
||||
// PLAYER
|
||||
Player player;
|
||||
initPlayer(&player);
|
||||
|
||||
|
||||
// Gameloop
|
||||
while (!WindowShouldClose()) {
|
||||
// UPDATE LOGIC
|
||||
starMovement(&activeStars, maxStars, star);
|
||||
playerMovement(&player, star, activeStars);
|
||||
|
||||
|
||||
|
||||
// DRAW
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
|
||||
drawStars(star, activeStars);
|
||||
drawPlayer(&player);
|
||||
|
||||
DrawFPS(20, 20);
|
||||
DrawText(TextFormat("Aktive Sterne: %d", activeStars), 20, 40, 20, WHITE);
|
||||
|
||||
EndDrawing();
|
||||
|
||||
}
|
||||
|
||||
|
||||
CloseWindow();
|
||||
|
||||
MemFree(star);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// FUNKTIONEN
|
||||
void initStars(Star* star, int maxStars) {
|
||||
for (int i = 0; i < maxStars; i++) {
|
||||
int randomX = GetRandomValue(0, WIDTH);
|
||||
int randomY = GetRandomValue(-500, -5);
|
||||
int randomRadius = GetRandomValue(1, 3);
|
||||
int randomSpeed = GetRandomValue(2, 4);
|
||||
star[i].pos = (Vector2){ (float)randomX, (float)randomY };
|
||||
star[i].radius = (float)randomRadius;
|
||||
star[i].speed = (float)randomSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void starMovement(int* activeStars, int maxStars, Star* star) {
|
||||
// Sterne entfernen oder hinzufügen
|
||||
if (IsKeyDown(KEY_S)) {
|
||||
if (*activeStars > 0) {
|
||||
(*activeStars)--; // Zeiger muss zuerst dereferenziert werden, wegen der Reihenfolge der Rechenoperanden
|
||||
}
|
||||
}
|
||||
|
||||
if (IsKeyDown(KEY_W)) {
|
||||
if (*activeStars < maxStars) {
|
||||
(*activeStars)++;
|
||||
}
|
||||
}
|
||||
|
||||
// Sterne fallen lassen
|
||||
for (int i = 0; i < (*activeStars); i++) {
|
||||
if (star[i].pos.y < HEIGHT) {
|
||||
star[i].pos.y += star[i].speed;
|
||||
}
|
||||
else {
|
||||
int randomX = GetRandomValue(0, WIDTH);
|
||||
int randomY = GetRandomValue(-50, -5);
|
||||
star[i].pos.x = (float)randomX;
|
||||
star[i].pos.y = (float)randomY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawStars(Star *star, int activeStars) {
|
||||
for (int i = 0; i < activeStars; i++) {
|
||||
DrawCircleV(star[i].pos, star[i].radius, WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// PLAYER
|
||||
void initPlayer(Player* player) {
|
||||
player->pos = (Vector2){ 400, 250 };
|
||||
player->size = (Vector2){ 20, 40 };
|
||||
player->speed = 5.f;
|
||||
player->color = RED;
|
||||
}
|
||||
|
||||
|
||||
void playerMovement(Player* player, Star* star, int activeStars) {
|
||||
if (IsKeyDown(KEY_LEFT) && player->pos.x > 0) {
|
||||
player->pos.x -= player->speed;
|
||||
}
|
||||
else if (IsKeyDown(KEY_RIGHT) && player->pos.x < WIDTH - player->size.x) {
|
||||
player->pos.x += player->speed;
|
||||
}
|
||||
|
||||
if (IsKeyDown(KEY_UP) && player->pos.y > HEIGHT / 2) {
|
||||
player->pos.y -= player->speed;
|
||||
}
|
||||
else if (IsKeyDown(KEY_DOWN) && player->pos.y < HEIGHT - player->size.y) {
|
||||
player->pos.y += player->speed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void drawPlayer(Player* player) {
|
||||
DrawRectangleV(player->pos, player->size, player->color);
|
||||
}
|
||||
Reference in new issue
Block a user