fix
@@ -1,16 +1,5 @@
|
|||||||
{
|
{
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
|
||||||
"name": "macOS",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/include",
|
|
||||||
"${workspaceFolder}/external/engine",
|
|
||||||
"${workspaceFolder}/external/raygui",
|
|
||||||
"${workspaceFolder}/external/rini",
|
|
||||||
"/opt/homebrew/Cellar/raylib/5.5/include"
|
|
||||||
],
|
|
||||||
"cStandard": "c99",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "Windows",
|
"name": "Windows",
|
||||||
"includePath": [
|
"includePath": [
|
||||||
|
|||||||
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 815 KiB |
|
After Width: | Height: | Size: 619 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 395 B |
|
After Width: | Height: | Size: 506 KiB |
|
After Width: | Height: | Size: 439 KiB |
@@ -1,9 +1,10 @@
|
|||||||
startView = 0 ; LOGO = 0, MENU = 1, GAMEPLAY = 2
|
startView = 1 ; LOGO = 0, MENU = 1, GAMEPLAY = 2, SETTINGS = 3
|
||||||
|
|
||||||
window_title = The Last Hive
|
window_title = The Last Pirate
|
||||||
window_width = 1280 ; in Pixel
|
window_width = 1280 ; in Pixel
|
||||||
window_height = 720 ; in Pixel
|
window_height = 720 ; in Pixel
|
||||||
|
|
||||||
showFPS = 1 ; OFF = 0, ON = 1
|
showFPS = 0 ; OFF = 0, ON = 1
|
||||||
|
soundtrackOn = 1 ; OFF = 0, ON = 1
|
||||||
|
|
||||||
font_path = assets/SproutLandsUI/fonts/pixelFont-7-8x14-sproutLands.fnt
|
font_path = assets/SproutLandsUI/fonts/pixelFont-7-8x14-sproutLands.fnt
|
||||||
@@ -17,7 +17,7 @@ PostProcessing CreatePostFX(const char* shaderPath){
|
|||||||
return postFX;
|
return postFX;
|
||||||
}
|
}
|
||||||
|
|
||||||
postFX.strength = 0.3f;
|
postFX.strength = 0.0f;
|
||||||
postFX.resolutionLoc = GetShaderLocation(postFX.shader, "resolution");
|
postFX.resolutionLoc = GetShaderLocation(postFX.shader, "resolution");
|
||||||
postFX.strengthLoc = GetShaderLocation(postFX.shader, "strength");
|
postFX.strengthLoc = GetShaderLocation(postFX.shader, "strength");
|
||||||
Vector2 resolution = { (float)GetScreenWidth(), (float)GetScreenHeight() };
|
Vector2 resolution = { (float)GetScreenWidth(), (float)GetScreenHeight() };
|
||||||
|
|||||||
@@ -1,37 +1,108 @@
|
|||||||
#ifndef Floor_H
|
#ifndef Floor_H
|
||||||
#define Floor_H
|
#define Floor_H
|
||||||
|
|
||||||
|
#include <raylib.h>
|
||||||
#include <sprite.h>
|
#include <sprite.h>
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Sprite sprite;
|
Sprite sprite;
|
||||||
Rectangle bounds;
|
Rectangle bounds;
|
||||||
|
Shader shader;
|
||||||
|
float time;
|
||||||
} Floor;
|
} Floor;
|
||||||
|
|
||||||
Floor CreateFloor(Texture2D texture, float textureWidth)
|
// ----------------------------------------------------
|
||||||
|
// Create floor (loads shader and sets defaults)
|
||||||
|
// ----------------------------------------------------
|
||||||
|
Floor CreateFloor()
|
||||||
{
|
{
|
||||||
return (Floor){
|
|
||||||
|
|
||||||
|
Texture2D base = LoadTexture("assets/ocean_base.png");
|
||||||
|
Texture2D caustic = LoadTexture("assets/CausticTexture.png");
|
||||||
|
Texture2D causticHighlight = LoadTexture("assets/CausticTextureHighlights.png");
|
||||||
|
Texture2D noise = LoadTexture("assets/noiseTexture.png");
|
||||||
|
Texture2D cloud = LoadTexture("assets/cloudnoise_1.png");
|
||||||
|
Texture2D voronoise = LoadTexture("assets/voronoise_3.png");
|
||||||
|
|
||||||
|
float textureWidth = 64.0f;
|
||||||
|
|
||||||
|
Floor floor = {
|
||||||
.sprite = {
|
.sprite = {
|
||||||
.texture = texture,
|
.texture = base,
|
||||||
.frameSize = {textureWidth, textureWidth},
|
.frameSize = {textureWidth, textureWidth},
|
||||||
.sourceRec = {0.0f, 0.0f, textureWidth, textureWidth},
|
.sourceRec = {0.0f, 0.0f, textureWidth, textureWidth},
|
||||||
.destRec = {0.0f, 0.0f, textureWidth, textureWidth},
|
.destRec = {0.0f, 0.0f, textureWidth, textureWidth},
|
||||||
.origin = {textureWidth / 2, textureWidth / 2},
|
.origin = {textureWidth / 2, textureWidth / 2},
|
||||||
.rotation = 0.0f,
|
.rotation = 0.0f,
|
||||||
.color = WHITE},
|
.color = WHITE},
|
||||||
.bounds = {0.0f, 0.0f, 0.0f, 0.0f}};
|
.bounds = {0},
|
||||||
|
.shader = LoadShader("shaders/water.vs", "shaders/water.fs"),
|
||||||
|
.time = 0.0f
|
||||||
|
};
|
||||||
|
|
||||||
|
float worldTileSize = 128.0f; // one tile covers 128x128 world units
|
||||||
|
float textureSize = 32.0f; // texture is 32x32 pixels
|
||||||
|
|
||||||
|
floor.sprite.frameSize = (Vector2){worldTileSize, worldTileSize};
|
||||||
|
floor.sprite.sourceRec = (Rectangle){0, 0, textureSize, textureSize};
|
||||||
|
floor.sprite.destRec = (Rectangle){0, 0, worldTileSize, worldTileSize};
|
||||||
|
floor.sprite.origin = (Vector2){0, 0};
|
||||||
|
|
||||||
|
|
||||||
|
// Optional: load your extra water textures here and bind them
|
||||||
|
// Example:
|
||||||
|
|
||||||
|
|
||||||
|
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "causticTexture"), caustic);
|
||||||
|
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "causticHighlightTexture"), causticHighlight);
|
||||||
|
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "causticNoiseTexture"), noise);
|
||||||
|
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "causticFadeNoiseTexture"), cloud);
|
||||||
|
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "specularNoiseTexture"), voronoise);
|
||||||
|
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "specularMovementLeftNoiseTexture"), voronoise);
|
||||||
|
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "specularMovementRightNoiseTexture"), cloud);
|
||||||
|
|
||||||
|
|
||||||
|
// Texture2D caustic = LoadTexture("resources/caustic.png");
|
||||||
|
// SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "causticTexture"), caustic);
|
||||||
|
|
||||||
|
// Setup aspect ratio and pixelization uniforms once
|
||||||
|
float aspect = (float)GetScreenHeight() / (float)GetScreenWidth();
|
||||||
|
float pixelization = 2048.0f;
|
||||||
|
int aspectLoc = GetShaderLocation(floor.shader, "aspectRatio");
|
||||||
|
int pixelLoc = GetShaderLocation(floor.shader, "pixelization");
|
||||||
|
SetShaderValue(floor.shader, aspectLoc, &aspect, SHADER_UNIFORM_FLOAT);
|
||||||
|
SetShaderValue(floor.shader, pixelLoc, &pixelization, SHADER_UNIFORM_FLOAT);
|
||||||
|
|
||||||
|
floor.sprite.texture = base;
|
||||||
|
|
||||||
|
return floor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------
|
||||||
|
// Update visible area (same logic as before)
|
||||||
|
// ----------------------------------------------------
|
||||||
void UpdateFloor(Floor *floor, const Camera2D *camera)
|
void UpdateFloor(Floor *floor, const Camera2D *camera)
|
||||||
{
|
{
|
||||||
floor->bounds.x = (int)((camera->target.x - (GetScreenWidth() / 2.0f / camera->zoom)) / floor->sprite.frameSize.x) - 1;
|
floor->bounds.x = (int)((camera->target.x - (GetScreenWidth() / 2.0f / camera->zoom)) / floor->sprite.frameSize.x) - 1;
|
||||||
floor->bounds.width = (int)((camera->target.x + (GetScreenWidth() / 2.0f / camera->zoom)) / floor->sprite.frameSize.x) + 1;
|
floor->bounds.width = (int)((camera->target.x + (GetScreenWidth() / 2.0f / camera->zoom)) / floor->sprite.frameSize.x) + 1;
|
||||||
floor->bounds.y = (int)((camera->target.y - (GetScreenHeight() / 2.0f / camera->zoom)) / floor->sprite.frameSize.y) - 1;
|
floor->bounds.y = (int)((camera->target.y - (GetScreenHeight() / 2.0f / camera->zoom)) / floor->sprite.frameSize.y) - 1;
|
||||||
floor->bounds.height = (int)((camera->target.y + (GetScreenHeight() / 2.0f / camera->zoom)) / floor->sprite.frameSize.y) + 1;
|
floor->bounds.height = (int)((camera->target.y + (GetScreenHeight() / 2.0f / camera->zoom)) / floor->sprite.frameSize.y) + 1;
|
||||||
|
|
||||||
|
// Update time uniform
|
||||||
|
floor->time += GetFrameTime();
|
||||||
|
int timeLoc = GetShaderLocation(floor->shader, "time");
|
||||||
|
SetShaderValue(floor->shader, timeLoc, &floor->time, SHADER_UNIFORM_FLOAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------
|
||||||
|
// Render floor tiles using the shader
|
||||||
|
// ----------------------------------------------------
|
||||||
void RenderFloor(Floor *floor)
|
void RenderFloor(Floor *floor)
|
||||||
{
|
{
|
||||||
|
BeginShaderMode(floor->shader);
|
||||||
|
|
||||||
for (int y = (int)floor->bounds.y; y <= (int)floor->bounds.height; y++)
|
for (int y = (int)floor->bounds.y; y <= (int)floor->bounds.height; y++)
|
||||||
{
|
{
|
||||||
for (int x = (int)floor->bounds.x; x <= (int)floor->bounds.width; x++)
|
for (int x = (int)floor->bounds.x; x <= (int)floor->bounds.width; x++)
|
||||||
@@ -41,6 +112,16 @@ void RenderFloor(Floor *floor)
|
|||||||
RenderSprite(&floor->sprite);
|
RenderSprite(&floor->sprite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EndShaderMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------
|
||||||
|
// Cleanup
|
||||||
|
// ----------------------------------------------------
|
||||||
|
void UnloadFloor(Floor *floor)
|
||||||
|
{
|
||||||
|
UnloadShader(floor->shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // Floor_H
|
#endif // Floor_H
|
||||||
|
|||||||
@@ -1,21 +1,16 @@
|
|||||||
#ifndef GAME_H
|
#ifndef GAME_H
|
||||||
#define GAME_H
|
#define GAME_H
|
||||||
|
|
||||||
#include <object.h>
|
|
||||||
#include <camera.h>
|
#include <camera.h>
|
||||||
#include <input.h>
|
#include <input.h>
|
||||||
|
|
||||||
|
#include "floor.h"
|
||||||
|
#include "player.h"
|
||||||
|
|
||||||
|
#include "gameassets.h"
|
||||||
#include <postfx.h>
|
#include <postfx.h>
|
||||||
#include <soundtrack.h>
|
#include <soundtrack.h>
|
||||||
#include <asset.h>
|
#include <asset.h>
|
||||||
#include <array.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "gameassets.h"
|
|
||||||
#include "floor.h"
|
|
||||||
#include "player.h"
|
|
||||||
#include "bee.h"
|
|
||||||
#include "hive.h"
|
|
||||||
#include "flowers.h"
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -25,10 +20,7 @@ typedef struct
|
|||||||
Soundtrack soundtracks[SOUNDTRACK_COUNT];
|
Soundtrack soundtracks[SOUNDTRACK_COUNT];
|
||||||
RenderTexture2D target;
|
RenderTexture2D target;
|
||||||
Floor floor;
|
Floor floor;
|
||||||
Object hive;
|
|
||||||
Array* flowers;
|
|
||||||
Player player;
|
Player player;
|
||||||
Bee bee1;
|
|
||||||
Camera2D camera;
|
Camera2D camera;
|
||||||
Mouse mouse;
|
Mouse mouse;
|
||||||
Image image;
|
Image image;
|
||||||
@@ -57,22 +49,13 @@ void InitGame(GameState *g, Window *window)
|
|||||||
g->soundtracks[i] = LoadSoundtrack(g->assets.soundtrackAssets[i].path);
|
g->soundtracks[i] = LoadSoundtrack(g->assets.soundtrackAssets[i].path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Target texture
|
|
||||||
g->target = LoadRenderTexture(window->width, window->height);
|
g->target = LoadRenderTexture(window->width, window->height);
|
||||||
|
g->player = CreatePlayer();
|
||||||
// Static Entities
|
g->floor = CreateFloor();
|
||||||
g->flowers = CreateFlowers(g->textures[FLOWER], g->assets.textureAssets[FLOWER].frameWidth, g->assets.textureAssets[FLOWER].rotation, 50.0f);
|
|
||||||
g->floor = CreateFloor(g->textures[GRASS], g->assets.textureAssets[GRASS].frameWidth);
|
|
||||||
g->hive = CreateHive(g->textures[HIVE], g->assets.textureAssets[HIVE].frameWidth);
|
|
||||||
|
|
||||||
// Animated Entities
|
|
||||||
g->player = CreatePlayer(IDLE_DOWN, HOE, g->textures[PLAYER], g->assets.textureAssets[PLAYER].frameWidth, 4, 2, g->hive.position, g->assets.textureAssets[PLAYER].rotation, 50.0f);
|
|
||||||
// g->bee1 = CreateBee(FLYING, g->textures[BEE], g->assets.textureAssets[BEE].frameWidth, 4, 10, g->hive.position, 10.0f, &g->flowers, &g->hive);
|
|
||||||
|
|
||||||
// I/O
|
|
||||||
g->camera = CreateCamera(window->width, window->height, g->player.physics.position, 10.0f);
|
g->camera = CreateCamera(window->width, window->height, g->player.physics.position, 10.0f);
|
||||||
|
|
||||||
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &g->textures[CURSOR]);
|
Texture2D mouseTexture = LoadTexture("assets/SproutLandsUI/Spritesheets/Mouse sprites/TriangleMouseicon1.png");
|
||||||
|
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &mouseTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateGame(GameState *g, State *state, Flags *flags)
|
void UpdateGame(GameState *g, State *state, Flags *flags)
|
||||||
@@ -85,14 +68,17 @@ void UpdateGame(GameState *g, State *state, Flags *flags)
|
|||||||
{
|
{
|
||||||
SetTargetFPS(0);
|
SetTargetFPS(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_ESCAPE))
|
if (IsKeyPressed(KEY_ESCAPE))
|
||||||
{
|
{
|
||||||
state->currentView = MENU;
|
state->currentView = MENU;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE))
|
if (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE))
|
||||||
{
|
{
|
||||||
state->running = false;
|
state->running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < SHADER_COUNT; i++)
|
for (int i = 0; i < SHADER_COUNT; i++)
|
||||||
{
|
{
|
||||||
UpdatePostFX(&g->postFX[i]);
|
UpdatePostFX(&g->postFX[i]);
|
||||||
@@ -105,18 +91,13 @@ void UpdateGame(GameState *g, State *state, Flags *flags)
|
|||||||
UpdateMouse(&g->mouse, &g->camera);
|
UpdateMouse(&g->mouse, &g->camera);
|
||||||
UpdateCamera2D(&g->camera, &g->player.physics.position, &g->mouse);
|
UpdateCamera2D(&g->camera, &g->player.physics.position, &g->mouse);
|
||||||
UpdateFloor(&g->floor, &g->camera);
|
UpdateFloor(&g->floor, &g->camera);
|
||||||
UpdatePlayer(&g->player, g->flowers);
|
UpdatePlayer(&g->player);
|
||||||
UpdateArray(g->flowers, UpdateFlower);
|
|
||||||
// UpdateBee(&g->bee1, &g->flowers, &g->hive);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderComponents(GameState *g)
|
void RenderComponents(GameState *g)
|
||||||
{
|
{
|
||||||
RenderFloor(&g->floor);
|
RenderFloor(&g->floor);
|
||||||
RenderSprite(&g->hive.sprite);
|
RenderPlayer(&g->player);
|
||||||
RenderArray(g->flowers, RenderFlower);
|
|
||||||
RenderSprite(&g->player.sprite);
|
|
||||||
RenderSprite(&g->bee1.sprite);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderGame(GameState *g, const State *appState, Flags *flags)
|
void RenderGame(GameState *g, const State *appState, Flags *flags)
|
||||||
@@ -128,13 +109,13 @@ void RenderGame(GameState *g, const State *appState, Flags *flags)
|
|||||||
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();
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
for (int i = 0; i < SHADER_COUNT; i++)
|
for (int i = 0; i < SHADER_COUNT; i++)
|
||||||
{
|
{
|
||||||
RenderPostFX(&g->postFX[i], &g->target);
|
RenderPostFX(&g->postFX[i], &g->target);
|
||||||
}
|
}
|
||||||
DrawText(TextFormat("Flower Seeds: %d", g->player.inventar.flowerSeedCount), 10, 10, 50, WHITE);
|
|
||||||
|
|
||||||
if (flags->showFPS)
|
if (flags->showFPS)
|
||||||
{
|
{
|
||||||
@@ -162,7 +143,6 @@ void CleanupGame(GameState *g)
|
|||||||
UnloadMusicStream(g->soundtracks[i].music);
|
UnloadMusicStream(g->soundtracks[i].music);
|
||||||
}
|
}
|
||||||
UnloadRenderTexture(g->target);
|
UnloadRenderTexture(g->target);
|
||||||
FreeArray(&g->flowers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // GAME_H
|
#endif // GAME_H
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ typedef enum
|
|||||||
} TextureID;
|
} TextureID;
|
||||||
|
|
||||||
const TextureAsset texAssets[TEX_COUNT] = {
|
const TextureAsset texAssets[TEX_COUNT] = {
|
||||||
{"assets/SproutLandsBasic/Characters/character.png", 48.0f, 48.0f, 0.0f},
|
{"assets/ship.png", 32.0f, 32.0f, 0.0f},
|
||||||
{"assets/SproutLandsBasic/Characters/BasicCharakterActions.png", 48.0f, 48.0f, 0.0f},
|
{"assets/SproutLandsBasic/Characters/BasicCharakterActions.png", 48.0f, 48.0f, 0.0f},
|
||||||
{"assets/SproutLandsBasic/Objects/tools.png", 48.0f, 16.0f, 0.0f},
|
{"assets/SproutLandsBasic/Objects/tools.png", 48.0f, 16.0f, 0.0f},
|
||||||
{"assets/carrot_and_tomato.png", 32.0f, 32.0f, 0.0f},
|
{"assets/carrot_and_tomato.png", 32.0f, 32.0f, 0.0f},
|
||||||
@@ -47,7 +47,7 @@ typedef enum
|
|||||||
} SoundtrackID;
|
} SoundtrackID;
|
||||||
|
|
||||||
const SoundtrackAsset soundtrackAssets[SOUNDTRACK_COUNT] = {
|
const SoundtrackAsset soundtrackAssets[SOUNDTRACK_COUNT] = {
|
||||||
{"assets/beez.mp3"}};
|
{"assets/sea.mp3"}};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef GAMEUI
|
||||||
|
#define GAMEUI
|
||||||
|
|
||||||
|
#include "flags.h"
|
||||||
|
|
||||||
|
void RenderGameUI(bool showFPS){
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
|
if (showFPS)
|
||||||
|
{
|
||||||
|
DrawFPS(10, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //GAMEUI
|
||||||
|
|
||||||
@@ -5,145 +5,148 @@
|
|||||||
#include <animation.h>
|
#include <animation.h>
|
||||||
#include <physics.h>
|
#include <physics.h>
|
||||||
#include <input.h>
|
#include <input.h>
|
||||||
#include <array.h>
|
#include <asset.h>
|
||||||
|
|
||||||
#include "flowers.h"
|
|
||||||
#include "inventar.h"
|
#include "inventar.h"
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
IDLE,
|
START_SHIP,
|
||||||
WALKING,
|
PLAYER_TEX_COUNT
|
||||||
USING_TOOL
|
} playerTextureID;
|
||||||
} PlayerState;
|
|
||||||
|
|
||||||
typedef enum
|
const TextureAsset textureAssets[PLAYER_TEX_COUNT] = {
|
||||||
{
|
{"assets/start_ship.png", 16.0f, 16.0f, 0.0f}
|
||||||
NO_TOOL,
|
};
|
||||||
HOE,
|
|
||||||
AXT,
|
|
||||||
CAN
|
|
||||||
} SelectedTool;
|
typedef enum {
|
||||||
|
ANCHOR,
|
||||||
|
SLOW_AHEAD,
|
||||||
|
FAST_AHEAD,
|
||||||
|
SPEED_COUNT
|
||||||
|
} playerSpeedID;
|
||||||
|
|
||||||
|
float playerSpeeds[SPEED_COUNT] = {
|
||||||
|
0.0f,
|
||||||
|
5.0f,
|
||||||
|
10.0f
|
||||||
|
};
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
IDLE_DOWN,
|
|
||||||
IDLE_UP,
|
|
||||||
IDLE_LEFT,
|
|
||||||
IDLE_RIGHT,
|
|
||||||
WALKING_DOWN,
|
|
||||||
WALKING_UP,
|
|
||||||
WALKING_LEFT,
|
|
||||||
WALKING_RIGHT,
|
|
||||||
HOE_DOWN,
|
|
||||||
HOE_UP,
|
|
||||||
HOE_RIGHT,
|
|
||||||
HOE_LEFT,
|
|
||||||
AXT_DOWN,
|
|
||||||
AXT_UP,
|
|
||||||
AXT_RIGHT,
|
|
||||||
AXT_LEFT,
|
|
||||||
CAN_DOWN,
|
|
||||||
CAN_UP,
|
|
||||||
CAN_RIGHT,
|
|
||||||
CAN_LEFT,
|
|
||||||
} PlayerAnimationState;
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
SelectedTool selectedTool;
|
|
||||||
Sprite sprite;
|
Sprite sprite;
|
||||||
Animation animation;
|
Animation animation;
|
||||||
Physics physics;
|
Physics physics;
|
||||||
Inventar inventar;
|
float rotation;
|
||||||
} Player;
|
} Player;
|
||||||
|
|
||||||
Player CreatePlayer(PlayerAnimationState animState, SelectedTool selectedTool, Texture2D texture, float frameWidth, int maxFrame, int framesSpeed, Vector2 startPosition, float rotation, float speed)
|
Player CreatePlayer(void)
|
||||||
{
|
{
|
||||||
return (Player){
|
|
||||||
.selectedTool = selectedTool,
|
TextureAsset startShipAsset = textureAssets[START_SHIP];
|
||||||
.sprite = {
|
|
||||||
|
Texture2D texture = LoadTexture(startShipAsset.path);
|
||||||
|
float frameWidth = startShipAsset.frameWidth;
|
||||||
|
float rotation = startShipAsset.rotation;
|
||||||
|
|
||||||
|
|
||||||
|
Sprite playerSprite = {
|
||||||
.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 = {0.0f, 0.0f, frameWidth, frameWidth},
|
.destRec = {0.0f, 0.0f, frameWidth, frameWidth},
|
||||||
.origin = {frameWidth / 2, frameWidth / 2},
|
.origin = {frameWidth / 2, frameWidth / 2},
|
||||||
.rotation = rotation,
|
.rotation = rotation,
|
||||||
.color = WHITE},
|
.color = WHITE
|
||||||
.animation = {.state = animState, .currentFrame = 0, .maxFrame = maxFrame, .framesCounter = 0, .framesSpeed = framesSpeed, .animTimer = 0.0f},
|
};
|
||||||
.physics = {.position = startPosition, .direction = (Vector2){0.0f, 0.0f}, .speed = speed},
|
|
||||||
.inventar = {.flowerSeedCount = 6}};
|
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]
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
return (Player){
|
||||||
|
.sprite = playerSprite,
|
||||||
|
.animation = playerAnimation,
|
||||||
|
.physics = playerPhysics,
|
||||||
|
.rotation = rotation
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdatePlayerAnimationState(int *state, SelectedTool *selectedTool, Vector2 *dir)
|
void UpdatePlayer(Player *player)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_ZERO))
|
|
||||||
{
|
|
||||||
*selectedTool = NO_TOOL;
|
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->sprite.sourceRec.x = 16.0f * 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
player->physics.speed = playerSpeeds[FAST_AHEAD];
|
||||||
|
player->sprite.sourceRec.x = 16.0f * 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_ONE))
|
if(IsKeyPressed(KEY_S) || IsKeyPressed(KEY_DOWN)){
|
||||||
{
|
if(player->physics.speed > playerSpeeds[ANCHOR]){
|
||||||
*selectedTool = HOE;
|
if(player->physics.speed > playerSpeeds[SLOW_AHEAD]){
|
||||||
|
player->physics.speed = playerSpeeds[SLOW_AHEAD];
|
||||||
|
player->sprite.sourceRec.x = 16.0f * 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
player->physics.speed = playerSpeeds[ANCHOR];
|
||||||
|
player->sprite.sourceRec.x = 16.0f * 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_TWO))
|
|
||||||
{
|
float rotationSpeed = 100.0f;
|
||||||
*selectedTool = AXT;
|
|
||||||
|
if (player->physics.speed > playerSpeeds[ANCHOR]){
|
||||||
|
|
||||||
|
if (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT)) {
|
||||||
|
player->rotation -= rotationSpeed * GetFrameTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_THREE))
|
if (IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT)) {
|
||||||
{
|
player->rotation += rotationSpeed * GetFrameTime();
|
||||||
*selectedTool = CAN;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir->x == 0 && dir->y == 0)
|
player->sprite.rotation = player->rotation;
|
||||||
{
|
|
||||||
switch (*state)
|
float rad = (player->rotation - 90.0f) * (PI / 180.0f);
|
||||||
{
|
Vector2 dir = { cosf(rad), sinf(rad) };
|
||||||
case WALKING_DOWN:
|
|
||||||
*state = IDLE_DOWN;
|
|
||||||
break;
|
|
||||||
case WALKING_UP:
|
|
||||||
*state = IDLE_UP;
|
|
||||||
break;
|
|
||||||
case WALKING_LEFT:
|
|
||||||
*state = IDLE_LEFT;
|
|
||||||
break;
|
|
||||||
case WALKING_RIGHT:
|
|
||||||
*state = IDLE_RIGHT;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (dir->y == 1)
|
|
||||||
*state = WALKING_DOWN;
|
|
||||||
else if (dir->y == -1)
|
|
||||||
*state = WALKING_UP;
|
|
||||||
else if (dir->x == -1)
|
|
||||||
*state = WALKING_LEFT;
|
|
||||||
else if (dir->x == 1)
|
|
||||||
*state = WALKING_RIGHT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdatePlayer(Player *player, Array* flowers)
|
|
||||||
{
|
|
||||||
if (IsKeyPressed(KEY_SPACE) && player->inventar.flowerSeedCount > 0)
|
|
||||||
{
|
|
||||||
AddFlower(flowers, player->sprite.destRec);
|
|
||||||
player->inventar.flowerSeedCount--;
|
|
||||||
}
|
|
||||||
Vector2 dir = GetDirectionVector();
|
|
||||||
UpdatePlayerAnimationState(&player->animation.state, &player->selectedTool, &dir);
|
|
||||||
UpdatePhysics(&player->physics, dir);
|
UpdatePhysics(&player->physics, dir);
|
||||||
UpdateSpriteDestRec(&player->sprite, &player->physics.position);
|
UpdateSpriteDestRec(&player->sprite, &player->physics.position);
|
||||||
UpdateAnimation(&player->animation, GetFrameTime());
|
//UpdateAnimation(&player->animation, GetFrameTime());
|
||||||
UpdateSpriteSourceRec(&player->sprite, &(Vector2){player->sprite.frameSize.x * player->animation.currentFrame, player->sprite.frameSize.y * player->animation.state});
|
//UpdateSpriteSourceRec(&player->sprite, &(Vector2){player->sprite.frameSize.x * player->animation.currentFrame, player->sprite.frameSize.y * player->animation.state});
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderPlayer(Player *player){
|
||||||
|
RenderSprite(&player->sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // PLAYER_H
|
#endif // PLAYER_H
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
✅ Notes for using in Raylib
|
||||||
|
|
||||||
|
Vertex shader: You can use the default Raylib one (default.vs).
|
||||||
|
|
||||||
|
Time uniform: Update each frame in C:
|
||||||
|
|
||||||
|
float t = GetTime();
|
||||||
|
SetShaderValue(shader, GetShaderLocation(shader, "time"), &t, SHADER_UNIFORM_FLOAT);
|
||||||
|
|
||||||
|
Other textures: Bind them using SetShaderTexture(shader, loc, texture).
|
||||||
|
|
||||||
|
If you want, I can also write a full Raylib C snippet showing exactly how to load this shader and set all the textures and uniforms.
|
||||||
|
|
||||||
|
Do you want me to do that?
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
#version 330
|
||||||
|
|
||||||
|
// -----------------------------
|
||||||
|
// Inputs
|
||||||
|
in vec2 fragTexCoord;
|
||||||
|
in vec4 fragColor;
|
||||||
|
|
||||||
|
// -----------------------------
|
||||||
|
// Outputs
|
||||||
|
out vec4 finalColor;
|
||||||
|
|
||||||
|
// -----------------------------
|
||||||
|
// Uniforms
|
||||||
|
uniform sampler2D texture0; // main texture
|
||||||
|
uniform sampler2D waterDepthGradient;
|
||||||
|
uniform sampler2D causticTexture;
|
||||||
|
uniform sampler2D causticHighlightTexture;
|
||||||
|
uniform sampler2D causticNoiseTexture;
|
||||||
|
uniform sampler2D causticFadeNoiseTexture;
|
||||||
|
uniform sampler2D specularNoiseTexture;
|
||||||
|
uniform sampler2D specularMovementLeftNoiseTexture;
|
||||||
|
uniform sampler2D specularMovementRightNoiseTexture;
|
||||||
|
uniform sampler2D foamTexture;
|
||||||
|
|
||||||
|
uniform float aspectRatio = 1.0;
|
||||||
|
uniform float pixelization = 2048.0;
|
||||||
|
|
||||||
|
uniform vec4 causticColor = vec4(0.455, 0.773, 0.765, 1.0);
|
||||||
|
uniform vec4 causticHighlightColor = vec4(0.741, 0.894, 0.898, 1.0);
|
||||||
|
uniform float causticScale = 12.0;
|
||||||
|
uniform float causticSpeed = 0.005;
|
||||||
|
uniform float causticMovementAmount = 0.15;
|
||||||
|
uniform float causticFaderMultiplier = 1.45;
|
||||||
|
|
||||||
|
uniform vec4 specularColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||||
|
uniform float specularThreshold = 0.35;
|
||||||
|
uniform float specularSpeed = 0.025;
|
||||||
|
uniform float specularScale = 15.0;
|
||||||
|
|
||||||
|
uniform vec4 foamColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||||
|
uniform float foamIntensity = 0.2;
|
||||||
|
uniform float foamScale = 15.0;
|
||||||
|
|
||||||
|
uniform vec4 outlineColor = vec4(0.675, 0.86, 1.0, 1.0);
|
||||||
|
uniform float generalTransparency = 1.0;
|
||||||
|
|
||||||
|
uniform float time;
|
||||||
|
|
||||||
|
// -----------------------------
|
||||||
|
// Helper functions
|
||||||
|
|
||||||
|
vec2 blendSubtract_vec2(vec2 base, vec2 blend, float opacity)
|
||||||
|
{
|
||||||
|
vec2 result = base - blend;
|
||||||
|
return mix(base, result, opacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
float blendSubtract_float(float base, float blend, float opacity)
|
||||||
|
{
|
||||||
|
float result = base - blend;
|
||||||
|
return mix(base, result, opacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
float blendOverlay_float(float base, float blend, float opacity)
|
||||||
|
{
|
||||||
|
float result1 = 1.0 - 2.0 * (1.0 - base) * (1.0 - blend);
|
||||||
|
float result2 = 2.0 * base * blend;
|
||||||
|
float zeroOrOne = step(0.5, base);
|
||||||
|
float res = result2 * zeroOrOne + (1.0 - zeroOrOne) * result1;
|
||||||
|
return mix(base, res, opacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 pixelizeCoordinates(vec2 coordinates)
|
||||||
|
{
|
||||||
|
return floor(coordinates * pixelization) / pixelization;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 applyAspectRatio(vec2 coordinates)
|
||||||
|
{
|
||||||
|
return vec2(coordinates.x, coordinates.y * aspectRatio);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------
|
||||||
|
// Shader layers
|
||||||
|
|
||||||
|
vec4 caustics(vec2 pixelizedCoordinates)
|
||||||
|
{
|
||||||
|
vec4 causticNoise = texture(causticNoiseTexture, time * causticSpeed + pixelizedCoordinates);
|
||||||
|
vec2 noiseCoordinates = blendSubtract_vec2(pixelizedCoordinates * causticScale, causticNoise.rg, causticMovementAmount);
|
||||||
|
vec4 causticHighlight = texture(causticHighlightTexture, noiseCoordinates) * causticHighlightColor;
|
||||||
|
vec4 caustic = texture(causticTexture, noiseCoordinates) * causticColor;
|
||||||
|
vec4 interpolatedCaustics = mix(caustic, causticHighlight, causticHighlight.a);
|
||||||
|
float fadeNoise = texture(causticFadeNoiseTexture, noiseCoordinates).r * causticFaderMultiplier;
|
||||||
|
return vec4(interpolatedCaustics.rgb, clamp(interpolatedCaustics.a - fadeNoise, 0.0, 1.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 specular(vec2 pixelizedCoordinates)
|
||||||
|
{
|
||||||
|
vec2 scaledCoordinates = pixelizedCoordinates * specularScale;
|
||||||
|
float specularNoise = texture(specularNoiseTexture, scaledCoordinates).r;
|
||||||
|
float leftScrollingNoise = texture(specularMovementLeftNoiseTexture, scaledCoordinates + vec2(time * specularSpeed, 0.0)).r;
|
||||||
|
float rightScrollingNoise = texture(specularMovementRightNoiseTexture, scaledCoordinates + vec2(time * specularSpeed * -1.0, 0.0)).r;
|
||||||
|
float combined = blendSubtract_float(blendOverlay_float(leftScrollingNoise, rightScrollingNoise, 1.0), specularNoise, 1.0);
|
||||||
|
return step(specularThreshold, combined) * specularColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 foam(vec2 pixelizedCoordinates, vec4 mainTexColor)
|
||||||
|
{
|
||||||
|
vec4 colorizedFoam = texture(foamTexture, pixelizedCoordinates * foamScale) * foamColor;
|
||||||
|
float intensity = clamp(mainTexColor.g * mainTexColor.a - foamIntensity, 0.0, 1.0);
|
||||||
|
return vec4(colorizedFoam.rgb, colorizedFoam.a * intensity);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------
|
||||||
|
// Main fragment
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 pixelizedCoordinates = pixelizeCoordinates(applyAspectRatio(fragTexCoord));
|
||||||
|
vec4 mainTex = texture(texture0, fragTexCoord);
|
||||||
|
vec4 depthBasedWaterColor = texture(waterDepthGradient, vec2(1.0 - mainTex.b, 1.0));
|
||||||
|
|
||||||
|
vec4 finalCaustics = caustics(pixelizedCoordinates);
|
||||||
|
vec4 finalSpecular = specular(pixelizedCoordinates);
|
||||||
|
vec4 finalFoam = foam(pixelizedCoordinates, mainTex);
|
||||||
|
|
||||||
|
vec4 waterWithCausticLayer = mix(depthBasedWaterColor, finalCaustics, finalCaustics.a);
|
||||||
|
vec4 waterWithCausticAndSpecularLayer = mix(waterWithCausticLayer, finalSpecular, ceil(finalCaustics.a) * finalSpecular.a);
|
||||||
|
vec4 waterWithCausticAndSpecularAndFoamLayer = mix(waterWithCausticAndSpecularLayer, finalFoam, finalFoam.a);
|
||||||
|
|
||||||
|
float outline = mainTex.a * mainTex.r;
|
||||||
|
vec4 finalOutlineColor = outline * outlineColor;
|
||||||
|
|
||||||
|
vec4 finalRGBColor = mix(waterWithCausticAndSpecularAndFoamLayer, finalOutlineColor, outline);
|
||||||
|
finalColor = vec4(finalRGBColor.rgb, mainTex.b * generalTransparency);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#version 330
|
||||||
|
in vec3 vertexPosition;
|
||||||
|
in vec2 vertexTexCoord;
|
||||||
|
in vec4 vertexColor;
|
||||||
|
|
||||||
|
out vec2 fragTexCoord;
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
|
uniform mat4 mvp;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
fragTexCoord = vertexTexCoord;
|
||||||
|
fragColor = vertexColor;
|
||||||
|
gl_Position = mvp * vec4(vertexPosition, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||