feat: flower growth over time
This commit is contained in:
Vendored
+8
@@ -66,6 +66,14 @@ void* GetRandomElementFromArray(Array* array){
|
||||
return &array->elements[randomIndex];
|
||||
}
|
||||
|
||||
void UpdateArray(Array* array, void (*updateFunc)(void*))
|
||||
{
|
||||
if (!array || !updateFunc) return;
|
||||
for (unsigned int i = 0; i < array->count; i++) {
|
||||
updateFunc(array->elements[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderArray(Array* array, void (*renderFunc)(void*))
|
||||
{
|
||||
if (!array || !renderFunc) return;
|
||||
|
||||
+22
-1
@@ -13,6 +13,7 @@ typedef struct {
|
||||
Sprite sprite;
|
||||
Vector2 position;
|
||||
AGE age;
|
||||
float ageTimer;
|
||||
} Flower;
|
||||
|
||||
Array* CreateFlowers(Texture2D texture, float frameWidth, float rotation, float fieldSize)
|
||||
@@ -35,13 +36,32 @@ Array* CreateFlowers(Texture2D texture, float frameWidth, float rotation, float
|
||||
.rotation = rotation,
|
||||
.color = WHITE,
|
||||
},
|
||||
.age = CHILD
|
||||
.age = CHILD,
|
||||
.ageTimer = 0.0f
|
||||
};
|
||||
AddElementToArray(flowers, flower);
|
||||
}
|
||||
return flowers;
|
||||
}
|
||||
|
||||
|
||||
void UpdateFlower(void* element) {
|
||||
Flower* f = (Flower*)element;
|
||||
if (!f) return;
|
||||
|
||||
f->ageTimer += 1;
|
||||
|
||||
if (f->age == CHILD && f->ageTimer >= 3000.0f) {
|
||||
f->age = TEEN;
|
||||
f->sprite.sourceRec.x = f->sprite.sourceRec.width;
|
||||
}
|
||||
else if (f->age == TEEN && f->ageTimer >= 6000.0f) {
|
||||
f->age = ADULT;
|
||||
f->sprite.sourceRec.x = 2.0f * f->sprite.sourceRec.width;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RenderFlower(void* element)
|
||||
{
|
||||
Flower* f = (Flower*)element;
|
||||
@@ -51,4 +71,5 @@ void RenderFlower(void* element)
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // FLOWERS_H
|
||||
|
||||
@@ -102,6 +102,7 @@ void UpdateGame(GameState *g, View *currentView, bool *running)
|
||||
UpdateCamera2D(&g->camera, &g->player.physics.position, &g->mouse);
|
||||
UpdateFloor(&g->floor, &g->camera);
|
||||
UpdatePlayer(&g->player);
|
||||
UpdateArray(g->flowers, UpdateFlower);
|
||||
// UpdateBee(&g->bee1, &g->flowers, &g->hive);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ const TextureAsset texAssets[TEX_COUNT] = {
|
||||
{"assets/SproutLandsBasic/Characters/character.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/flower.png", 16.0f, 16.0f, 45.0f},
|
||||
{"assets/carrot_and_tomato.png", 32.0f, 32.0f, 0.0f},
|
||||
{"assets/character_bee.png", 16.0f, 16.0f, 0.0f},
|
||||
{"assets/grass.png", 16.0f, 16.0f, 0.0f},
|
||||
{"assets/hive.png", 32.0f, 32.0f, 0.0f},
|
||||
|
||||
Reference in New Issue
Block a user