feat: add islands

This commit is contained in:
huaqo-games
2025-10-31 18:52:40 +01:00
parent 8761c69cfa
commit 03c663dcf9
2 changed files with 67 additions and 0 deletions
+5
View File
@@ -5,6 +5,7 @@
#include "appGameFloor.h" #include "appGameFloor.h"
#include "appGamePlayer.h" #include "appGamePlayer.h"
#include "appGameBirds.h" #include "appGameBirds.h"
#include "appGameIslands.h"
#include "appGameAssets.h" #include "appGameAssets.h"
typedef struct typedef struct
@@ -16,6 +17,7 @@ typedef struct
Floor floor; Floor floor;
Player player; Player player;
Birds birds; Birds birds;
Islands islands;
Camera2D camera; Camera2D camera;
Mouse mouse; Mouse mouse;
Image image; Image image;
@@ -41,6 +43,7 @@ void InitGame(GameState *g, Window *window)
g->target = LoadRenderTexture(window->width, window->height); g->target = LoadRenderTexture(window->width, window->height);
g->player = CreatePlayer(); g->player = CreatePlayer();
g->birds = CreateBirds(); g->birds = CreateBirds();
g->islands = CreateIslands();
g->floor = CreateFloor(); g->floor = CreateFloor();
g->camera = CreateCamera(g->player.physics.position, 10.0f); g->camera = CreateCamera(g->player.physics.position, 10.0f);
@@ -83,6 +86,7 @@ void UpdateGame(GameState *g, State *state, Flags *flags)
UpdateFloor(&g->floor, &g->camera); UpdateFloor(&g->floor, &g->camera);
UpdatePlayer(&g->player); UpdatePlayer(&g->player);
UpdateBirds(&g->birds); UpdateBirds(&g->birds);
UpdateIslands(&g->islands);
} }
void RenderComponents(GameState *g) void RenderComponents(GameState *g)
@@ -90,6 +94,7 @@ void RenderComponents(GameState *g)
RenderFloor(&g->floor); RenderFloor(&g->floor);
RenderPlayer(&g->player); RenderPlayer(&g->player);
RenderBirds(&g->birds); RenderBirds(&g->birds);
RenderIslands(&g->islands);
} }
void RenderGame(GameState *g, const State *appState, Flags *flags) void RenderGame(GameState *g, const State *appState, Flags *flags)
+62
View File
@@ -0,0 +1,62 @@
#ifndef APPGAMEISLANDS_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] = {
{"assets/island.png", 16.0f, 16.0f, 0.0f}
};
Islands CreateIslands(void){
TextureAsset islandAsset = islandsTextureAssets[ISLAND];
Texture2D texture = LoadTexture(islandAsset.path);
float frameWidth = islandAsset.frameWidth;
float rotation = islandAsset.rotation;
Sprite islandSprite = {
.texture = texture,
.frameSize = {frameWidth, frameWidth},
.sourceRec = {0.0f, 0.0f, frameWidth, frameWidth},
.destRec = {GetScreenWidth()/2, 0.0f, frameWidth, frameWidth},
.origin = {frameWidth / 2, frameWidth / 2},
.rotation = rotation,
.color = WHITE
};
Physics islandPhysics = {
.position = (Vector2){-100.0f, 0.0f},
.direction = (Vector2){0.0f, 0.0f},
.speed = 10.0f
};
return (Islands){
.sprite = islandSprite,
.physics = islandPhysics
};
}
void UpdateIslands(Islands *islands){
UpdatePhysics(&islands->physics, (Vector2){0.0f,0.0f});
UpdateSpriteDestRec(&islands->sprite, &islands->physics.position);
UpdateAnimation(&islands->animation, GetFrameTime());
UpdateSpriteSourceRec(&islands->sprite, &(Vector2){islands->sprite.frameSize.x * islands->animation.currentFrame, islands->sprite.frameSize.y});
}
void RenderIslands(Islands *islands){
RenderSprite(&islands->sprite);
}
#endif // APPGAMEISLANDS_H