Initial commit: Tetris Prototype
This commit is contained in:
commit
987845e4dc
9 files changed
+10449
No files matched your search
@@ -0,0 +1,2 @@
|
|||||||
|
CompileFlags:
|
||||||
|
Add: [-I, C:/msys64/ucrt64/include, --target=x86_64-w64-mingw32]
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
# Name der Ausgabedatei
|
||||||
|
TARGET = spiel.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,110 @@
|
|||||||
|
#include "include/raylib.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct Block {
|
||||||
|
Vector2 position;
|
||||||
|
int form, onGround;
|
||||||
|
float speed;
|
||||||
|
|
||||||
|
struct Block *next;
|
||||||
|
} Block;
|
||||||
|
|
||||||
|
|
||||||
|
void createBlock(Block **head) {
|
||||||
|
Block *block = MemAlloc(sizeof(Block));
|
||||||
|
block->position = (Vector2){ 400, -40 };
|
||||||
|
block->form = 1;
|
||||||
|
block->onGround = 0;
|
||||||
|
block->speed = 2;
|
||||||
|
block->next = NULL;
|
||||||
|
|
||||||
|
// Falls die Liste leer ist
|
||||||
|
if (*head == NULL) {
|
||||||
|
*head = block;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Durch alle Blöcke iterieren und den neuesten am Schluss hinzufügen
|
||||||
|
Block *currentBlock = *head;
|
||||||
|
while (currentBlock->next != NULL) {
|
||||||
|
currentBlock = currentBlock->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentBlock->next = block;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
|
||||||
|
// INIT
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
InitWindow(screenWidth, screenHeight, "Raylib Manuell");
|
||||||
|
|
||||||
|
Block *block = { 0 };
|
||||||
|
createBlock(&block);
|
||||||
|
int blockMoving = 1;
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
|
||||||
|
while (!WindowShouldClose()) {
|
||||||
|
// UPDATE GAME LOGIC
|
||||||
|
Block *currentBlock = block;
|
||||||
|
// Alle Blöcke fallen lassen
|
||||||
|
while (currentBlock != NULL) {
|
||||||
|
// Wenn Block noch nicht auf Boden, dann fallen
|
||||||
|
if (currentBlock->onGround == 0) {
|
||||||
|
|
||||||
|
Block *collisionBlock = block;
|
||||||
|
while (collisionBlock != NULL) {
|
||||||
|
struct Rectangle rect1 = {currentBlock->position.x, currentBlock->position.y, 20, 20};
|
||||||
|
struct Rectangle rect2 = {collisionBlock->position.x, collisionBlock->position.y, 20, 20};
|
||||||
|
|
||||||
|
if (CheckCollisionRecs(rect1, rect2)) {
|
||||||
|
currentBlock->onGround = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentBlock->position.y < screenHeight - 20) {
|
||||||
|
currentBlock->position.y += currentBlock->speed;
|
||||||
|
} else {
|
||||||
|
blockMoving = 0;
|
||||||
|
currentBlock->onGround = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
collisionBlock = collisionBlock->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
currentBlock = currentBlock->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wenn sich kein Block mehr bewegt, einen neuen erstellen
|
||||||
|
if (blockMoving == 0) {
|
||||||
|
createBlock(&block);
|
||||||
|
blockMoving = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ZEICHNEN
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
DrawFPS(20, 20);
|
||||||
|
|
||||||
|
currentBlock = block;
|
||||||
|
while (currentBlock != NULL) {
|
||||||
|
DrawRectangleV(currentBlock->position, (Vector2){20, 20}, BLUE);
|
||||||
|
currentBlock = currentBlock->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CloseWindow();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user