diff --git a/include/appGame.h b/include/appGame.h index 9f4b764..e45058f 100644 --- a/include/appGame.h +++ b/include/appGame.h @@ -5,6 +5,7 @@ #include "appGameFloor.h" #include "appGamePlayer.h" #include "appGameBirds.h" +#include "appGameIslands.h" #include "appGameAssets.h" typedef struct @@ -16,6 +17,7 @@ typedef struct Floor floor; Player player; Birds birds; + Islands islands; Camera2D camera; Mouse mouse; Image image; @@ -41,6 +43,7 @@ void InitGame(GameState *g, Window *window) g->target = LoadRenderTexture(window->width, window->height); g->player = CreatePlayer(); g->birds = CreateBirds(); + g->islands = CreateIslands(); g->floor = CreateFloor(); 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); UpdatePlayer(&g->player); UpdateBirds(&g->birds); + UpdateIslands(&g->islands); } void RenderComponents(GameState *g) @@ -90,6 +94,7 @@ void RenderComponents(GameState *g) RenderFloor(&g->floor); RenderPlayer(&g->player); RenderBirds(&g->birds); + RenderIslands(&g->islands); } void RenderGame(GameState *g, const State *appState, Flags *flags) diff --git a/include/appGameIslands.h b/include/appGameIslands.h new file mode 100644 index 0000000..10ee0cd --- /dev/null +++ b/include/appGameIslands.h @@ -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 +