final oop style

This commit is contained in:
huaqo
2026-03-01 12:57:09 +01:00
parent c064e80be2
commit e1596f633d
10 changed files with 1004 additions and 393 deletions
+27 -35
View File
@@ -1,47 +1,39 @@
#include "app.h"
const TextureAsset islandsTextureAssets[ISLANDS_TEX_COUNT] = {
{"assets/island.png", 16.0f, 16.0f, 0.0f}
};
{"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
};
Islands CreateIslands(void) {
TextureAsset islandAsset = islandsTextureAssets[ISLAND];
Texture2D texture = LoadTexture(islandAsset.path);
float frameWidth = islandAsset.frameWidth;
float rotation = islandAsset.rotation;
Physics islandPhysics = {
.position = (Vector2){-100.0f, 0.0f},
.direction = (Vector2){0.0f, 0.0f},
.speed = 10.0f
};
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};
return (Islands){
.sprite = islandSprite,
.physics = islandPhysics
};
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});
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);
UpdateSpriteSourceRec(
&islands->sprite,
&(Vector2){islands->sprite.frameSize.x * islands->animation.currentFrame,
islands->sprite.frameSize.y});
}
void RenderIslands(Islands *islands) { RenderSprite(&islands->sprite); }