big refactor: i see i need header files
This commit is contained in:
@@ -29,11 +29,11 @@ EXTERNAL_FLAGS = \
|
|||||||
$(EXTERNAL_RAYGUI)
|
$(EXTERNAL_RAYGUI)
|
||||||
|
|
||||||
ifeq ($(OS), Windows_NT)
|
ifeq ($(OS), Windows_NT)
|
||||||
SRC = src\main.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_FLAGS = -I%RAYLIB% -L%RAYLIB% -lraylib -lopengl32 -lgdi32 -lwinmm
|
||||||
else
|
else
|
||||||
SRC = src/main.c
|
SRC = $(wildcard src/*.c)
|
||||||
TARGET = bin/osx/game
|
TARGET = bin/osx/game
|
||||||
RAYLIB_FLAGS = $(shell pkg-config --libs --cflags raylib)
|
RAYLIB_FLAGS = $(shell pkg-config --libs --cflags raylib)
|
||||||
endif
|
endif
|
||||||
@@ -47,4 +47,4 @@ clean:
|
|||||||
rm -f $(TARGET)
|
rm -f $(TARGET)
|
||||||
|
|
||||||
run: clean build
|
run: clean build
|
||||||
./$(TARGET)
|
./$(TARGET)
|
||||||
|
|||||||
Vendored
-30
@@ -1,30 +0,0 @@
|
|||||||
#ifndef ASSET_H
|
|
||||||
#define ASSET_H
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char* path;
|
|
||||||
float frameWidth;
|
|
||||||
float frameHeight;
|
|
||||||
float rotation;
|
|
||||||
} TextureAsset;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char* path;
|
|
||||||
} ShaderAsset;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char* path;
|
|
||||||
} SoundtrackAsset;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char* path;
|
|
||||||
} SoundAsset;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const TextureAsset *textureAssets;
|
|
||||||
const ShaderAsset *shaderAssets;
|
|
||||||
const SoundtrackAsset *soundtrackAssets;
|
|
||||||
const SoundAsset *soundAssets;
|
|
||||||
} Assets;
|
|
||||||
|
|
||||||
#endif // ASSET_H
|
|
||||||
Vendored
-21
@@ -1,21 +0,0 @@
|
|||||||
#ifndef ENGINE_H
|
|
||||||
#define ENGINE_H
|
|
||||||
|
|
||||||
#include "animation.h"
|
|
||||||
//#include "array.h"
|
|
||||||
#include "asset.h"
|
|
||||||
#include "camera.h"
|
|
||||||
#include "config.h"
|
|
||||||
#include "gamegui.h"
|
|
||||||
#include "gui.h"
|
|
||||||
#include "input.h"
|
|
||||||
#include "object.h"
|
|
||||||
#include "physics.h"
|
|
||||||
#include "postfx.h"
|
|
||||||
#include "soundtrack.h"
|
|
||||||
#include "sprite.h"
|
|
||||||
#include "vector.h"
|
|
||||||
#include "window.h"
|
|
||||||
#include "font.h"
|
|
||||||
|
|
||||||
#endif //ENGINE_H
|
|
||||||
Vendored
-10
@@ -1,10 +0,0 @@
|
|||||||
#ifndef DISPLAY_H
|
|
||||||
#define DISPLAY_H
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
const char* title;
|
|
||||||
} Window;
|
|
||||||
|
|
||||||
#endif // DISPLAY_H
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#ifndef APPCOLORS_H
|
|
||||||
#define APPCOLORS_H
|
|
||||||
|
|
||||||
#define TEXT_COLOR_DARK (Color){ 182, 137, 98, 255}
|
|
||||||
#define TEXT_COLOR_LIGHT (Color){ 243, 229, 194, 255}
|
|
||||||
|
|
||||||
#endif // APPCOLORS_H
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
#ifndef APPGAMEASSETS_H
|
|
||||||
#define APPGAMEASSETS_H
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
POST_FX,
|
|
||||||
SHADER_COUNT
|
|
||||||
} ShaderID;
|
|
||||||
|
|
||||||
const ShaderAsset shaderAssets[SHADER_COUNT] = {
|
|
||||||
{"shaders/postfx.fs"}};
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
BEE_AMBIENT,
|
|
||||||
SOUNDTRACK_COUNT
|
|
||||||
} SoundtrackID;
|
|
||||||
|
|
||||||
const SoundtrackAsset soundtrackAssets[SOUNDTRACK_COUNT] = {
|
|
||||||
{"assets/sea.mp3"}};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // APPGAMEASSETS_H
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
#ifndef APPMENUASSETS_H
|
|
||||||
#define APPMENUASSETS_H
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
MENU_CURSOR_TEX,
|
|
||||||
MENU_BIG_BUTTONS_TEX,
|
|
||||||
MENU_BOARD_TEX,
|
|
||||||
MENU_CLOUD_BACKGROUND,
|
|
||||||
MENU_CLOUD_MIDGROUND,
|
|
||||||
MENU_CLOUD_FOREGROUND,
|
|
||||||
MENU_TEX_COUNT
|
|
||||||
} MenuTextureID;
|
|
||||||
|
|
||||||
const TextureAsset menuTextureAssets[MENU_TEX_COUNT] = {
|
|
||||||
{"assets/mouse.png", 16.0f, 16.0f, 0.0f},
|
|
||||||
{"assets/buttons.png", 288.0f/3, 96.0f/3, 0.0f},
|
|
||||||
{"assets/menu_board.png", 128.0f, 144.0f, 0.0f},
|
|
||||||
{"assets/cloud_background.png", 576.0f, 324.0f, 0.0f},
|
|
||||||
{"assets/cloud_midground.png", 576.0f, 324.0f, 0.0f},
|
|
||||||
{"assets/cloud_foreground.png", 576.0f, 324.0f, 0.0f}};
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
MENU_MUSIC,
|
|
||||||
MENU_SOUNDTRACK_COUNT
|
|
||||||
} MenuSoundtrackID;
|
|
||||||
|
|
||||||
const SoundtrackAsset menuSoundtrackAssets[MENU_SOUNDTRACK_COUNT] = {
|
|
||||||
{"assets/merrygoround.wav"}};
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
HOVER_SOUND,
|
|
||||||
CLICK_SOUND,
|
|
||||||
MENU_SOUND_COUNT
|
|
||||||
} MenuSoundID;
|
|
||||||
|
|
||||||
const SoundAsset menuSoundAssets[MENU_SOUND_COUNT] = {
|
|
||||||
{"assets/button_hover.wav"},
|
|
||||||
{"assets/button_click.wav"}};
|
|
||||||
|
|
||||||
#endif // APPMENUASSETS_H
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#ifndef APPMENUVIEW_H
|
|
||||||
#define APPMENUVIEW_H
|
|
||||||
|
|
||||||
typedef enum MenuView {
|
|
||||||
MAIN = 0,
|
|
||||||
SETTINGS = 1
|
|
||||||
} MenuView;
|
|
||||||
|
|
||||||
#endif // MENUVIEW_H
|
|
||||||
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#ifndef APPSETTINGS_H
|
|
||||||
#define APPSETTINGS_H
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
bool showFPS;
|
|
||||||
bool soundtrackOn;
|
|
||||||
} Flags;
|
|
||||||
|
|
||||||
#endif // APPSETTINGS_H
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#ifndef APPSTATE_H
|
|
||||||
#define APPSTATE_H
|
|
||||||
|
|
||||||
typedef enum View {
|
|
||||||
LOGO = 0,
|
|
||||||
MENU = 1,
|
|
||||||
GAMEPLAY = 2
|
|
||||||
} View;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
View currentView;
|
|
||||||
bool running;
|
|
||||||
bool gameStarted;
|
|
||||||
} State;
|
|
||||||
|
|
||||||
#endif // APPSTATE_H
|
|
||||||
@@ -0,0 +1,257 @@
|
|||||||
|
#ifndef APPTYPES_H
|
||||||
|
#define APPTYPES_H
|
||||||
|
|
||||||
|
//INCLUDES//
|
||||||
|
#include <raylib.h>
|
||||||
|
#include <engine.h>
|
||||||
|
|
||||||
|
//DEFINES//
|
||||||
|
#define TEXT_COLOR_DARK (Color){ 182, 137, 98, 255}
|
||||||
|
#define TEXT_COLOR_LIGHT (Color){ 243, 229, 194, 255}
|
||||||
|
|
||||||
|
//ENUMS//
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
MENU_CURSOR_TEX,
|
||||||
|
MENU_BIG_BUTTONS_TEX,
|
||||||
|
MENU_BOARD_TEX,
|
||||||
|
MENU_CLOUD_BACKGROUND,
|
||||||
|
MENU_CLOUD_MIDGROUND,
|
||||||
|
MENU_CLOUD_FOREGROUND,
|
||||||
|
MENU_TEX_COUNT
|
||||||
|
} MenuTextureID;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
MENU_MUSIC,
|
||||||
|
MENU_SOUNDTRACK_COUNT
|
||||||
|
} MenuSoundtrackID;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
HOVER_SOUND,
|
||||||
|
CLICK_SOUND,
|
||||||
|
MENU_SOUND_COUNT
|
||||||
|
} MenuSoundID;
|
||||||
|
|
||||||
|
typedef enum MenuView {
|
||||||
|
MAIN = 0,
|
||||||
|
SETTINGS = 1
|
||||||
|
} MenuView;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
START_SHIP,
|
||||||
|
PLAYER_TEX_COUNT
|
||||||
|
} playerTextureID;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ANCHOR,
|
||||||
|
SLOW_AHEAD,
|
||||||
|
FAST_AHEAD,
|
||||||
|
SPEED_COUNT
|
||||||
|
} playerSpeedID;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
FLYING,
|
||||||
|
BIRDS_TEX_COUNT
|
||||||
|
} birdsTextureID;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
ISLAND,
|
||||||
|
ISLANDS_TEX_COUNT
|
||||||
|
} islandsTextureID;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
POST_FX,
|
||||||
|
SHADER_COUNT
|
||||||
|
} ShaderID;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
BEE_AMBIENT,
|
||||||
|
SOUNDTRACK_COUNT
|
||||||
|
} SoundtrackID;
|
||||||
|
|
||||||
|
typedef enum View {
|
||||||
|
LOGO = 0,
|
||||||
|
MENU = 1,
|
||||||
|
GAMEPLAY = 2
|
||||||
|
} View;
|
||||||
|
|
||||||
|
//STRUCTS//
|
||||||
|
typedef struct {
|
||||||
|
int frameCounter;
|
||||||
|
int positionX;
|
||||||
|
int positionY;
|
||||||
|
int lettersCount;
|
||||||
|
int topSideRecWidth;
|
||||||
|
int leftSideRecHeight;
|
||||||
|
int bottomSideRecWidth;
|
||||||
|
int rightSideRecHeight;
|
||||||
|
int state;
|
||||||
|
float alpha;
|
||||||
|
} LogoState;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Sprite sprite;
|
||||||
|
float scrolling;
|
||||||
|
float scale;
|
||||||
|
float scrollSpeed;
|
||||||
|
Vector2 pos;
|
||||||
|
} Background;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Assets assets;
|
||||||
|
Mouse mouse;
|
||||||
|
Texture2D textures[MENU_TEX_COUNT];
|
||||||
|
Sound sounds[MENU_SOUND_COUNT];
|
||||||
|
Soundtrack soundtracks[MENU_SOUNDTRACK_COUNT];
|
||||||
|
ImageElement board;
|
||||||
|
ImageButton playButton;
|
||||||
|
ImageButton quitButton;
|
||||||
|
ImageButton settingsButton;
|
||||||
|
int menuScale;
|
||||||
|
Background background;
|
||||||
|
Background midground;
|
||||||
|
Background foreground;
|
||||||
|
} MenuMain;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Button showFPS;
|
||||||
|
Button soundtrackOn;
|
||||||
|
|
||||||
|
} MenuSettings;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
MenuView menuView;
|
||||||
|
MenuMain menuMain;
|
||||||
|
MenuSettings menuSettings;
|
||||||
|
} MenuState;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Sprite sprite;
|
||||||
|
Rectangle bounds;
|
||||||
|
Shader shader;
|
||||||
|
float time;
|
||||||
|
} Floor;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Sprite sprite;
|
||||||
|
Animation animation;
|
||||||
|
Physics physics;
|
||||||
|
float rotation;
|
||||||
|
} Player;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Sprite sprite;
|
||||||
|
Animation animation;
|
||||||
|
Physics physics;
|
||||||
|
} Birds;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Sprite sprite;
|
||||||
|
Animation animation;
|
||||||
|
Physics physics;
|
||||||
|
} Islands;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Assets assets;
|
||||||
|
PostProcessing postFX[SHADER_COUNT];
|
||||||
|
Soundtrack soundtracks[SOUNDTRACK_COUNT];
|
||||||
|
RenderTexture2D target;
|
||||||
|
Floor floor;
|
||||||
|
Player player;
|
||||||
|
Birds birds;
|
||||||
|
Islands islands;
|
||||||
|
Camera2D camera;
|
||||||
|
Mouse mouse;
|
||||||
|
Image image;
|
||||||
|
} GameState;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
View currentView;
|
||||||
|
bool running;
|
||||||
|
bool gameStarted;
|
||||||
|
} State;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
bool showFPS;
|
||||||
|
bool soundtrackOn;
|
||||||
|
} Flags;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Config config;
|
||||||
|
State state;
|
||||||
|
Flags flags;
|
||||||
|
Window window;
|
||||||
|
Font font;
|
||||||
|
LogoState logo;
|
||||||
|
MenuState menu;
|
||||||
|
GameState game;
|
||||||
|
} App;
|
||||||
|
|
||||||
|
//FUNCTIONS//
|
||||||
|
void InitLogo(LogoState *l);
|
||||||
|
void UpdateLogo(LogoState *l, View *currentView, bool *running);
|
||||||
|
void RenderLogo(const LogoState *l, Flags *flags);
|
||||||
|
|
||||||
|
void InitBackground(float scrollSpeed, Background *bg, Texture2D *texture, const TextureAsset *backgroundAsset);
|
||||||
|
void UpdateBackground(Background *bg);
|
||||||
|
void RenderBackground(Background *bg);
|
||||||
|
|
||||||
|
void InitMenuMain(MenuMain *m);
|
||||||
|
void UpdateMenuMain(MenuMain *m, State *state, Flags *flags, MenuView *menuView);
|
||||||
|
void RenderMenuMain(MenuMain *m, Font *font, const char *title, Flags *flags);
|
||||||
|
void CleanupMenuMain(MenuMain *m);
|
||||||
|
|
||||||
|
void InitMenuSettings(MenuSettings *s);
|
||||||
|
void UpdateMenuSettings(MenuSettings *s, MenuView *menuView, Flags *flags);
|
||||||
|
void RenderMenuSettings(MenuSettings *s, Flags *flags);
|
||||||
|
void CleanupMenuSettings(MenuSettings *s);
|
||||||
|
|
||||||
|
void InitMenu(MenuState *m);
|
||||||
|
void UpdateMenu(MenuState *m, State *state, Flags *flags);
|
||||||
|
void RenderMenu(MenuState *m, Font *font, const char *title, Flags *flags);
|
||||||
|
void CleanupMenu(MenuState *m);
|
||||||
|
|
||||||
|
Floor CreateFloor(void);
|
||||||
|
void UpdateFloor(Floor *floor, const Camera2D *camera);
|
||||||
|
void RenderFloor(Floor *floor);
|
||||||
|
void UnloadFloor(Floor *floor);
|
||||||
|
|
||||||
|
playerSpeedID GetPlayerSpeedID(float speed);
|
||||||
|
Player CreatePlayer(void);
|
||||||
|
void UpdatePlayer(Player *player);
|
||||||
|
void RenderPlayer(Player *player);
|
||||||
|
|
||||||
|
Birds CreateBirds(void);
|
||||||
|
void UpdateBirds(Birds *birds);
|
||||||
|
void RenderBirds(Birds *birds);
|
||||||
|
|
||||||
|
Islands CreateIslands(void);
|
||||||
|
void UpdateIslands(Islands *islands);
|
||||||
|
void RenderIslands(Islands *islands);
|
||||||
|
|
||||||
|
void InitGame(App *app);
|
||||||
|
void UpdateGame(App *app);
|
||||||
|
void RenderComponents(App *app);
|
||||||
|
void RenderGame(App *app);
|
||||||
|
void CleanupGame(App *app);
|
||||||
|
|
||||||
|
void ConfigApp(App *app);
|
||||||
|
void InitApp(App *app);
|
||||||
|
void UpdateApp(App *app);
|
||||||
|
void CleanupApp(App *app);
|
||||||
|
|
||||||
|
#endif //APPTYPES_H
|
||||||
@@ -0,0 +1,232 @@
|
|||||||
|
#ifndef ENGINE_H
|
||||||
|
#define ENGINE_H
|
||||||
|
|
||||||
|
#include <raylib.h>
|
||||||
|
#include <raymath.h>
|
||||||
|
#include <raygui.h>
|
||||||
|
#include <rini.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
} Animation;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void** elements;
|
||||||
|
unsigned int count;
|
||||||
|
unsigned int capacity;
|
||||||
|
} Array;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char* path;
|
||||||
|
float frameWidth;
|
||||||
|
float frameHeight;
|
||||||
|
float rotation;
|
||||||
|
} TextureAsset;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char* path;
|
||||||
|
} ShaderAsset;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char* path;
|
||||||
|
} SoundtrackAsset;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char* path;
|
||||||
|
} SoundAsset;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const TextureAsset *textureAssets;
|
||||||
|
const ShaderAsset *shaderAssets;
|
||||||
|
const SoundtrackAsset *soundtrackAssets;
|
||||||
|
const SoundAsset *soundAssets;
|
||||||
|
} Assets;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *path;
|
||||||
|
rini_config rini;
|
||||||
|
} Config;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
NOT_CLICKED,
|
||||||
|
HOVER,
|
||||||
|
CLICKED
|
||||||
|
} ButtonState;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Sprite sprite;
|
||||||
|
Vector2 notClicked;
|
||||||
|
Vector2 hover;
|
||||||
|
Vector2 clicked;
|
||||||
|
bool isHovered;
|
||||||
|
bool isClicked;
|
||||||
|
} ImageButton;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Sprite sprite;
|
||||||
|
} ImageElement;
|
||||||
|
|
||||||
|
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;
|
||||||
|
} Mouse;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Sprite sprite;
|
||||||
|
Vector2 position;
|
||||||
|
} Object;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Object *data;
|
||||||
|
const Object *prototype;
|
||||||
|
size_t count;
|
||||||
|
} ObjectArray;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Vector2 position;
|
||||||
|
Vector2 direction;
|
||||||
|
Vector2 velocity;
|
||||||
|
float speed;
|
||||||
|
} Physics;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Shader shader;
|
||||||
|
int resolutionLoc;
|
||||||
|
int strengthLoc;
|
||||||
|
float strength;
|
||||||
|
} PostProcessing;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Music music;
|
||||||
|
bool playing;
|
||||||
|
bool paused;
|
||||||
|
} Soundtrack;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Vector2 *data;
|
||||||
|
size_t count;
|
||||||
|
} Vector2Array;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
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);
|
||||||
|
|
||||||
|
Camera2D CreateCamera(Vector2 playerPosition, float initZoom);
|
||||||
|
void UpdateCameraTarget(Camera2D *camera, Vector2 *position, const float smoothness);
|
||||||
|
void UpdateCameraZoom(Camera2D *camera, const float *scaleFactor, const float *minZoom, const float *maxZoom);
|
||||||
|
void UpdateCamera2D(Camera2D* camera, Vector2* position, Mouse* mouse);
|
||||||
|
|
||||||
|
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);
|
||||||
|
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 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 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);
|
||||||
|
int isImageButtonClicked(ImageButton *b, Sound soundHover, Sound soundClick);
|
||||||
|
void renderImageButton(ImageButton *b);
|
||||||
|
void renderImageElement(ImageElement *e);
|
||||||
|
|
||||||
|
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);
|
||||||
|
void UpdateMouseScreen(Mouse *mouse);
|
||||||
|
void UpdateMouse(Mouse *mouse, Camera2D *camera);
|
||||||
|
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);
|
||||||
|
void RenderObjectArray(const ObjectArray *objects);
|
||||||
|
|
||||||
|
void UpdatePhysicsDirection(Vector2 *direction, Vector2 vector);
|
||||||
|
void UpdatePhysicsVelocity(Vector2 *velocity, Vector2 *direction, float *speed);
|
||||||
|
void UpdatePhysicsPosition(Vector2 *position, Vector2 *velocity);
|
||||||
|
void UpdatePhysicsSpeed(float *speed, float *newSpeed);
|
||||||
|
void UpdatePhysics(Physics *physics, Vector2 direction);
|
||||||
|
|
||||||
|
PostProcessing CreatePostFX(const char* shaderPath);
|
||||||
|
void UpdatePostFX(PostProcessing *postFX);
|
||||||
|
void RenderPostFX(PostProcessing *postFX, RenderTexture2D *target);
|
||||||
|
void UnloadPostFX(PostProcessing *postFX);
|
||||||
|
|
||||||
|
Soundtrack LoadSoundtrack(const char* musicPath);
|
||||||
|
void UpdateSoundtrack(Soundtrack *soundtrack, bool playing);
|
||||||
|
|
||||||
|
void UpdateSpriteSourceRec(Sprite *sprite, const Vector2 *vector);
|
||||||
|
void UpdateSpriteDestRec(Sprite *sprite, const Vector2 *vector);
|
||||||
|
void UpdateSpriteRotation(Sprite *sprite, Vector2 *vector);
|
||||||
|
void RenderSprite(const Sprite *sprite);
|
||||||
|
void PrintSprite(const Sprite *sprite);
|
||||||
|
|
||||||
|
bool IsVectorZero(Vector2 v);
|
||||||
|
Vector2 GetRandomVector(const Rectangle bounds);
|
||||||
|
|
||||||
|
#endif //ENGINE_H
|
||||||
|
|
||||||
@@ -1,26 +1,6 @@
|
|||||||
#ifndef APP_H
|
|
||||||
#define APP_H
|
|
||||||
|
|
||||||
#include <engine.h>
|
#include <engine.h>
|
||||||
|
|
||||||
#include "appState.h"
|
#include "appTypes.h"
|
||||||
#include "appSettings.h"
|
|
||||||
#include "appColors.h"
|
|
||||||
|
|
||||||
#include "appLogo.h"
|
|
||||||
#include "appMenu.h"
|
|
||||||
#include "appGame.h"
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Config config;
|
|
||||||
State state;
|
|
||||||
Flags flags;
|
|
||||||
Window window;
|
|
||||||
Font font;
|
|
||||||
LogoState logo;
|
|
||||||
MenuState menu;
|
|
||||||
GameState game;
|
|
||||||
} App;
|
|
||||||
|
|
||||||
void ConfigApp(App* app){
|
void ConfigApp(App* app){
|
||||||
InitConfig(&app->config, "config/config.ini");
|
InitConfig(&app->config, "config/config.ini");
|
||||||
@@ -36,7 +16,7 @@ void InitApp(App *app){
|
|||||||
InitFont(&app->font, "assets/font.fnt");
|
InitFont(&app->font, "assets/font.fnt");
|
||||||
InitLogo(&app->logo);
|
InitLogo(&app->logo);
|
||||||
InitMenu(&app->menu);
|
InitMenu(&app->menu);
|
||||||
InitGame(&app->game,&app->window);
|
InitGame(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateApp(App *app){
|
void UpdateApp(App *app){
|
||||||
@@ -60,8 +40,8 @@ void UpdateApp(App *app){
|
|||||||
}break;
|
}break;
|
||||||
case GAMEPLAY:
|
case GAMEPLAY:
|
||||||
{
|
{
|
||||||
UpdateGame(&app->game, &app->state, &app->flags);
|
UpdateGame(app);
|
||||||
RenderGame(&app->game, &app->state, &app->flags);
|
RenderGame(app);
|
||||||
}break;
|
}break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
@@ -70,9 +50,8 @@ void UpdateApp(App *app){
|
|||||||
|
|
||||||
void CleanupApp(App *app){
|
void CleanupApp(App *app){
|
||||||
CleanupMenu(&app->menu);
|
CleanupMenu(&app->menu);
|
||||||
CleanupGame(&app->game);
|
CleanupGame(app);
|
||||||
CleanupFont(&app->font);
|
CleanupFont(&app->font);
|
||||||
CleanUpConfig(&app->config);
|
CleanUpConfig(&app->config);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //APP_H
|
|
||||||
@@ -1,30 +1,17 @@
|
|||||||
#ifndef APPGAME_H
|
#include "appTypes.h"
|
||||||
#define APPGAME_H
|
|
||||||
|
const ShaderAsset shaderAssets[SHADER_COUNT] = {
|
||||||
|
{"shaders/postfx.fs"}};
|
||||||
|
|
||||||
|
|
||||||
#include "appGameFloor.h"
|
|
||||||
#include "appGamePlayer.h"
|
|
||||||
#include "appGameBirds.h"
|
|
||||||
#include "appGameIslands.h"
|
|
||||||
#include "appGameAssets.h"
|
|
||||||
|
|
||||||
typedef struct
|
const SoundtrackAsset soundtrackAssets[SOUNDTRACK_COUNT] = {
|
||||||
{
|
{"assets/sea.mp3"}};
|
||||||
Assets assets;
|
|
||||||
PostProcessing postFX[SHADER_COUNT];
|
|
||||||
Soundtrack soundtracks[SOUNDTRACK_COUNT];
|
|
||||||
RenderTexture2D target;
|
|
||||||
Floor floor;
|
|
||||||
Player player;
|
|
||||||
Birds birds;
|
|
||||||
Islands islands;
|
|
||||||
Camera2D camera;
|
|
||||||
Mouse mouse;
|
|
||||||
Image image;
|
|
||||||
} GameState;
|
|
||||||
|
|
||||||
void InitGame(GameState *g, Window *window)
|
|
||||||
|
void InitGame(App *app)
|
||||||
{
|
{
|
||||||
|
GameState *g = &app->game;
|
||||||
g->assets = (Assets){
|
g->assets = (Assets){
|
||||||
.shaderAssets = shaderAssets,
|
.shaderAssets = shaderAssets,
|
||||||
.soundtrackAssets = soundtrackAssets
|
.soundtrackAssets = soundtrackAssets
|
||||||
@@ -40,7 +27,7 @@ void InitGame(GameState *g, Window *window)
|
|||||||
g->soundtracks[i] = LoadSoundtrack(g->assets.soundtrackAssets[i].path);
|
g->soundtracks[i] = LoadSoundtrack(g->assets.soundtrackAssets[i].path);
|
||||||
}
|
}
|
||||||
|
|
||||||
g->target = LoadRenderTexture(window->width, window->height);
|
g->target = LoadRenderTexture(app->window.width, app->window.height);
|
||||||
g->player = CreatePlayer();
|
g->player = CreatePlayer();
|
||||||
g->birds = CreateBirds();
|
g->birds = CreateBirds();
|
||||||
g->islands = CreateIslands();
|
g->islands = CreateIslands();
|
||||||
@@ -51,10 +38,11 @@ void InitGame(GameState *g, Window *window)
|
|||||||
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &mouseTexture);
|
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &mouseTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateGame(GameState *g, State *state, Flags *flags)
|
void UpdateGame(App *app)
|
||||||
{
|
{
|
||||||
if(!state->gameStarted){
|
GameState *g = &app->game;
|
||||||
state->gameStarted = true;
|
if(!app->state.gameStarted){
|
||||||
|
app->state.gameStarted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetFPS() <= 60)
|
if (GetFPS() <= 60)
|
||||||
@@ -64,12 +52,12 @@ void UpdateGame(GameState *g, State *state, Flags *flags)
|
|||||||
|
|
||||||
if (IsKeyPressed(KEY_ESCAPE))
|
if (IsKeyPressed(KEY_ESCAPE))
|
||||||
{
|
{
|
||||||
state->currentView = MENU;
|
app->state.currentView = MENU;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE))
|
if (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE))
|
||||||
{
|
{
|
||||||
state->running = false;
|
app->state.running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < SHADER_COUNT; i++)
|
for (int i = 0; i < SHADER_COUNT; i++)
|
||||||
@@ -78,7 +66,7 @@ void UpdateGame(GameState *g, State *state, Flags *flags)
|
|||||||
}
|
}
|
||||||
for (int i = 0; i < SOUNDTRACK_COUNT; i++)
|
for (int i = 0; i < SOUNDTRACK_COUNT; i++)
|
||||||
{
|
{
|
||||||
UpdateSoundtrack(&g->soundtracks[i], flags->soundtrackOn);
|
UpdateSoundtrack(&g->soundtracks[i], app->flags.soundtrackOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateMouse(&g->mouse, &g->camera);
|
UpdateMouse(&g->mouse, &g->camera);
|
||||||
@@ -89,22 +77,31 @@ void UpdateGame(GameState *g, State *state, Flags *flags)
|
|||||||
UpdateIslands(&g->islands);
|
UpdateIslands(&g->islands);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderComponents(GameState *g)
|
void RenderComponents(App *app)
|
||||||
{
|
{
|
||||||
|
GameState *g = &app->game;
|
||||||
RenderFloor(&g->floor);
|
RenderFloor(&g->floor);
|
||||||
RenderPlayer(&g->player);
|
RenderPlayer(&g->player);
|
||||||
RenderBirds(&g->birds);
|
RenderBirds(&g->birds);
|
||||||
RenderIslands(&g->islands);
|
RenderIslands(&g->islands);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderGame(GameState *g, const State *appState, Flags *flags)
|
void RenderGame(App *app)
|
||||||
{
|
{
|
||||||
|
GameState *g = &app->game;
|
||||||
|
|
||||||
BeginTextureMode(g->target);
|
BeginTextureMode(g->target);
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
BeginMode2D(g->camera);
|
BeginMode2D(g->camera);
|
||||||
RenderComponents(g);
|
RenderComponents(app);
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
DrawTextureRec(g->mouse.cursorTexture, (Rectangle){0, 0, g->mouse.cursorTexture.width, g->mouse.cursorTexture.height}, (Vector2){g->mouse.screenPosition.x, g->mouse.screenPosition.y}, WHITE);
|
DrawTextureRec
|
||||||
|
(
|
||||||
|
g->mouse.cursorTexture,
|
||||||
|
(Rectangle){0, 0, g->mouse.cursorTexture.width, g->mouse.cursorTexture.height},
|
||||||
|
(Vector2){g->mouse.screenPosition.x, g->mouse.screenPosition.y},
|
||||||
|
WHITE
|
||||||
|
);
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
@@ -114,7 +111,7 @@ void RenderGame(GameState *g, const State *appState, Flags *flags)
|
|||||||
RenderPostFX(&g->postFX[i], &g->target);
|
RenderPostFX(&g->postFX[i], &g->target);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags->showFPS)
|
if (app->flags.showFPS)
|
||||||
{
|
{
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
}
|
}
|
||||||
@@ -122,8 +119,9 @@ void RenderGame(GameState *g, const State *appState, Flags *flags)
|
|||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CleanupGame(GameState *g)
|
void CleanupGame(App *app)
|
||||||
{
|
{
|
||||||
|
GameState *g = &app->game;
|
||||||
for (int i = 0; i < SHADER_COUNT; i++)
|
for (int i = 0; i < SHADER_COUNT; i++)
|
||||||
{
|
{
|
||||||
UnloadPostFX(&g->postFX[i]);
|
UnloadPostFX(&g->postFX[i]);
|
||||||
@@ -135,4 +133,3 @@ void CleanupGame(GameState *g)
|
|||||||
UnloadRenderTexture(g->target);
|
UnloadRenderTexture(g->target);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // APPGAME_H
|
|
||||||
@@ -1,17 +1,4 @@
|
|||||||
#ifndef APPGAMEBIRDS_H
|
#include "appTypes.h"
|
||||||
#define APPGAMEBIRDS_H
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Sprite sprite;
|
|
||||||
Animation animation;
|
|
||||||
Physics physics;
|
|
||||||
} Birds;
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
FLYING,
|
|
||||||
BIRDS_TEX_COUNT
|
|
||||||
} birdsTextureID;
|
|
||||||
|
|
||||||
const TextureAsset birdsTextureAssets[BIRDS_TEX_COUNT] = {
|
const TextureAsset birdsTextureAssets[BIRDS_TEX_COUNT] = {
|
||||||
{"assets/birds.png", 16.0f, 16.0f, 45.0f}
|
{"assets/birds.png", 16.0f, 16.0f, 45.0f}
|
||||||
@@ -68,4 +55,3 @@ void RenderBirds(Birds *birds){
|
|||||||
RenderSprite(&birds->sprite);
|
RenderSprite(&birds->sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // APPGAMEBIRDS_H
|
|
||||||
@@ -1,14 +1,4 @@
|
|||||||
#ifndef APPGAMEFloor_H
|
#include "appTypes.h"
|
||||||
#define APPGAMEFloor_H
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
Sprite sprite;
|
|
||||||
Rectangle bounds;
|
|
||||||
Shader shader;
|
|
||||||
float time;
|
|
||||||
} Floor;
|
|
||||||
|
|
||||||
Floor CreateFloor(void)
|
Floor CreateFloor(void)
|
||||||
{
|
{
|
||||||
@@ -98,5 +88,3 @@ void UnloadFloor(Floor *floor)
|
|||||||
UnloadShader(floor->shader);
|
UnloadShader(floor->shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // APPGAMEFLOOR_H
|
|
||||||
|
|
||||||
@@ -1,17 +1,4 @@
|
|||||||
#ifndef APPGAMEISLANDS_H
|
#include "appTypes.h"
|
||||||
#define APPGAMEISLANDS_H
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Sprite sprite;
|
|
||||||
Animation animation;
|
|
||||||
Physics physics;
|
|
||||||
} Islands;
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
ISLAND,
|
|
||||||
ISLANDS_TEX_COUNT
|
|
||||||
} islandsTextureID;
|
|
||||||
|
|
||||||
const TextureAsset islandsTextureAssets[ISLANDS_TEX_COUNT] = {
|
const TextureAsset islandsTextureAssets[ISLANDS_TEX_COUNT] = {
|
||||||
{"assets/island.png", 16.0f, 16.0f, 0.0f}
|
{"assets/island.png", 16.0f, 16.0f, 0.0f}
|
||||||
@@ -58,5 +45,3 @@ void RenderIslands(Islands *islands){
|
|||||||
RenderSprite(&islands->sprite);
|
RenderSprite(&islands->sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // APPGAMEISLANDS_H
|
|
||||||
|
|
||||||
@@ -1,22 +1,10 @@
|
|||||||
#ifndef APPGAMEPLAYER_H
|
#include "appTypes.h"
|
||||||
#define APPGAMEPLAYER_H
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
START_SHIP,
|
|
||||||
PLAYER_TEX_COUNT
|
|
||||||
} playerTextureID;
|
|
||||||
|
|
||||||
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}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
ANCHOR,
|
|
||||||
SLOW_AHEAD,
|
|
||||||
FAST_AHEAD,
|
|
||||||
SPEED_COUNT
|
|
||||||
} playerSpeedID;
|
|
||||||
|
|
||||||
float playerSpeeds[SPEED_COUNT] = {
|
float playerSpeeds[SPEED_COUNT] = {
|
||||||
0.0f,
|
0.0f,
|
||||||
@@ -33,15 +21,6 @@ playerSpeedID GetPlayerSpeedID(float speed) {
|
|||||||
return ANCHOR;
|
return ANCHOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
Sprite sprite;
|
|
||||||
Animation animation;
|
|
||||||
Physics physics;
|
|
||||||
float rotation;
|
|
||||||
} Player;
|
|
||||||
|
|
||||||
Player CreatePlayer(void)
|
Player CreatePlayer(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -142,4 +121,3 @@ void RenderPlayer(Player *player){
|
|||||||
RenderSprite(&player->sprite);
|
RenderSprite(&player->sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // APPGAMEPLAYER_H
|
|
||||||
@@ -1,18 +1,4 @@
|
|||||||
#ifndef APPLOGO_H
|
#include "appTypes.h"
|
||||||
#define APPLOGO_H
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int frameCounter;
|
|
||||||
int positionX;
|
|
||||||
int positionY;
|
|
||||||
int lettersCount;
|
|
||||||
int topSideRecWidth;
|
|
||||||
int leftSideRecHeight;
|
|
||||||
int bottomSideRecWidth;
|
|
||||||
int rightSideRecHeight;
|
|
||||||
int state;
|
|
||||||
float alpha;
|
|
||||||
} LogoState;
|
|
||||||
|
|
||||||
void InitLogo(LogoState *l) {
|
void InitLogo(LogoState *l) {
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
@@ -114,4 +100,3 @@ void RenderLogo(const LogoState *l, Flags *flags) {
|
|||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // APPLOGO_H
|
|
||||||
@@ -1,16 +1,4 @@
|
|||||||
#ifndef APPMENU_H
|
#include "appTypes.h"
|
||||||
#define APPMENU_H
|
|
||||||
|
|
||||||
#include <appMenuView.h>
|
|
||||||
#include <appMenuSettings.h>
|
|
||||||
#include <appMenuMain.h>
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
MenuView menuView;
|
|
||||||
MenuMain menuMain;
|
|
||||||
MenuSettings menuSettings;
|
|
||||||
} MenuState;
|
|
||||||
|
|
||||||
void InitMenu(MenuState *m)
|
void InitMenu(MenuState *m)
|
||||||
{
|
{
|
||||||
@@ -59,4 +47,3 @@ void CleanupMenu(MenuState *m)
|
|||||||
CleanupMenuMain(&m->menuMain);
|
CleanupMenuMain(&m->menuMain);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // APPMENU_H
|
|
||||||
@@ -1,25 +1,23 @@
|
|||||||
#ifndef APPMENUMAIN_H
|
#include "appTypes.h"
|
||||||
#define APPMENUMAIN_H
|
|
||||||
|
|
||||||
#include "appMenuAssets.h"
|
|
||||||
#include "appMenuView.h"
|
|
||||||
#include "appMenuMainBackground.h"
|
|
||||||
|
|
||||||
typedef struct {
|
const TextureAsset menuTextureAssets[MENU_TEX_COUNT] = {
|
||||||
Assets assets;
|
{"assets/mouse.png", 16.0f, 16.0f, 0.0f},
|
||||||
Mouse mouse;
|
{"assets/buttons.png", 288.0f/3, 96.0f/3, 0.0f},
|
||||||
Texture2D textures[MENU_TEX_COUNT];
|
{"assets/menu_board.png", 128.0f, 144.0f, 0.0f},
|
||||||
Sound sounds[MENU_SOUND_COUNT];
|
{"assets/cloud_background.png", 576.0f, 324.0f, 0.0f},
|
||||||
Soundtrack soundtracks[MENU_SOUNDTRACK_COUNT];
|
{"assets/cloud_midground.png", 576.0f, 324.0f, 0.0f},
|
||||||
ImageElement board;
|
{"assets/cloud_foreground.png", 576.0f, 324.0f, 0.0f}};
|
||||||
ImageButton playButton;
|
|
||||||
ImageButton quitButton;
|
|
||||||
ImageButton settingsButton;
|
const SoundtrackAsset menuSoundtrackAssets[MENU_SOUNDTRACK_COUNT] = {
|
||||||
int menuScale;
|
{"assets/merrygoround.wav"}};
|
||||||
Background background;
|
|
||||||
Background midground;
|
|
||||||
Background foreground;
|
const SoundAsset menuSoundAssets[MENU_SOUND_COUNT] = {
|
||||||
} MenuMain;
|
{"assets/button_hover.wav"},
|
||||||
|
{"assets/button_click.wav"}};
|
||||||
|
|
||||||
|
|
||||||
void InitMenuMain(MenuMain *m){
|
void InitMenuMain(MenuMain *m){
|
||||||
|
|
||||||
@@ -208,4 +206,3 @@ void CleanupMenuMain(MenuMain *m){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //APPMENUMAIN_H
|
|
||||||
@@ -1,13 +1,4 @@
|
|||||||
#ifndef APPMENUMAINBACKGROUND_H
|
#include "appTypes.h"
|
||||||
#define APPMENUMAINBACKGROUND_H
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Sprite sprite;
|
|
||||||
float scrolling;
|
|
||||||
float scale;
|
|
||||||
float scrollSpeed;
|
|
||||||
Vector2 pos;
|
|
||||||
} Background;
|
|
||||||
|
|
||||||
void InitBackground(float scrollSpeed, Background *bg, Texture2D *texture, const TextureAsset *backgroundAsset){
|
void InitBackground(float scrollSpeed, Background *bg, Texture2D *texture, const TextureAsset *backgroundAsset){
|
||||||
bg->scrolling = 0.0f;
|
bg->scrolling = 0.0f;
|
||||||
@@ -65,4 +56,3 @@ void RenderBackground(Background *bg){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // APPMENUMAINBACKGROUND_H
|
|
||||||
@@ -1,13 +1,4 @@
|
|||||||
#ifndef APPMENUSETTINGS_H
|
#include "appTypes.h"
|
||||||
#define APPMENUSETTINGS_H
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
Button showFPS;
|
|
||||||
Button soundtrackOn;
|
|
||||||
|
|
||||||
} MenuSettings;
|
|
||||||
|
|
||||||
void InitMenuSettings(MenuSettings *s)
|
void InitMenuSettings(MenuSettings *s)
|
||||||
{
|
{
|
||||||
@@ -65,4 +56,3 @@ void ClenupMenuSettings(MenuSettings *s){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // APPMENUSETTINGS_H
|
|
||||||
@@ -1,14 +1,4 @@
|
|||||||
#ifndef ANIMATION_H
|
#include "engine.h"
|
||||||
#define ANIMATION_H
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int state;
|
|
||||||
int currentFrame;
|
|
||||||
int maxFrame;
|
|
||||||
int framesCounter;
|
|
||||||
int framesSpeed;
|
|
||||||
float animTimer;
|
|
||||||
} Animation;
|
|
||||||
|
|
||||||
void UpdateAnimation(Animation *animation, float deltaTime) {
|
void UpdateAnimation(Animation *animation, float deltaTime) {
|
||||||
animation->animTimer += deltaTime;
|
animation->animTimer += deltaTime;
|
||||||
@@ -25,5 +15,3 @@ void UpdateAnimation(Animation *animation, float deltaTime) {
|
|||||||
animation->currentFrame = 0;
|
animation->currentFrame = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ANIMATION_H
|
|
||||||
@@ -1,13 +1,7 @@
|
|||||||
#ifndef ARRAY_H
|
#include "engine.h"
|
||||||
#define ARRAY_H
|
|
||||||
|
|
||||||
typedef struct {
|
Array* CreateArray(unsigned int initCapacity)
|
||||||
void** elements;
|
{
|
||||||
unsigned int count;
|
|
||||||
unsigned int capacity;
|
|
||||||
} Array;
|
|
||||||
|
|
||||||
Array* CreateArray(unsigned int initCapacity){
|
|
||||||
Array* array = malloc(sizeof(Array));
|
Array* array = malloc(sizeof(Array));
|
||||||
if (!array) return NULL;
|
if (!array) return NULL;
|
||||||
|
|
||||||
@@ -22,7 +16,8 @@ Array* CreateArray(unsigned int initCapacity){
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AddElementToArray(Array* array, void* element){
|
int AddElementToArray(Array* array, void* element)
|
||||||
|
{
|
||||||
if(array->count >= array->capacity) {
|
if(array->count >= array->capacity) {
|
||||||
unsigned int newCapacity = array->capacity * 2;
|
unsigned int newCapacity = array->capacity * 2;
|
||||||
void** newElements = realloc(array->elements, sizeof(void*) * newCapacity);
|
void** newElements = realloc(array->elements, sizeof(void*) * newCapacity);
|
||||||
@@ -48,7 +43,8 @@ int AddElementToArray(Array* array, void* element){
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// SWAP AND POP REMOVE
|
// SWAP AND POP REMOVE
|
||||||
int RemoveElementFromArray(Array* array, unsigned int index) {
|
int RemoveElementFromArray(Array* array, unsigned int index)
|
||||||
|
{
|
||||||
if (index >= array->count) return 0;
|
if (index >= array->count) return 0;
|
||||||
|
|
||||||
array->elements[index] = array->elements[array->count - 1];
|
array->elements[index] = array->elements[array->count - 1];
|
||||||
@@ -58,7 +54,8 @@ int RemoveElementFromArray(Array* array, unsigned int index) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* GetRandomElementFromArray(Array* array){
|
void* GetRandomElementFromArray(Array* array)
|
||||||
|
{
|
||||||
if (array == NULL || array->elements == NULL || array->count == 0) {
|
if (array == NULL || array->elements == NULL || array->count == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -82,7 +79,8 @@ void RenderArray(Array* array, void (*renderFunc)(void*))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreeArray(Array** array) {
|
void FreeArray(Array** array)
|
||||||
|
{
|
||||||
if (!array || !*array) return;
|
if (!array || !*array) return;
|
||||||
|
|
||||||
free((*array)->elements);
|
free((*array)->elements);
|
||||||
@@ -92,5 +90,3 @@ void FreeArray(Array** array) {
|
|||||||
*array = NULL;
|
*array = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // ARRAY_H
|
|
||||||
@@ -1,8 +1,4 @@
|
|||||||
#ifndef CAMERA_H
|
#include "engine.h"
|
||||||
#define CAMERA_H
|
|
||||||
|
|
||||||
#include "input.h"
|
|
||||||
#include <raymath.h>
|
|
||||||
|
|
||||||
Camera2D CreateCamera(Vector2 playerPosition, float initZoom){
|
Camera2D CreateCamera(Vector2 playerPosition, float initZoom){
|
||||||
int windowWidth = GetScreenWidth();
|
int windowWidth = GetScreenWidth();
|
||||||
@@ -29,5 +25,3 @@ void UpdateCamera2D(Camera2D* camera, Vector2* position, Mouse* mouse){
|
|||||||
UpdateCameraZoom(camera, &mouse->scaleFactor, &mouse->minZoom, &mouse->maxZoom);
|
UpdateCameraZoom(camera, &mouse->scaleFactor, &mouse->minZoom, &mouse->maxZoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // CAMERA_H
|
|
||||||
@@ -1,16 +1,7 @@
|
|||||||
#ifndef CONFIG_H
|
|
||||||
#define CONFIG_H
|
|
||||||
|
|
||||||
#define RINI_IMPLEMENTATION
|
#define RINI_IMPLEMENTATION
|
||||||
#define RINI_VALUE_DELIMITER '='
|
#define RINI_VALUE_DELIMITER '='
|
||||||
|
|
||||||
#include <rini.h>
|
#include "engine.h"
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char *path;
|
|
||||||
rini_config rini;
|
|
||||||
} Config;
|
|
||||||
|
|
||||||
void InitConfig(Config *config, const char* path) {
|
void InitConfig(Config *config, const char* path) {
|
||||||
config->rini = rini_load_config(path);
|
config->rini = rini_load_config(path);
|
||||||
@@ -63,4 +54,3 @@ void CleanUpConfig(Config *config) {
|
|||||||
rini_unload_config(&config->rini);
|
rini_unload_config(&config->rini);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CONFIG_H
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
#ifndef FONT_H
|
#include "engine.h"
|
||||||
#define FONT_H
|
|
||||||
|
|
||||||
void InitFont(Font *font, const char* path){
|
void InitFont(Font *font, const char* path){
|
||||||
*font = LoadFont(path);
|
*font = LoadFont(path);
|
||||||
@@ -10,4 +9,3 @@ void CleanupFont(Font *font){
|
|||||||
UnloadFont(*font);
|
UnloadFont(*font);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //FONT_H
|
|
||||||
@@ -1,29 +1,4 @@
|
|||||||
#ifndef GAMEGUI_H
|
#include "engine.h"
|
||||||
#define GAMEGUI_H
|
|
||||||
|
|
||||||
#include "sprite.h"
|
|
||||||
#include <raylib.h>
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
NOT_CLICKED,
|
|
||||||
HOVER,
|
|
||||||
CLICKED
|
|
||||||
} ButtonState;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
Sprite sprite;
|
|
||||||
Vector2 notClicked;
|
|
||||||
Vector2 hover;
|
|
||||||
Vector2 clicked;
|
|
||||||
bool isHovered;
|
|
||||||
bool isClicked;
|
|
||||||
} ImageButton;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
Sprite sprite;
|
|
||||||
} ImageElement;
|
|
||||||
|
|
||||||
ImageButton CreateImageButton(ButtonState state, Texture2D *texture, const TextureAsset *asset, Vector2 *source, Vector2 *clicked, Vector2 *hover, Rectangle *destRec){
|
ImageButton CreateImageButton(ButtonState state, Texture2D *texture, const TextureAsset *asset, Vector2 *source, Vector2 *clicked, Vector2 *hover, Rectangle *destRec){
|
||||||
return (ImageButton){
|
return (ImageButton){
|
||||||
@@ -95,5 +70,3 @@ void renderImageElement(ImageElement *e){
|
|||||||
RenderSprite(&e->sprite);
|
RenderSprite(&e->sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // GAMEGUI_H
|
|
||||||
@@ -1,14 +1,6 @@
|
|||||||
#ifndef GUI_H
|
|
||||||
#define GUI_H
|
|
||||||
|
|
||||||
#define RAYGUI_IMPLEMENTATION
|
#define RAYGUI_IMPLEMENTATION
|
||||||
#include <raygui.h>
|
|
||||||
|
|
||||||
typedef struct
|
#include "engine.h"
|
||||||
{
|
|
||||||
Rectangle rec;
|
|
||||||
char *text;
|
|
||||||
} Button;
|
|
||||||
|
|
||||||
Button initButton(char *text, Vector2 dimensions, Vector2 position)
|
Button initButton(char *text, Vector2 dimensions, Vector2 position)
|
||||||
{
|
{
|
||||||
@@ -29,4 +21,3 @@ void renderButton(Button *b)
|
|||||||
GuiButton(b->rec, b->text);
|
GuiButton(b->rec, b->text);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // GUI_H
|
|
||||||
@@ -1,20 +1,4 @@
|
|||||||
#ifndef INPUT_H
|
#include "engine.h"
|
||||||
#define INPUT_H
|
|
||||||
|
|
||||||
#include <raymath.h>
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Vector2 screenPosition;
|
|
||||||
Vector2 worldPosition;
|
|
||||||
float zoomSpeed;
|
|
||||||
float minZoom;
|
|
||||||
float maxZoom;
|
|
||||||
float scaleFactor;
|
|
||||||
float wheelMove;
|
|
||||||
bool leftButton;
|
|
||||||
bool rightButton;
|
|
||||||
Texture2D cursorTexture;
|
|
||||||
} Mouse;
|
|
||||||
|
|
||||||
Mouse CreateMouse(float zoomSpeed, float minZoom, float maxZoom, Texture2D *texture){
|
Mouse CreateMouse(float zoomSpeed, float minZoom, float maxZoom, Texture2D *texture){
|
||||||
HideCursor();
|
HideCursor();
|
||||||
@@ -57,5 +41,3 @@ Vector2 GetDirectionVector(void){
|
|||||||
if (Vector2Length(vector) > 0.0f) {vector = Vector2Normalize(vector); }
|
if (Vector2Length(vector) > 0.0f) {vector = Vector2Normalize(vector); }
|
||||||
return vector;
|
return vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //INPUT_H
|
|
||||||
@@ -1,19 +1,4 @@
|
|||||||
#ifndef OBJECT_H
|
#include "engine.h"
|
||||||
#define OBJECT_H
|
|
||||||
#include "sprite.h"
|
|
||||||
#include "vector.h"
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Sprite sprite;
|
|
||||||
Vector2 position;
|
|
||||||
} Object;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Object *data;
|
|
||||||
const Object *prototype;
|
|
||||||
size_t count;
|
|
||||||
} ObjectArray;
|
|
||||||
|
|
||||||
ObjectArray CreateObjectArray(const Object *prototype, const size_t count) {
|
ObjectArray CreateObjectArray(const Object *prototype, const size_t count) {
|
||||||
ObjectArray objects = {0};
|
ObjectArray objects = {0};
|
||||||
@@ -126,4 +111,3 @@ void RenderObjectArray(const ObjectArray *objects){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // OBJECT_H
|
|
||||||
@@ -1,15 +1,4 @@
|
|||||||
#ifndef PHYSICS_H
|
#include "engine.h"
|
||||||
#define PHYSICS_H
|
|
||||||
|
|
||||||
#include <raymath.h>
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
Vector2 position;
|
|
||||||
Vector2 direction;
|
|
||||||
Vector2 velocity;
|
|
||||||
float speed;
|
|
||||||
} Physics;
|
|
||||||
|
|
||||||
void UpdatePhysicsDirection(Vector2 *direction, Vector2 vector)
|
void UpdatePhysicsDirection(Vector2 *direction, Vector2 vector)
|
||||||
{
|
{
|
||||||
@@ -38,4 +27,3 @@ void UpdatePhysics(Physics *physics, Vector2 direction)
|
|||||||
UpdatePhysicsPosition(&physics->position, &physics->velocity);
|
UpdatePhysicsPosition(&physics->position, &physics->velocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // PHYSICS_H
|
|
||||||
@@ -1,12 +1,4 @@
|
|||||||
#ifndef POSTFX_H
|
#include "engine.h"
|
||||||
#define POSTFX_H
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Shader shader;
|
|
||||||
int resolutionLoc;
|
|
||||||
int strengthLoc;
|
|
||||||
float strength;
|
|
||||||
} PostProcessing;
|
|
||||||
|
|
||||||
PostProcessing CreatePostFX(const char* shaderPath){
|
PostProcessing CreatePostFX(const char* shaderPath){
|
||||||
PostProcessing postFX = {0};
|
PostProcessing postFX = {0};
|
||||||
@@ -42,5 +34,3 @@ void UnloadPostFX(PostProcessing *postFX){
|
|||||||
if (postFX->shader.id == 0) return;
|
if (postFX->shader.id == 0) return;
|
||||||
UnloadShader(postFX->shader);
|
UnloadShader(postFX->shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // POSTFX_H
|
|
||||||
@@ -1,11 +1,4 @@
|
|||||||
#ifndef SOUNDTRACK_H
|
#include "engine.h"
|
||||||
#define SOUNDTRACK_H
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Music music;
|
|
||||||
bool playing;
|
|
||||||
bool paused;
|
|
||||||
} Soundtrack;
|
|
||||||
|
|
||||||
Soundtrack LoadSoundtrack(const char* musicPath){
|
Soundtrack LoadSoundtrack(const char* musicPath){
|
||||||
Soundtrack soundtrack = {
|
Soundtrack soundtrack = {
|
||||||
@@ -35,5 +28,3 @@ void UpdateSoundtrack(Soundtrack *soundtrack, bool playing){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // SOUNDTRACK_H
|
|
||||||
|
|
||||||
@@ -1,18 +1,5 @@
|
|||||||
#ifndef SPRITE_H
|
#include "engine.h"
|
||||||
#define SPRITE_H
|
|
||||||
|
|
||||||
#include <raymath.h>
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
Texture2D texture;
|
|
||||||
Rectangle sourceRec;
|
|
||||||
Rectangle destRec;
|
|
||||||
Vector2 frameSize;
|
|
||||||
Vector2 origin;
|
|
||||||
float rotation;
|
|
||||||
Color color;
|
|
||||||
} Sprite;
|
|
||||||
|
|
||||||
void UpdateSpriteSourceRec(Sprite *sprite, const Vector2 *vector)
|
void UpdateSpriteSourceRec(Sprite *sprite, const Vector2 *vector)
|
||||||
{
|
{
|
||||||
@@ -58,5 +45,3 @@ void PrintSprite(const Sprite *sprite)
|
|||||||
printf(" Sprite.rotation: %f\n", sprite->rotation);
|
printf(" Sprite.rotation: %f\n", sprite->rotation);
|
||||||
printf(" Sprite.color: r = %d, g = %d, b = %d, a = %d\n", sprite->color.r, sprite->color.g, sprite->color.b, sprite->color.a);
|
printf(" Sprite.color: r = %d, g = %d, b = %d, a = %d\n", sprite->color.r, sprite->color.g, sprite->color.b, sprite->color.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // SPRITE_H
|
|
||||||
@@ -1,10 +1,4 @@
|
|||||||
#ifndef VECTOR_H
|
#include "engine.h"
|
||||||
#define VECTOR_H
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Vector2 *data;
|
|
||||||
size_t count;
|
|
||||||
} Vector2Array;
|
|
||||||
|
|
||||||
bool IsVectorZero(Vector2 v) {
|
bool IsVectorZero(Vector2 v) {
|
||||||
float epsilon = 0.01f;
|
float epsilon = 0.01f;
|
||||||
@@ -18,4 +12,3 @@ Vector2 GetRandomVector(const Rectangle bounds) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // VECTOR_H
|
|
||||||
+1
-2
@@ -1,5 +1,4 @@
|
|||||||
#include <raylib.h>
|
#include "appTypes.h"
|
||||||
#include "app.h"
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user