This commit is contained in:
2026-07-05 21:03:55 +02:00
14 changed files with 507 additions and 914 deletions
+3
View File
@@ -0,0 +1,3 @@
bin/
compile_commands.json
*.data
+12 -4
View File
@@ -21,7 +21,10 @@ C_FLAGS = \
$(C_FLAG_NO_UNKNOWN_PRAGMAS) $(C_FLAG_NO_UNKNOWN_PRAGMAS)
# INCLUDE FLGAS # INCLUDE FLGAS
INCLUDE_FLAGS = -Iinclude INCLUDE_FLAGS = \
-Iinclude \
$(EXTERNAL_FLAGS) \
$(RAYLIB_CFLAGS)
# EXTERNAL FLAGS # EXTERNAL FLAGS
EXTERNAL_RAYGUI = -Iexternal/raygui EXTERNAL_RAYGUI = -Iexternal/raygui
@@ -34,11 +37,13 @@ EXTERNAL_FLAGS = \
ifeq ($(OS), Windows_NT) ifeq ($(OS), Windows_NT)
SRC = $(wildcard src\*.c) SRC = $(wildcard src\*.c)
TARGET = bin\win\game.exe 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 else
SRC = $(wildcard src/*.c) SRC = $(wildcard src/*.c)
TARGET = bin/unix/game 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 endif
# CREATE BIN DIR # CREATE BIN DIR
@@ -46,7 +51,10 @@ $(shell mkdir -p bin/unix bin/win)
# COMMANDS # COMMANDS
build: $(SRC) 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: clean:
rm -rf $(TARGET) rm -rf $(TARGET)
-684
View File
@@ -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"
}
]
+2
View File
@@ -0,0 +1,2 @@
HEALTH_MAX = 100
START_GOLD = 0
+10
View File
@@ -108,7 +108,11 @@ typedef struct {
Animation animation; Animation animation;
Physics physics; Physics physics;
float rotation; float rotation;
<<<<<<< HEAD
Sound soundFlapping; Sound soundFlapping;
=======
int health;
>>>>>>> origin/pirate
int gold; int gold;
} Player; } Player;
@@ -260,9 +264,15 @@ Projectiles CreateProjectiles(void);
void UpdateProjectiles(Projectiles *projectiles, Enemies *enemies); void UpdateProjectiles(Projectiles *projectiles, Enemies *enemies);
void RenderProjectiles(Projectiles *projectiles); 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 InitGame(App *app);
void UpdateGame(App *app); void UpdateGame(App *app);
void RenderComponents(App *app); void RenderComponents(App *app);
void RenderOverlay(Mouse *mouse);
void RenderGame(App *app); void RenderGame(App *app);
void CleanupGame(App *app); void CleanupGame(App *app);
+61 -51
View File
@@ -1,17 +1,16 @@
#ifndef ENGINE_H #ifndef ENGINE_H
#define ENGINE_H #define ENGINE_H
#include <math.h>
#include <raygui.h>
#include <raylib.h> #include <raylib.h>
#include <raymath.h> #include <raymath.h>
#include <raygui.h>
#include <rini.h> #include <rini.h>
#include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h>
typedef struct typedef struct {
{
Texture2D texture; Texture2D texture;
Rectangle sourceRec; Rectangle sourceRec;
Rectangle destRec; Rectangle destRec;
@@ -31,28 +30,28 @@ typedef struct {
} Animation; } Animation;
typedef struct { typedef struct {
void** elements; void **elements;
unsigned int count; unsigned int count;
unsigned int capacity; unsigned int capacity;
} Array; } Array;
typedef struct { typedef struct {
const char* path; const char *path;
float frameWidth; float frameWidth;
float frameHeight; float frameHeight;
float rotation; float rotation;
} TextureAsset; } TextureAsset;
typedef struct { typedef struct {
const char* path; const char *path;
} ShaderAsset; } ShaderAsset;
typedef struct { typedef struct {
const char* path; const char *path;
} SoundtrackAsset; } SoundtrackAsset;
typedef struct { typedef struct {
const char* path; const char *path;
} SoundAsset; } SoundAsset;
typedef struct { typedef struct {
@@ -67,14 +66,9 @@ typedef struct {
rini_config rini; rini_config rini;
} Config; } Config;
typedef enum { typedef enum { NOT_CLICKED, HOVER, CLICKED } ButtonState;
NOT_CLICKED,
HOVER,
CLICKED
} ButtonState;
typedef struct typedef struct {
{
Sprite sprite; Sprite sprite;
Vector2 notClicked; Vector2 notClicked;
Vector2 hover; Vector2 hover;
@@ -83,13 +77,11 @@ typedef struct
bool isClicked; bool isClicked;
} ImageButton; } ImageButton;
typedef struct typedef struct {
{
Sprite sprite; Sprite sprite;
} ImageElement; } ImageElement;
typedef struct typedef struct {
{
Rectangle rec; Rectangle rec;
char *text; char *text;
} Button; } Button;
@@ -118,12 +110,12 @@ typedef struct {
size_t count; size_t count;
} ObjectArray; } ObjectArray;
typedef struct typedef struct {
{
Vector2 position; Vector2 position;
Vector2 direction; Vector2 direction;
Vector2 velocity; Vector2 velocity;
float speed; float speed;
float weight;
} Physics; } Physics;
typedef struct { typedef struct {
@@ -147,44 +139,51 @@ typedef struct {
typedef struct { typedef struct {
int width; int width;
int height; int height;
const char* title; const char *title;
} Window; } Window;
void UpdateAnimation(Animation *animation, float deltaTime); void UpdateAnimation(Animation *animation, float deltaTime);
Array* CreateArray(unsigned int initCapacity); Array *CreateArray(unsigned int initCapacity);
int AddElementToArray(Array* array, void* element); int AddElementToArray(Array *array, void *element);
int RemoveElementFromArray(Array* array, unsigned int index); int RemoveElementFromArray(Array *array, unsigned int index);
void* GetRandomElementFromArray(Array* array); void *GetRandomElementFromArray(Array *array);
void UpdateArray(Array* array, void (*updateFunc)(void*)); void UpdateArray(Array *array, void (*updateFunc)(void *));
void RenderArray(Array* array, void (*renderFunc)(void*)); void RenderArray(Array *array, void (*renderFunc)(void *));
void FreeArray(Array** array); void FreeArray(Array **array);
Camera2D* GetCamera(void); Camera2D *GetCamera(void);
Rectangle GetCameraRectangle(void); Rectangle GetCameraRectangle(void);
void CreateCamera(Vector2 playerPosition, float initZoom); void CreateCamera(Vector2 playerPosition, float initZoom);
void UpdateCameraTarget(Vector2 *position, const float smoothness); void UpdateCameraTarget(Vector2 *position, const float smoothness);
void UpdateCameraZoom(const float *scaleFactor, const float *minZoom, const float *maxZoom); void UpdateCameraZoom(const float *scaleFactor, const float *minZoom,
void UpdateCamera2D(Vector2* position, Mouse* mouse); 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 GetConfigInt(Config *config, const char *key);
int GetConfigIntOrDefault(Config *config, const char *key, int default_value); int GetConfigIntOrDefault(Config *config, const char *key, int default_value);
const char* GetConfigString(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 *GetConfigStringOrDefault(Config *config, const char *key,
const char* GetConfigDescription(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 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 SetConfigDescription(Config *config, const char *key, const char *desc);
int AddCommentLine(Config *config, const char *comment); int AddCommentLine(Config *config, const char *comment);
void SaveConfig(Config *config); void SaveConfig(Config *config);
void CleanUpConfig(Config *config); void CleanUpConfig(Config *config);
void InitFont(Font *font, const char* path); void InitFont(Font *font, const char *path);
void CleanupFont(Font *font); void CleanupFont(Font *font);
ImageButton CreateImageButton(ButtonState state, Texture2D *texture, const TextureAsset *asset, Vector2 *source, Vector2 *clicked, Vector2 *hover, Rectangle *destRec); ImageButton CreateImageButton(ButtonState state, Texture2D *texture,
ImageElement CreateImageElement(Texture2D *texture, const TextureAsset *asset, Vector2 *source, Rectangle *destRec); 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); int isImageButtonClicked(ImageButton *b, Sound soundHover, Sound soundClick);
void renderImageButton(ImageButton *b); void renderImageButton(ImageButton *b);
void renderImageElement(ImageElement *e); void renderImageElement(ImageElement *e);
@@ -193,18 +192,24 @@ Button initButton(char *text, Vector2 dimensions, Vector2 position);
int isButtonClicked(Button *b); int isButtonClicked(Button *b);
void renderButton(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 UpdateMouseScreen(Mouse *mouse);
void UpdateMouse(Mouse *mouse); void UpdateMouse(Mouse *mouse);
Vector2 GetDirectionVector(void); Vector2 GetDirectionVector(void);
ObjectArray CreateObjectArray(const Object *prototype, const size_t count); ObjectArray CreateObjectArray(const Object *prototype, const size_t count);
Object* GetRandomObject(ObjectArray *objects); Object *GetRandomObject(ObjectArray *objects);
void AddObjectToArray(ObjectArray *objects, const Object *prototype, Vector2 position); void AddObjectToArray(ObjectArray *objects, const Object *prototype,
void SetPositionForObjectArray(ObjectArray *objects, const Vector2Array *positions); Vector2 position);
void SetRandomPositionForObjectArray(ObjectArray *objects, const Rectangle bounds); void SetPositionForObjectArray(ObjectArray *objects,
void SwapAndPopObjectsArrayOnRecCollision(ObjectArray *objects, const Rectangle rec); const Vector2Array *positions);
void SwapAndPopObjectsArrayOnPointCollision(ObjectArray *objects, const Vector2 point); 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); void RenderObjectArray(const ObjectArray *objects);
Vector2 GetDirectionBetweenTwoVectors(Vector2 vec1, Vector2 vec2); Vector2 GetDirectionBetweenTwoVectors(Vector2 vec1, Vector2 vec2);
@@ -215,12 +220,12 @@ void UpdatePhysicsPosition(Vector2 *position, Vector2 *velocity);
void UpdatePhysicsSpeed(float *speed, float *newSpeed); void UpdatePhysicsSpeed(float *speed, float *newSpeed);
void UpdatePhysics(Physics *physics, Vector2 direction); void UpdatePhysics(Physics *physics, Vector2 direction);
PostProcessing CreatePostFX(const char* shaderPath); PostProcessing CreatePostFX(const char *shaderPath);
void UpdatePostFX(PostProcessing *postFX); void UpdatePostFX(PostProcessing *postFX);
void RenderPostFX(PostProcessing *postFX, RenderTexture2D *target); void RenderPostFX(PostProcessing *postFX, RenderTexture2D *target);
void UnloadPostFX(PostProcessing *postFX); void UnloadPostFX(PostProcessing *postFX);
Soundtrack LoadSoundtrack(const char* musicPath); Soundtrack LoadSoundtrack(const char *musicPath);
void UpdateSoundtrack(Soundtrack *soundtrack, bool playing); void UpdateSoundtrack(Soundtrack *soundtrack, bool playing);
void UpdateSpriteSourceRec(Sprite *sprite, const Vector2 *vector); void UpdateSpriteSourceRec(Sprite *sprite, const Vector2 *vector);
@@ -233,12 +238,17 @@ bool IsVectorZero(Vector2 v);
Vector2 GetRandomVector(const Rectangle bounds); Vector2 GetRandomVector(const Rectangle bounds);
Vector2 RotationToVector2(float rotation); Vector2 RotationToVector2(float rotation);
float Vector2ToRotation(Vector2 vec); float Vector2ToRotation(Vector2 vec);
float Cross2D(Vector2 a, Vector2 b);
Vector2 GetPositionInsideRectangle(Rectangle rec); Vector2 GetPositionInsideRectangle(Rectangle rec);
Vector2 GetPositionOutsideRectangle(Rectangle rec, int min, int max); Vector2 GetPositionOutsideRectangle(Rectangle rec, int min, int max);
<<<<<<< HEAD
bool SaveStorageValue(const char* fileName, unsigned int position, int value); bool SaveStorageValue(const char* fileName, unsigned int position, int value);
int LoadStorageValue(const char* fileName, unsigned int position); int LoadStorageValue(const char* fileName, unsigned int position);
#endif //ENGINE_H #endif //ENGINE_H
=======
#endif // ENGINE_H
>>>>>>> origin/pirate
+11
View File
@@ -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
+11
View File
@@ -69,8 +69,15 @@ void UpdateGame(App *app) {
UpdateBirds(&g->birds); UpdateBirds(&g->birds);
UpdateEnemies(&g->enemies, &g->projectiles); UpdateEnemies(&g->enemies, &g->projectiles);
UpdateIslands(&g->islands); UpdateIslands(&g->islands);
<<<<<<< HEAD
UpdateProjectiles(&g->projectiles, &g->enemies); UpdateProjectiles(&g->projectiles, &g->enemies);
UpdateSoundtrack(&g->soundtracks[AMBIENT], app->flags.soundtrackOn); 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) { void RenderComponents(App *app) {
@@ -92,6 +99,7 @@ void RenderGame(App *app) {
BeginMode2D(*camera); BeginMode2D(*camera);
RenderComponents(app); RenderComponents(app);
EndMode2D(); EndMode2D();
<<<<<<< HEAD
DrawTextureRec( DrawTextureRec(
g->mouse.cursorTexture, g->mouse.cursorTexture,
(Rectangle){0, 0, g->mouse.cursorTexture.width, (Rectangle){0, 0, g->mouse.cursorTexture.width,
@@ -100,6 +108,9 @@ void RenderGame(App *app) {
Player *player = GetPlayer(); Player *player = GetPlayer();
DrawText(TextFormat("Gold: %u", player->gold), 0.0f, 0.0f, 12.0f, YELLOW); DrawText(TextFormat("Gold: %u", player->gold), 0.0f, 0.0f, 12.0f, YELLOW);
=======
RenderOverlay(&g->mouse);
>>>>>>> origin/pirate
EndTextureMode(); EndTextureMode();
BeginDrawing(); BeginDrawing();
+102
View File
@@ -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;
}
}
}
+64 -10
View File
@@ -1,47 +1,62 @@
#include "app.h" #include "app.h"
const TextureAsset enemiesTextureAssets[ENEMIES_TEX_COUNT] = { 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 CreateEnemies(void){
Enemies enemies = {.count = MAX_ENEMIES}; Enemies enemies = {.count = MAX_ENEMIES};
TextureAsset textureAsset = enemiesTextureAssets[BOAT]; TextureAsset textureAsset = enemiesTextureAssets[BOAT];
Texture2D texture = LoadTexture(textureAsset.path); Texture2D texture = LoadTexture(textureAsset.path);
float frameWidth = textureAsset.frameWidth; float frameWidth = textureAsset.frameWidth;
float rotation = textureAsset.rotation; float rotation = textureAsset.rotation;
for (int i = 0; i < enemies.count; i++) { for (int i = 0; i < enemies.count; i++)
{
enemies.sprite[i] = (Sprite){ enemies.sprite[i] = (Sprite){
.texture = texture, .texture = texture,
.frameSize = {frameWidth, frameWidth}, .frameSize = {frameWidth, frameWidth},
.sourceRec = {0.0f, 0.0f, frameWidth, frameWidth}, .sourceRec = {0.0f, 0.0f, frameWidth, frameWidth},
.destRec = {GetScreenWidth() / 2, 0.0f, frameWidth, frameWidth}, .destRec = {GetScreenWidth()/2, 0.0f, frameWidth, frameWidth},
.origin = {frameWidth / 2, frameWidth / 2}, .origin = {frameWidth / 2, frameWidth / 2},
.rotation = rotation, .rotation = rotation,
.color = WHITE}; .color = WHITE
};
enemies.animation[i] = (Animation){.state = 1, enemies.animation[i] = (Animation){
.state = 1,
.currentFrame = 0, .currentFrame = 0,
.maxFrame = 2, .maxFrame = 2,
.framesCounter = 0, .framesCounter = 0,
.framesSpeed = 2.0f, .framesSpeed = 2.0f,
.animTimer = 0.0f}; .animTimer = 0.0f
};
Rectangle cameraRec = GetCameraRectangle(); Rectangle cameraRec = GetCameraRectangle();
enemies.physics[i] = enemies.physics[i] = (Physics){
(Physics){.position = GetPositionOutsideRectangle(cameraRec, 100, 1000), .position = GetPositionOutsideRectangle(cameraRec, 100, 1000),
.direction = (Vector2){0.0f, 0.0f}, .direction = (Vector2){0.0f, 0.0f},
.speed = 5.0f}; .speed = 5.0f,
.weight = 5.0f
};
<<<<<<< HEAD
enemies.arrived[i] = true; enemies.arrived[i] = true;
enemies.destPos[i] = (Vector2){0.0f, 0.0f}; enemies.destPos[i] = (Vector2){0.0f, 0.0f};
enemies.alive[i] = true; 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) { void UpdateEnemies(Enemies *enemies, Projectiles *projectiles) {
Camera2D *camera = GetCamera(); Camera2D *camera = GetCamera();
Rectangle cameraRec = GetCameraRectangle(); Rectangle cameraRec = GetCameraRectangle();
@@ -91,4 +106,43 @@ void RenderEnemies(Enemies *enemies) {
RenderSprite(&enemies->sprite[i]); 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
}
+19
View File
@@ -0,0 +1,19 @@
#include "app.h"
#include "raylib.h"
#include <limits.h>
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);
}
+77 -27
View File
@@ -1,4 +1,5 @@
#include "app.h" #include "app.h"
#include "engine.h"
typedef enum { typedef enum {
FLAPPING, FLAPPING,
@@ -10,14 +11,11 @@ const SoundAsset playerSoundAssets[SOUND_COUNT] = {
}; };
const TextureAsset playerTextureAssets[PLAYER_TEX_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] = { float playerSpeeds[SPEED_COUNT] = {0.0f, 5.0f, 10.0f};
0.0f,
5.0f, Config config;
10.0f
};
playerSpeedID GetPlayerSpeedID(float speed) { playerSpeedID GetPlayerSpeedID(float speed) {
for (int i = 0; i < SPEED_COUNT; i++) { for (int i = 0; i < SPEED_COUNT; i++) {
@@ -28,12 +26,12 @@ playerSpeedID GetPlayerSpeedID(float speed) {
return ANCHOR; return ANCHOR;
} }
Player* GetPlayer(void) Player *GetPlayer(void) {
{
static Player player; static Player player;
return &player; return &player;
} }
<<<<<<< HEAD
void CreatePlayer(void) void CreatePlayer(void)
{ {
TextureAsset startShipAsset = playerTextureAssets[START_SHIP]; TextureAsset startShipAsset = playerTextureAssets[START_SHIP];
@@ -51,16 +49,17 @@ void CreatePlayer(void)
.rotation = rotation, .rotation = rotation,
.color = WHITE .color = WHITE
}; };
=======
void CreatePlayer(void) {
Animation playerAnimation = { InitConfig(&config, "config/player.ini");
.state = 1, int PLAYER_HEALTH_MAX = GetConfigInt(&config, "HEALTH_MAX");
.currentFrame = 0, int START_GOLD = GetConfigInt(&config, "START_GOLD");
.maxFrame = 3, >>>>>>> origin/pirate
.framesCounter = 0,
.framesSpeed = 0.0f,
.animTimer = 0.0f
};
TextureAsset startShipAsset = playerTextureAssets[START_SHIP];
<<<<<<< HEAD
Physics playerPhysics = { Physics playerPhysics = {
.position = (Vector2){(float)LoadStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSX), (float)LoadStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSY)}, .position = (Vector2){(float)LoadStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSX), (float)LoadStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSY)},
.direction = (Vector2){0.0f, 0.0f}, .direction = (Vector2){0.0f, 0.0f},
@@ -95,25 +94,68 @@ void UpdatePlayer(void)
} }
} }
} }
=======
Texture2D texture = LoadTexture(startShipAsset.path);
float frameWidth = startShipAsset.frameWidth;
float rotation = startShipAsset.rotation;
if(IsKeyPressed(KEY_S) || IsKeyPressed(KEY_DOWN)){ Sprite playerSprite = {.texture = texture,
if(player->physics.speed > playerSpeeds[ANCHOR]){ .frameSize = {frameWidth, frameWidth},
if(player->physics.speed > playerSpeeds[SLOW_AHEAD]){ .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};
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};
}
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]; player->physics.speed = playerSpeeds[SLOW_AHEAD];
} else {
player->physics.speed = playerSpeeds[FAST_AHEAD];
} }
else { }
player->physics.speed = playerSpeeds[ANCHOR]; }
>>>>>>> origin/pirate
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];
} }
} }
} }
player->sprite.sourceRec.x = 16.0f * GetPlayerSpeedID(player->physics.speed); player->sprite.sourceRec.x = 16.0f * GetPlayerSpeedID(player->physics.speed);
float rotationSpeed = 50.0f; float rotationSpeed = 50.0f;
if (player->physics.speed > playerSpeeds[ANCHOR]){ if (player->physics.speed > playerSpeeds[ANCHOR]) {
if (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT)) { if (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT)) {
player->rotation -= rotationSpeed * GetFrameTime(); player->rotation -= rotationSpeed * GetFrameTime();
@@ -124,6 +166,11 @@ void UpdatePlayer(void)
} }
} }
player->sprite.rotation = player->rotation;
Vector2 dir = RotationToVector2(player->rotation - 90.0f);
<<<<<<< HEAD
player->sprite.rotation = player->rotation; player->sprite.rotation = player->rotation;
Vector2 dir = RotationToVector2(player->rotation - 90.0f); Vector2 dir = RotationToVector2(player->rotation - 90.0f);
UpdatePhysics(&player->physics, dir); 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_POSX, (int)player->physics.position.x);
SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSY, (int)player->physics.position.y); SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSY, (int)player->physics.position.y);
SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_ROTATION, (int)player->rotation); 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){ void RenderPlayer(void) {
Player* player = GetPlayer(); Player *player = GetPlayer();
RenderSprite(&player->sprite); RenderSprite(&player->sprite);
} }
+16 -18
View File
@@ -2,16 +2,10 @@
#include <raylib.h> #include <raylib.h>
#include <raymath.h> #include <raymath.h>
typedef enum { typedef enum { CANNONBALL_SHOOTING, CANNONBALL_IMPACT, SOUND_COUNT } SoundID;
CANNONBALL_SHOOTING,
CANNONBALL_IMPACT,
SOUND_COUNT
} SoundID;
const SoundAsset soundAssets[SOUND_COUNT] = { const SoundAsset soundAssets[SOUND_COUNT] = {{"assets/cannonball_shooting.mp3"},
{"assets/cannonball_shooting.mp3"}, {"assets/cannonball_impact.mp3"}};
{"assets/cannonball_impact.mp3"}
};
Projectiles CreateProjectiles(void) { Projectiles CreateProjectiles(void) {
Projectiles projectiles = {.count = MAX_PROJECTILES}; Projectiles projectiles = {.count = MAX_PROJECTILES};
@@ -23,7 +17,8 @@ Projectiles CreateProjectiles(void) {
projectiles.radius[i] = 1.0f; projectiles.radius[i] = 1.0f;
projectiles.active[i] = false; projectiles.active[i] = false;
projectiles.color[i] = GRAY; 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); 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)) { 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]) { if (!projectiles->active[i]) {
projectiles->active[i] = true; projectiles->active[i] = true;
Player *player = GetPlayer(); Player *player = GetPlayer();
@@ -68,26 +63,29 @@ void UpdateProjectiles(Projectiles *projectiles, Enemies *enemies) {
for (int i = 0; i < projectiles->count; i++) { 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++){ for (int j = 0; j < enemies->count; j++) {
if (CheckCollisionCircleRec(projectiles->physics[i].position, projectiles->radius[i], enemies->sprite[j].destRec)){ if (CheckCollisionCircleRec(projectiles->physics[i].position,
projectiles->radius[i],
enemies->sprite[j].destRec)) {
PlaySound(projectiles->soundImpact[i]); PlaySound(projectiles->soundImpact[i]);
Player *player = GetPlayer(); Player *player = GetPlayer();
player->gold += 1; 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; projectiles->active[i] = false;
} }
} }
UpdatePhysics(&projectiles->physics[i], UpdatePhysics(&projectiles->physics[i], projectiles->physics[i].direction);
projectiles->physics[i].direction);
} }
} }
void RenderProjectiles(Projectiles *projectiles) { void RenderProjectiles(Projectiles *projectiles) {
for (int i = 0; i < projectiles->count; i++) { for (int i = 0; i < projectiles->count; i++) {
if (projectiles->active[i]) { if (projectiles->active[i] == true) {
DrawCircle(projectiles->physics[i].position.x, DrawCircle(projectiles->physics[i].position.x,
projectiles->physics[i].position.y, projectiles->radius[i], projectiles->physics[i].position.y, projectiles->radius[i],
projectiles->color[i]); projectiles->color[i]);
+6 -7
View File
@@ -8,20 +8,19 @@ bool IsVectorZero(Vector2 v) {
Vector2 GetRandomVector(const Rectangle bounds) { Vector2 GetRandomVector(const Rectangle bounds) {
return (Vector2){ return (Vector2){
bounds.x + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.width, bounds.x + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.width,
bounds.y + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.height bounds.y + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.height};
};
} }
Vector2 RotationToVector2(float rotation) Vector2 RotationToVector2(float rotation) {
{
float rad = rotation * (PI / 180.0f); float rad = rotation * (PI / 180.0f);
Vector2 vec = { cosf(rad), sinf(rad) }; Vector2 vec = {cosf(rad), sinf(rad)};
return vec; return vec;
} }
float Vector2ToRotation(Vector2 vec) float Vector2ToRotation(Vector2 vec) {
{
float rad = atan2f(vec.y, vec.x); float rad = atan2f(vec.y, vec.x);
float deg = rad * (180.0f / PI); float deg = rad * (180.0f / PI);
return deg; return deg;
} }
float Cross2D(Vector2 a, Vector2 b) { return a.x * b.y - a.y * b.x; }