feat: flower growth over time
This commit is contained in:
Vendored
+8
@@ -66,6 +66,14 @@ void* GetRandomElementFromArray(Array* array){
|
|||||||
return &array->elements[randomIndex];
|
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*))
|
void RenderArray(Array* array, void (*renderFunc)(void*))
|
||||||
{
|
{
|
||||||
if (!array || !renderFunc) return;
|
if (!array || !renderFunc) return;
|
||||||
|
|||||||
+22
-1
@@ -13,6 +13,7 @@ typedef struct {
|
|||||||
Sprite sprite;
|
Sprite sprite;
|
||||||
Vector2 position;
|
Vector2 position;
|
||||||
AGE age;
|
AGE age;
|
||||||
|
float ageTimer;
|
||||||
} Flower;
|
} Flower;
|
||||||
|
|
||||||
Array* CreateFlowers(Texture2D texture, float frameWidth, float rotation, float fieldSize)
|
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,
|
.rotation = rotation,
|
||||||
.color = WHITE,
|
.color = WHITE,
|
||||||
},
|
},
|
||||||
.age = CHILD
|
.age = CHILD,
|
||||||
|
.ageTimer = 0.0f
|
||||||
};
|
};
|
||||||
AddElementToArray(flowers, flower);
|
AddElementToArray(flowers, flower);
|
||||||
}
|
}
|
||||||
return flowers;
|
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)
|
void RenderFlower(void* element)
|
||||||
{
|
{
|
||||||
Flower* f = (Flower*)element;
|
Flower* f = (Flower*)element;
|
||||||
@@ -51,4 +71,5 @@ void RenderFlower(void* element)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // FLOWERS_H
|
#endif // FLOWERS_H
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ void UpdateGame(GameState *g, View *currentView, bool *running)
|
|||||||
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);
|
UpdatePlayer(&g->player);
|
||||||
|
UpdateArray(g->flowers, UpdateFlower);
|
||||||
// UpdateBee(&g->bee1, &g->flowers, &g->hive);
|
// 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/character.png", 48.0f, 48.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/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/character_bee.png", 16.0f, 16.0f, 0.0f},
|
||||||
{"assets/grass.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},
|
{"assets/hive.png", 32.0f, 32.0f, 0.0f},
|
||||||
|
|||||||
Reference in New Issue
Block a user