feat: flower plant on player location

This commit is contained in:
beyer-rebecca
2025-04-12 21:59:25 +02:00
committed by huaqo
parent 79c6a058c7
commit 23f16988b3
4 changed files with 34 additions and 19 deletions
+24 -12
View File
@@ -16,6 +16,8 @@ typedef struct {
float ageTimer;
} Flower;
Flower DEFAULT_FLOWER;
Array* CreateFlowers(Texture2D texture, float frameWidth, float rotation, float fieldSize)
{
Array* flowers = CreateArray(10);
@@ -25,25 +27,35 @@ Array* CreateFlowers(Texture2D texture, float frameWidth, float rotation, float
exit(1);
}
DEFAULT_FLOWER = (Flower){
.sprite = {
.texture = texture,
.sourceRec = {0.0f, 0.0f, frameWidth, frameWidth},
.destRec = {(float)GetRandomValue(-fieldSize,fieldSize), (float)GetRandomValue(-fieldSize,fieldSize), frameWidth, frameWidth},
.origin = {frameWidth / 2, frameWidth / 2},
.rotation = rotation,
.color = WHITE,
},
.age = CHILD,
.ageTimer = 0.0f
};
for (int i = 0; i < 10; i++) {
Flower* flower = malloc(sizeof(Flower));
*flower = (Flower){
.sprite = {
.texture = texture,
.sourceRec = {0.0f, 0.0f, frameWidth, frameWidth},
.destRec = {(float)GetRandomValue(-fieldSize,fieldSize), (float)GetRandomValue(-fieldSize,fieldSize), frameWidth, frameWidth},
.origin = {frameWidth / 2, frameWidth / 2},
.rotation = rotation,
.color = WHITE,
},
.age = CHILD,
.ageTimer = 0.0f
};
*flower = DEFAULT_FLOWER;
flower->sprite.destRec = (Rectangle){(float)GetRandomValue(-fieldSize,fieldSize), (float)GetRandomValue(-fieldSize,fieldSize), frameWidth, frameWidth};
AddElementToArray(flowers, flower);
}
return flowers;
}
void AddFlower(Array* flowers, Rectangle rec){
Flower* flower = malloc(sizeof(Flower));
*flower = DEFAULT_FLOWER;
flower->sprite.destRec = rec;
AddElementToArray(flowers, flower);
}
void UpdateFlower(void* element) {
Flower* f = (Flower*)element;