diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f37a446 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +bin/ +compile_commands.json +*.data diff --git a/Makefile b/Makefile index b752024..b26b71b 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,10 @@ C_FLAGS = \ $(C_FLAG_NO_UNKNOWN_PRAGMAS) # INCLUDE FLGAS -INCLUDE_FLAGS = -Iinclude +INCLUDE_FLAGS = \ + -Iinclude \ + $(EXTERNAL_FLAGS) \ + $(RAYLIB_CFLAGS) # EXTERNAL FLAGS EXTERNAL_RAYGUI = -Iexternal/raygui @@ -34,11 +37,13 @@ EXTERNAL_FLAGS = \ ifeq ($(OS), Windows_NT) SRC = $(wildcard src\*.c) TARGET = bin\win\game.exe - RAYLIB_FLAGS = -I%RAYLIB% -L%RAYLIB% -lraylib -lopengl32 -lgdi32 -lwinmm + RAYLIB_CFLAGS = -I%RAYLIB% + RAYLIB_LIBS = -L%RAYLIB% -lraylib -lopengl32 -lgdi32 -lwinmm else SRC = $(wildcard src/*.c) TARGET = bin/unix/game - RAYLIB_FLAGS = $(shell pkg-config --libs --cflags raylib) -lm + RAYLIB_CFLAGS = $(shell pkg-config --cflags raylib) + RAYLIB_LIBS = $(shell pkg-config --libs raylib) -lm endif # CREATE BIN DIR @@ -46,7 +51,10 @@ $(shell mkdir -p bin/unix bin/win) # COMMANDS build: $(SRC) - $(COMPILER) $(SRC) -o $(TARGET) $(C_FLAGS) $(INCLUDE_FLAGS) $(EXTERNAL_FLAGS) $(RAYLIB_FLAGS) + $(COMPILER) $(SRC) -o $(TARGET) \ + $(C_FLAGS) \ + $(INCLUDE_FLAGS) \ + $(RAYLIB_LIBS) clean: rm -rf $(TARGET) diff --git a/compile_commands.json b/compile_commands.json deleted file mode 100644 index 7c4ab3f..0000000 --- a/compile_commands.json +++ /dev/null @@ -1,684 +0,0 @@ -[ - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/app.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/app.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/appGameBirds.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/appGameBirds.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/appGame.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/appGame.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/appGameEnemies.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/appGameEnemies.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/appGameFloor.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/appGameFloor.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/appGameIslands.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/appGameIslands.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/appGamePlayer.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/appGamePlayer.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/appGameShip.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/appGameShip.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/appGameShoot.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/appGameShoot.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/appLogo.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/appLogo.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/appMenu.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/appMenu.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/appMenuMainBackground.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/appMenuMainBackground.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/appMenuMain.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/appMenuMain.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/appMenuSettings.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/appMenuSettings.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/appState.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/appState.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/engineAnimation.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/engineAnimation.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/engineArray.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/engineArray.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/engineCamera.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/engineCamera.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/engineConfig.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/engineConfig.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/engineFont.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/engineFont.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/engineGamegui.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/engineGamegui.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/engineGui.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/engineGui.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/engineInput.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/engineInput.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/engineObject.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/engineObject.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/enginePhysics.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/enginePhysics.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/enginePostfx.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/enginePostfx.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/engineRectangle.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/engineRectangle.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/engineSoundtrack.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/engineSoundtrack.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/engineSprite.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/engineSprite.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/engineVector.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/engineVector.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - }, - { - "arguments": [ - "/usr/bin/gcc", - "-c", - "-std=c99", - "-g", - "-Wall", - "-Wpedantic", - "-Wshadow", - "-Wstrict-prototypes", - "-Wno-unknown-pragmas", - "-Iinclude", - "-Iexternal/rini", - "-Iexternal/raygui", - "-o", - "bin/osx/game", - "src/main.c" - ], - "directory": "/home/huaqo/dev/the-last-hive", - "file": "/home/huaqo/dev/the-last-hive/src/main.c", - "output": "/home/huaqo/dev/the-last-hive/bin/osx/game" - } -] diff --git a/config/player.ini b/config/player.ini new file mode 100644 index 0000000..9ad7fc6 --- /dev/null +++ b/config/player.ini @@ -0,0 +1,2 @@ +HEALTH_MAX = 100 +START_GOLD = 0 diff --git a/include/app.h b/include/app.h index 80a68b5..4bcfe2b 100644 --- a/include/app.h +++ b/include/app.h @@ -108,7 +108,11 @@ typedef struct { Animation animation; Physics physics; float rotation; +<<<<<<< HEAD Sound soundFlapping; +======= + int health; +>>>>>>> origin/pirate int gold; } Player; @@ -260,9 +264,15 @@ Projectiles CreateProjectiles(void); void UpdateProjectiles(Projectiles *projectiles, Enemies *enemies); void RenderProjectiles(Projectiles *projectiles); +void CheckPlayerCollisions(Player *player, Enemies *enemies); +void CheckEnemyCollisions(Enemies *enemies); +void CheckProjectileCollisions(Projectiles *projectiles, Enemies *enemies, + Player *player); + void InitGame(App *app); void UpdateGame(App *app); void RenderComponents(App *app); +void RenderOverlay(Mouse *mouse); void RenderGame(App *app); void CleanupGame(App *app); diff --git a/include/engine.h b/include/engine.h index 98f5f04..ba59057 100644 --- a/include/engine.h +++ b/include/engine.h @@ -1,190 +1,189 @@ #ifndef ENGINE_H #define ENGINE_H +#include +#include #include #include -#include #include -#include #include +#include #include -#include -typedef struct -{ - Texture2D texture; - Rectangle sourceRec; - Rectangle destRec; - Vector2 frameSize; - Vector2 origin; - float rotation; - Color color; +typedef struct { + Texture2D texture; + Rectangle sourceRec; + Rectangle destRec; + Vector2 frameSize; + Vector2 origin; + float rotation; + Color color; } Sprite; -typedef struct { - int state; - int currentFrame; - int maxFrame; - int framesCounter; - int framesSpeed; - float animTimer; +typedef struct { + int state; + int currentFrame; + int maxFrame; + int framesCounter; + int framesSpeed; + float animTimer; } Animation; typedef struct { - void** elements; - unsigned int count; - unsigned int capacity; + void **elements; + unsigned int count; + unsigned int capacity; } Array; typedef struct { - const char* path; - float frameWidth; - float frameHeight; - float rotation; + const char *path; + float frameWidth; + float frameHeight; + float rotation; } TextureAsset; typedef struct { - const char* path; + const char *path; } ShaderAsset; typedef struct { - const char* path; + const char *path; } SoundtrackAsset; typedef struct { - const char* path; + const char *path; } SoundAsset; typedef struct { - const TextureAsset *textureAssets; - const ShaderAsset *shaderAssets; - const SoundtrackAsset *soundtrackAssets; - const SoundAsset *soundAssets; + const TextureAsset *textureAssets; + const ShaderAsset *shaderAssets; + const SoundtrackAsset *soundtrackAssets; + const SoundAsset *soundAssets; } Assets; typedef struct { - char *path; - rini_config rini; + char *path; + rini_config rini; } Config; -typedef enum { - NOT_CLICKED, - HOVER, - CLICKED -} ButtonState; +typedef enum { NOT_CLICKED, HOVER, CLICKED } ButtonState; -typedef struct -{ - Sprite sprite; - Vector2 notClicked; - Vector2 hover; - Vector2 clicked; - bool isHovered; - bool isClicked; +typedef struct { + Sprite sprite; + Vector2 notClicked; + Vector2 hover; + Vector2 clicked; + bool isHovered; + bool isClicked; } ImageButton; -typedef struct -{ - Sprite sprite; +typedef struct { + Sprite sprite; } ImageElement; -typedef struct -{ - Rectangle rec; - char *text; +typedef struct { + Rectangle rec; + char *text; } Button; typedef struct { - Vector2 screenPosition; - Vector2 worldPosition; - float zoomSpeed; - float minZoom; - float maxZoom; - float scaleFactor; - float wheelMove; - bool leftButton; - bool rightButton; - Texture2D cursorTexture; + Vector2 screenPosition; + Vector2 worldPosition; + float zoomSpeed; + float minZoom; + float maxZoom; + float scaleFactor; + float wheelMove; + bool leftButton; + bool rightButton; + Texture2D cursorTexture; } Mouse; typedef struct { - Sprite sprite; - Vector2 position; + Sprite sprite; + Vector2 position; } Object; typedef struct { - Object *data; - const Object *prototype; - size_t count; + Object *data; + const Object *prototype; + size_t count; } ObjectArray; -typedef struct -{ - Vector2 position; - Vector2 direction; - Vector2 velocity; - float speed; +typedef struct { + Vector2 position; + Vector2 direction; + Vector2 velocity; + float speed; + float weight; } Physics; typedef struct { - Shader shader; - int resolutionLoc; - int strengthLoc; - float strength; + Shader shader; + int resolutionLoc; + int strengthLoc; + float strength; } PostProcessing; typedef struct { - Music music; - bool playing; - bool paused; + Music music; + bool playing; + bool paused; } Soundtrack; typedef struct { - Vector2 *data; - size_t count; + Vector2 *data; + size_t count; } Vector2Array; typedef struct { - int width; - int height; - const char* title; + int width; + int height; + const char *title; } Window; void UpdateAnimation(Animation *animation, float deltaTime); -Array* CreateArray(unsigned int initCapacity); -int AddElementToArray(Array* array, void* element); -int RemoveElementFromArray(Array* array, unsigned int index); -void* GetRandomElementFromArray(Array* array); -void UpdateArray(Array* array, void (*updateFunc)(void*)); -void RenderArray(Array* array, void (*renderFunc)(void*)); -void FreeArray(Array** array); +Array *CreateArray(unsigned int initCapacity); +int AddElementToArray(Array *array, void *element); +int RemoveElementFromArray(Array *array, unsigned int index); +void *GetRandomElementFromArray(Array *array); +void UpdateArray(Array *array, void (*updateFunc)(void *)); +void RenderArray(Array *array, void (*renderFunc)(void *)); +void FreeArray(Array **array); -Camera2D* GetCamera(void); +Camera2D *GetCamera(void); Rectangle GetCameraRectangle(void); void CreateCamera(Vector2 playerPosition, float initZoom); void UpdateCameraTarget(Vector2 *position, const float smoothness); -void UpdateCameraZoom(const float *scaleFactor, const float *minZoom, const float *maxZoom); -void UpdateCamera2D(Vector2* position, Mouse* mouse); +void UpdateCameraZoom(const float *scaleFactor, const float *minZoom, + const float *maxZoom); +void UpdateCamera2D(Vector2 *position, Mouse *mouse); -void InitConfig(Config *config, const char* path); +void InitConfig(Config *config, const char *path); int GetConfigInt(Config *config, const char *key); int GetConfigIntOrDefault(Config *config, const char *key, int default_value); -const char* GetConfigString(Config *config, const char *key); -const char* GetConfigStringOrDefault(Config *config, const char *key, const char *default_value); -const char* GetConfigDescription(Config *config, const char *key); +const char *GetConfigString(Config *config, const char *key); +const char *GetConfigStringOrDefault(Config *config, const char *key, + const char *default_value); +const char *GetConfigDescription(Config *config, const char *key); int SetConfigInt(Config *config, const char *key, int value, const char *desc); -int SetConfigString(Config *config, const char *key, const char *text, const char *desc); +int SetConfigString(Config *config, const char *key, const char *text, + const char *desc); int SetConfigDescription(Config *config, const char *key, const char *desc); int AddCommentLine(Config *config, const char *comment); void SaveConfig(Config *config); void CleanUpConfig(Config *config); -void InitFont(Font *font, const char* path); +void InitFont(Font *font, const char *path); void CleanupFont(Font *font); -ImageButton CreateImageButton(ButtonState state, Texture2D *texture, const TextureAsset *asset, Vector2 *source, Vector2 *clicked, Vector2 *hover, Rectangle *destRec); -ImageElement CreateImageElement(Texture2D *texture, const TextureAsset *asset, Vector2 *source, Rectangle *destRec); +ImageButton CreateImageButton(ButtonState state, Texture2D *texture, + const TextureAsset *asset, Vector2 *source, + Vector2 *clicked, Vector2 *hover, + Rectangle *destRec); +ImageElement CreateImageElement(Texture2D *texture, const TextureAsset *asset, + Vector2 *source, Rectangle *destRec); int isImageButtonClicked(ImageButton *b, Sound soundHover, Sound soundClick); void renderImageButton(ImageButton *b); void renderImageElement(ImageElement *e); @@ -193,18 +192,24 @@ Button initButton(char *text, Vector2 dimensions, Vector2 position); int isButtonClicked(Button *b); void renderButton(Button *b); -Mouse CreateMouse(float zoomSpeed, float minZoom, float maxZoom, Texture2D *texture); +Mouse CreateMouse(float zoomSpeed, float minZoom, float maxZoom, + Texture2D *texture); void UpdateMouseScreen(Mouse *mouse); void UpdateMouse(Mouse *mouse); Vector2 GetDirectionVector(void); ObjectArray CreateObjectArray(const Object *prototype, const size_t count); -Object* GetRandomObject(ObjectArray *objects); -void AddObjectToArray(ObjectArray *objects, const Object *prototype, Vector2 position); -void SetPositionForObjectArray(ObjectArray *objects, const Vector2Array *positions); -void SetRandomPositionForObjectArray(ObjectArray *objects, const Rectangle bounds); -void SwapAndPopObjectsArrayOnRecCollision(ObjectArray *objects, const Rectangle rec); -void SwapAndPopObjectsArrayOnPointCollision(ObjectArray *objects, const Vector2 point); +Object *GetRandomObject(ObjectArray *objects); +void AddObjectToArray(ObjectArray *objects, const Object *prototype, + Vector2 position); +void SetPositionForObjectArray(ObjectArray *objects, + const Vector2Array *positions); +void SetRandomPositionForObjectArray(ObjectArray *objects, + const Rectangle bounds); +void SwapAndPopObjectsArrayOnRecCollision(ObjectArray *objects, + const Rectangle rec); +void SwapAndPopObjectsArrayOnPointCollision(ObjectArray *objects, + const Vector2 point); void RenderObjectArray(const ObjectArray *objects); Vector2 GetDirectionBetweenTwoVectors(Vector2 vec1, Vector2 vec2); @@ -215,12 +220,12 @@ void UpdatePhysicsPosition(Vector2 *position, Vector2 *velocity); void UpdatePhysicsSpeed(float *speed, float *newSpeed); void UpdatePhysics(Physics *physics, Vector2 direction); -PostProcessing CreatePostFX(const char* shaderPath); +PostProcessing CreatePostFX(const char *shaderPath); void UpdatePostFX(PostProcessing *postFX); void RenderPostFX(PostProcessing *postFX, RenderTexture2D *target); void UnloadPostFX(PostProcessing *postFX); -Soundtrack LoadSoundtrack(const char* musicPath); +Soundtrack LoadSoundtrack(const char *musicPath); void UpdateSoundtrack(Soundtrack *soundtrack, bool playing); void UpdateSpriteSourceRec(Sprite *sprite, const Vector2 *vector); @@ -233,12 +238,17 @@ bool IsVectorZero(Vector2 v); Vector2 GetRandomVector(const Rectangle bounds); Vector2 RotationToVector2(float rotation); float Vector2ToRotation(Vector2 vec); +float Cross2D(Vector2 a, Vector2 b); Vector2 GetPositionInsideRectangle(Rectangle rec); Vector2 GetPositionOutsideRectangle(Rectangle rec, int min, int max); +<<<<<<< HEAD bool SaveStorageValue(const char* fileName, unsigned int position, int value); int LoadStorageValue(const char* fileName, unsigned int position); #endif //ENGINE_H +======= +#endif // ENGINE_H +>>>>>>> origin/pirate diff --git a/notes.md b/notes.md new file mode 100644 index 0000000..a32ee96 --- /dev/null +++ b/notes.md @@ -0,0 +1,11 @@ +# 04.07.26 + +What i can do next: + +- Player health bar +- Enemy health +- Enemy shooting +- Enemy Projectile -> player collisions effect +- Player Projectile -> Enemy collision effect +- End screen or something +- Shader for foam when driving diff --git a/src/appGame.c b/src/appGame.c index fedd700..e454cc1 100644 --- a/src/appGame.c +++ b/src/appGame.c @@ -69,8 +69,15 @@ void UpdateGame(App *app) { UpdateBirds(&g->birds); UpdateEnemies(&g->enemies, &g->projectiles); UpdateIslands(&g->islands); +<<<<<<< HEAD UpdateProjectiles(&g->projectiles, &g->enemies); UpdateSoundtrack(&g->soundtracks[AMBIENT], app->flags.soundtrackOn); +======= + UpdateProjectiles(&g->projectiles); + CheckPlayerCollisions(GetPlayer(), &app->game.enemies); + CheckEnemyCollisions(&app->game.enemies); + CheckProjectileCollisions(&app->game.projectiles, &app->game.enemies, GetPlayer()); +>>>>>>> origin/pirate } void RenderComponents(App *app) { @@ -92,6 +99,7 @@ void RenderGame(App *app) { BeginMode2D(*camera); RenderComponents(app); EndMode2D(); +<<<<<<< HEAD DrawTextureRec( g->mouse.cursorTexture, (Rectangle){0, 0, g->mouse.cursorTexture.width, @@ -100,8 +108,11 @@ void RenderGame(App *app) { Player *player = GetPlayer(); DrawText(TextFormat("Gold: %u", player->gold), 0.0f, 0.0f, 12.0f, YELLOW); +======= + RenderOverlay(&g->mouse); +>>>>>>> origin/pirate EndTextureMode(); - + BeginDrawing(); ClearBackground(BLACK); for (int i = 0; i < SHADER_COUNT; i++) { diff --git a/src/appGameCollisions.c b/src/appGameCollisions.c new file mode 100644 index 0000000..d42b723 --- /dev/null +++ b/src/appGameCollisions.c @@ -0,0 +1,102 @@ +#include "app.h" + +float playerCollisionRadius = 8.0f; +float enemiesCollisionRadius = 8.0f; +float projectilesCollisionRadius = 1.0f; + +void CheckPlayerCollisions(Player *player, Enemies *enemies) { + for (int i = 0; i < enemies->count; i++) { + + Vector2 playerPos = player->physics.position; + Vector2 enemiesPos = enemies->physics[i].position; + + float minDist = playerCollisionRadius + enemiesCollisionRadius; + + if (CheckCollisionCircles(playerPos, playerCollisionRadius, enemiesPos, + enemiesCollisionRadius)) { + + player->health -= 1; + + float dist = GetDistanceBetweenTwoVectors(playerPos, enemiesPos); + float overlap = minDist - dist; + + if (dist > 0.0f) { + Vector2 collisionVector = GetDirectionBetweenTwoVectors( + enemies->physics[i].position, player->physics.position); + player->physics.position.x += collisionVector.x * overlap; + player->physics.position.y += collisionVector.y * overlap; + Vector2 forward = RotationToVector2(player->rotation - 90.0f); + float side = Cross2D(forward, collisionVector); + player->rotation += side * 120.0f * GetFrameTime(); + } + } + } +} + +void CheckEnemyCollisions(Enemies *enemies) { + for (int a = 0; a < enemies->count; a++) { + for (int b = a + 1; b < enemies->count; b++) { + + Vector2 posA = enemies->physics[a].position; + Vector2 posB = enemies->physics[b].position; + + float minDist = enemiesCollisionRadius * 2; + + if (CheckCollisionCircles(posA, enemiesCollisionRadius, posB, + enemiesCollisionRadius)) { + + Vector2 collisionVectorA = GetDirectionBetweenTwoVectors(posB, posA); + Vector2 collisionVectorB = GetDirectionBetweenTwoVectors(posA, posB); + float dist = GetDistanceBetweenTwoVectors(posA, posB); + float overlap = minDist - dist; + + if (dist > 0.0f) { + enemies->physics[a].position.x += collisionVectorA.x * overlap * 0.5f; + enemies->physics[a].position.y += collisionVectorA.y * overlap * 0.5f; + + enemies->physics[b].position.x += collisionVectorB.x * overlap * 0.5f; + enemies->physics[b].position.y += collisionVectorB.y * overlap * 0.5f; + + Vector2 forwardA = + RotationToVector2(enemies->sprite[a].rotation - 90.0f); + Vector2 forwardB = + RotationToVector2(enemies->sprite[b].rotation - 90.0f); + float sideA = Cross2D(forwardA, collisionVectorA); + float sideB = Cross2D(forwardB, collisionVectorB); + enemies->sprite[a].rotation += sideA * 120.0f * GetFrameTime(); + enemies->sprite[b].rotation += sideB * 120.0f * GetFrameTime(); + } + } + } + } +} + +void CheckProjectileCollisions(Projectiles *projectiles, Enemies *enemies, + Player *player) { + for (int i = 0; i < projectiles->count; i++) { + if (!projectiles->active[i]) + continue; + Vector2 projectilePos = projectiles->physics[i].position; + for (int j = 0; j < enemies->count; j++) { + Vector2 enemyPos = enemies->physics[j].position; + + if (CheckCollisionCircles(projectilePos, projectilesCollisionRadius, + enemyPos, enemiesCollisionRadius)) { + player->gold += 20; + Rectangle cameraRec = GetCameraRectangle(); + enemies->physics[j].position = + GetPositionOutsideRectangle(cameraRec, 100, 1000); + } + } + + if (!projectiles->active[i]) + continue; + + Vector2 playerPos = player->physics.position; + if (CheckCollisionCircles(projectilePos, projectilesCollisionRadius, + playerPos, playerCollisionRadius)) { + + player->health -= 20; + } + } +} diff --git a/src/appGameEnemies.c b/src/appGameEnemies.c index 9cbd98c..5e44ea0 100644 --- a/src/appGameEnemies.c +++ b/src/appGameEnemies.c @@ -1,47 +1,62 @@ #include "app.h" const TextureAsset enemiesTextureAssets[ENEMIES_TEX_COUNT] = { - {"assets/ship_start.png", 16.0f, 16.0f, 90.0f}}; + {"assets/ship_start.png", 16.0f, 16.0f, 90.0f} +}; -Enemies CreateEnemies(void) { - Enemies enemies = {.count = MAX_ENEMIES}; - TextureAsset textureAsset = enemiesTextureAssets[BOAT]; - Texture2D texture = LoadTexture(textureAsset.path); - float frameWidth = textureAsset.frameWidth; - float rotation = textureAsset.rotation; +Enemies CreateEnemies(void){ + Enemies enemies = {.count = MAX_ENEMIES}; + TextureAsset textureAsset = enemiesTextureAssets[BOAT]; + Texture2D texture = LoadTexture(textureAsset.path); + float frameWidth = textureAsset.frameWidth; + float rotation = textureAsset.rotation; - for (int i = 0; i < enemies.count; i++) { - enemies.sprite[i] = (Sprite){ - .texture = texture, - .frameSize = {frameWidth, frameWidth}, - .sourceRec = {0.0f, 0.0f, frameWidth, frameWidth}, - .destRec = {GetScreenWidth() / 2, 0.0f, frameWidth, frameWidth}, - .origin = {frameWidth / 2, frameWidth / 2}, - .rotation = rotation, - .color = WHITE}; + for (int i = 0; i < enemies.count; i++) + { + enemies.sprite[i] = (Sprite){ + .texture = texture, + .frameSize = {frameWidth, frameWidth}, + .sourceRec = {0.0f, 0.0f, frameWidth, frameWidth}, + .destRec = {GetScreenWidth()/2, 0.0f, frameWidth, frameWidth}, + .origin = {frameWidth / 2, frameWidth / 2}, + .rotation = rotation, + .color = WHITE + }; - enemies.animation[i] = (Animation){.state = 1, - .currentFrame = 0, - .maxFrame = 2, - .framesCounter = 0, - .framesSpeed = 2.0f, - .animTimer = 0.0f}; + enemies.animation[i] = (Animation){ + .state = 1, + .currentFrame = 0, + .maxFrame = 2, + .framesCounter = 0, + .framesSpeed = 2.0f, + .animTimer = 0.0f + }; - Rectangle cameraRec = GetCameraRectangle(); + Rectangle cameraRec = GetCameraRectangle(); - enemies.physics[i] = - (Physics){.position = GetPositionOutsideRectangle(cameraRec, 100, 1000), - .direction = (Vector2){0.0f, 0.0f}, - .speed = 5.0f}; + enemies.physics[i] = (Physics){ + .position = GetPositionOutsideRectangle(cameraRec, 100, 1000), + .direction = (Vector2){0.0f, 0.0f}, + .speed = 5.0f, + .weight = 5.0f + }; +<<<<<<< HEAD enemies.arrived[i] = true; enemies.destPos[i] = (Vector2){0.0f, 0.0f}; enemies.alive[i] = true; } +======= + enemies.arrived[i] = true; + enemies.destPos[i] = (Vector2){0.0f, 0.0f}; +>>>>>>> origin/pirate - return enemies; + } + + return enemies; } +<<<<<<< HEAD void UpdateEnemies(Enemies *enemies, Projectiles *projectiles) { Camera2D *camera = GetCamera(); Rectangle cameraRec = GetCameraRectangle(); @@ -91,4 +106,43 @@ void RenderEnemies(Enemies *enemies) { RenderSprite(&enemies->sprite[i]); } } +======= +void UpdateEnemies(Enemies *enemies){ + Camera2D *camera = GetCamera(); + Rectangle cameraRec = GetCameraRectangle(); + + for (int i = 0; i < enemies->count; i++) + { + if(enemies->arrived[i]) + { + enemies->destPos[i] = GetPositionOutsideRectangle(cameraRec, 100, 1000); + enemies->arrived[i] = false; + } + if(CheckCollisionPointCircle(enemies->physics[i].position, enemies->destPos[i], 10.0F)) + { + enemies->arrived[i] = true; + } + if(GetDistanceBetweenTwoVectors(enemies->physics[i].position, camera->target) > 1000){ + enemies->physics[i].position = GetPositionOutsideRectangle(cameraRec, 100, 1000); + } + Vector2 dir = GetDirectionBetweenTwoVectors(enemies->physics[i].position, enemies->destPos[i]); + UpdatePhysics(&enemies->physics[i], dir); + UpdateSpriteDestRec(&enemies->sprite[i], &enemies->physics[i].position); + float rotation = Vector2ToRotation(dir); + UpdateSpriteRotation(&enemies->sprite[i], rotation + 90.0f); + UpdateAnimation(&enemies->animation[i], GetFrameTime()); + UpdateSpriteSourceRec(&enemies->sprite[i], &(Vector2){enemies->sprite[i].frameSize.x * enemies->animation[i].currentFrame, enemies->sprite[i].frameSize.y}); + } } + +void RenderEnemies(Enemies *enemies){ + + for (int i = 0; i < enemies->count; i++) + { + RenderSprite(&enemies->sprite[i]); + } + +>>>>>>> origin/pirate +} + + diff --git a/src/appGameOverlay.c b/src/appGameOverlay.c new file mode 100644 index 0000000..b5b87f1 --- /dev/null +++ b/src/appGameOverlay.c @@ -0,0 +1,19 @@ +#include "app.h" +#include "raylib.h" +#include + +void RenderOverlay(Mouse *mouse) { + + // Health + Player *player = GetPlayer(); + const char *text = TextFormat("Health: %i\n" + "Gold: %i\n", + player->health, player->gold); + DrawText(text, 0, 0, 25, WHITE); + + // Mouse + Rectangle mouseRectangle = (Rectangle){0, 0, mouse->cursorTexture.width, + mouse->cursorTexture.height}; + DrawTextureRec(mouse->cursorTexture, mouseRectangle, mouse->screenPosition, + WHITE); +} diff --git a/src/appGamePlayer.c b/src/appGamePlayer.c index c4361df..6141b79 100644 --- a/src/appGamePlayer.c +++ b/src/appGamePlayer.c @@ -1,4 +1,5 @@ #include "app.h" +#include "engine.h" typedef enum { FLAPPING, @@ -10,30 +11,27 @@ const SoundAsset playerSoundAssets[SOUND_COUNT] = { }; const TextureAsset playerTextureAssets[PLAYER_TEX_COUNT] = { - {"assets/ship_start.png", 16.0f, 16.0f, 0.0f} -}; + {"assets/ship_start.png", 16.0f, 16.0f, 0.0f}}; -float playerSpeeds[SPEED_COUNT] = { - 0.0f, - 5.0f, - 10.0f -}; +float playerSpeeds[SPEED_COUNT] = {0.0f, 5.0f, 10.0f}; + +Config config; playerSpeedID GetPlayerSpeedID(float speed) { - for (int i = 0; i < SPEED_COUNT; i++) { - if (playerSpeeds[i] == speed) { - return (playerSpeedID)i; - } + for (int i = 0; i < SPEED_COUNT; i++) { + if (playerSpeeds[i] == speed) { + return (playerSpeedID)i; } - return ANCHOR; + } + return ANCHOR; } -Player* GetPlayer(void) -{ - static Player player; - return &player; +Player *GetPlayer(void) { + static Player player; + return &player; } +<<<<<<< HEAD void CreatePlayer(void) { TextureAsset startShipAsset = playerTextureAssets[START_SHIP]; @@ -51,16 +49,17 @@ void CreatePlayer(void) .rotation = rotation, .color = WHITE }; +======= +void CreatePlayer(void) { - Animation playerAnimation = { - .state = 1, - .currentFrame = 0, - .maxFrame = 3, - .framesCounter = 0, - .framesSpeed = 0.0f, - .animTimer = 0.0f - }; + InitConfig(&config, "config/player.ini"); + int PLAYER_HEALTH_MAX = GetConfigInt(&config, "HEALTH_MAX"); + int START_GOLD = GetConfigInt(&config, "START_GOLD"); +>>>>>>> origin/pirate + TextureAsset startShipAsset = playerTextureAssets[START_SHIP]; + +<<<<<<< HEAD Physics playerPhysics = { .position = (Vector2){(float)LoadStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSX), (float)LoadStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSY)}, .direction = (Vector2){0.0f, 0.0f}, @@ -95,35 +94,83 @@ void UpdatePlayer(void) } } } +======= + Texture2D texture = LoadTexture(startShipAsset.path); + float frameWidth = startShipAsset.frameWidth; + float rotation = startShipAsset.rotation; - if(IsKeyPressed(KEY_S) || IsKeyPressed(KEY_DOWN)){ - if(player->physics.speed > playerSpeeds[ANCHOR]){ - if(player->physics.speed > playerSpeeds[SLOW_AHEAD]){ - player->physics.speed = playerSpeeds[SLOW_AHEAD]; - } - else { - player->physics.speed = playerSpeeds[ANCHOR]; + Sprite playerSprite = {.texture = texture, + .frameSize = {frameWidth, frameWidth}, + .sourceRec = {0.0f, 0.0f, frameWidth, frameWidth}, + .destRec = {0.0f, 0.0f, frameWidth, frameWidth}, + .origin = {frameWidth / 2, frameWidth / 2}, + .rotation = rotation, + .color = WHITE}; - } - } - } + Animation playerAnimation = {.state = 1, + .currentFrame = 0, + .maxFrame = 3, + .framesCounter = 0, + .framesSpeed = 0.0f, + .animTimer = 0.0f}; - player->sprite.sourceRec.x = 16.0f * GetPlayerSpeedID(player->physics.speed); + Physics playerPhysics = {.position = (Vector2){0.0f, 0.0f}, + .direction = (Vector2){0.0f, 0.0f}, + .speed = playerSpeeds[ANCHOR], + .weight = 10.0f}; + Player *player = GetPlayer(); + *player = (Player){.sprite = playerSprite, + .animation = playerAnimation, + .physics = playerPhysics, + .rotation = rotation, + .health = PLAYER_HEALTH_MAX, + .gold = START_GOLD}; +} - float rotationSpeed = 50.0f; +void UpdatePlayer(void) { + Player *player = GetPlayer(); + if (IsKeyPressed(KEY_W) || IsKeyPressed(KEY_UP)) { + if (player->physics.speed < playerSpeeds[FAST_AHEAD]) { + if (player->physics.speed < playerSpeeds[SLOW_AHEAD]) { + player->physics.speed = playerSpeeds[SLOW_AHEAD]; + } else { + player->physics.speed = playerSpeeds[FAST_AHEAD]; + } + } + } +>>>>>>> origin/pirate - if (player->physics.speed > playerSpeeds[ANCHOR]){ + if (IsKeyPressed(KEY_S) || IsKeyPressed(KEY_DOWN)) { + if (player->physics.speed > playerSpeeds[ANCHOR]) { + if (player->physics.speed > playerSpeeds[SLOW_AHEAD]) { + player->physics.speed = playerSpeeds[SLOW_AHEAD]; + } else { + player->physics.speed = playerSpeeds[ANCHOR]; + } + } + } - if (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT)) { - player->rotation -= rotationSpeed * GetFrameTime(); - } + player->sprite.sourceRec.x = 16.0f * GetPlayerSpeedID(player->physics.speed); - if (IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT)) { - player->rotation += rotationSpeed * GetFrameTime(); - } - } + float rotationSpeed = 50.0f; + if (player->physics.speed > playerSpeeds[ANCHOR]) { + + if (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT)) { + player->rotation -= rotationSpeed * GetFrameTime(); + } + + if (IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT)) { + player->rotation += rotationSpeed * GetFrameTime(); + } + } + + player->sprite.rotation = player->rotation; + + Vector2 dir = RotationToVector2(player->rotation - 90.0f); + +<<<<<<< HEAD player->sprite.rotation = player->rotation; Vector2 dir = RotationToVector2(player->rotation - 90.0f); UpdatePhysics(&player->physics, dir); @@ -131,10 +178,13 @@ void UpdatePlayer(void) SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSX, (int)player->physics.position.x); SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSY, (int)player->physics.position.y); SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_ROTATION, (int)player->rotation); +======= + UpdatePhysics(&player->physics, dir); + UpdateSpriteDestRec(&player->sprite, &player->physics.position); +>>>>>>> origin/pirate } -void RenderPlayer(void){ - Player* player = GetPlayer(); - RenderSprite(&player->sprite); +void RenderPlayer(void) { + Player *player = GetPlayer(); + RenderSprite(&player->sprite); } - diff --git a/src/appGameProjectiles.c b/src/appGameProjectiles.c index ecccde2..e71275c 100644 --- a/src/appGameProjectiles.c +++ b/src/appGameProjectiles.c @@ -2,16 +2,10 @@ #include #include -typedef enum { - CANNONBALL_SHOOTING, - CANNONBALL_IMPACT, - SOUND_COUNT -} SoundID; +typedef enum { CANNONBALL_SHOOTING, CANNONBALL_IMPACT, SOUND_COUNT } SoundID; -const SoundAsset soundAssets[SOUND_COUNT] = { - {"assets/cannonball_shooting.mp3"}, - {"assets/cannonball_impact.mp3"} -}; +const SoundAsset soundAssets[SOUND_COUNT] = {{"assets/cannonball_shooting.mp3"}, + {"assets/cannonball_impact.mp3"}}; Projectiles CreateProjectiles(void) { Projectiles projectiles = {.count = MAX_PROJECTILES}; @@ -23,7 +17,8 @@ Projectiles CreateProjectiles(void) { projectiles.radius[i] = 1.0f; projectiles.active[i] = false; projectiles.color[i] = GRAY; - projectiles.soundShooting[i] = LoadSound(soundAssets[CANNONBALL_SHOOTING].path); + projectiles.soundShooting[i] = + LoadSound(soundAssets[CANNONBALL_SHOOTING].path); projectiles.soundImpact[i] = LoadSound(soundAssets[CANNONBALL_IMPACT].path); } @@ -52,7 +47,7 @@ void UpdateProjectiles(Projectiles *projectiles, Enemies *enemies) { } if (IsKeyDown(KEY_E) && (currentTime - lastShotTime >= reloadTime)) { - for (int i = 0; i < projectiles->count; i++){ + for (int i = 0; i < projectiles->count; i++) { if (!projectiles->active[i]) { projectiles->active[i] = true; Player *player = GetPlayer(); @@ -68,26 +63,29 @@ void UpdateProjectiles(Projectiles *projectiles, Enemies *enemies) { for (int i = 0; i < projectiles->count; i++) { - if (!projectiles->active[i]) continue; + if (!projectiles->active[i]) + continue; - for (int j = 0; j < enemies->count; j++){ - if (CheckCollisionCircleRec(projectiles->physics[i].position, projectiles->radius[i], enemies->sprite[j].destRec)){ + for (int j = 0; j < enemies->count; j++) { + if (CheckCollisionCircleRec(projectiles->physics[i].position, + projectiles->radius[i], + enemies->sprite[j].destRec)) { PlaySound(projectiles->soundImpact[i]); Player *player = GetPlayer(); player->gold += 1; - SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_GOLD, player->gold); + SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_GOLD, + player->gold); projectiles->active[i] = false; } } - UpdatePhysics(&projectiles->physics[i], - projectiles->physics[i].direction); + UpdatePhysics(&projectiles->physics[i], projectiles->physics[i].direction); } } void RenderProjectiles(Projectiles *projectiles) { for (int i = 0; i < projectiles->count; i++) { - if (projectiles->active[i]) { + if (projectiles->active[i] == true) { DrawCircle(projectiles->physics[i].position.x, projectiles->physics[i].position.y, projectiles->radius[i], projectiles->color[i]); diff --git a/src/engineVector.c b/src/engineVector.c index 38a141f..40481ba 100644 --- a/src/engineVector.c +++ b/src/engineVector.c @@ -1,27 +1,26 @@ #include "engine.h" bool IsVectorZero(Vector2 v) { - float epsilon = 0.01f; - return (fabs(v.x) < epsilon && fabs(v.y) < epsilon); + float epsilon = 0.01f; + return (fabs(v.x) < epsilon && fabs(v.y) < epsilon); } Vector2 GetRandomVector(const Rectangle bounds) { - return (Vector2){ - bounds.x + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.width, - bounds.y + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.height - }; + return (Vector2){ + bounds.x + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.width, + bounds.y + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.height}; } -Vector2 RotationToVector2(float rotation) -{ - float rad = rotation * (PI / 180.0f); - Vector2 vec = { cosf(rad), sinf(rad) }; - return vec; +Vector2 RotationToVector2(float rotation) { + float rad = rotation * (PI / 180.0f); + Vector2 vec = {cosf(rad), sinf(rad)}; + return vec; } -float Vector2ToRotation(Vector2 vec) -{ - float rad = atan2f(vec.y, vec.x); - float deg = rad * (180.0f / PI); - return deg; +float Vector2ToRotation(Vector2 vec) { + float rad = atan2f(vec.y, vec.x); + float deg = rad * (180.0f / PI); + return deg; } + +float Cross2D(Vector2 a, Vector2 b) { return a.x * b.y - a.y * b.x; }