array.h, still needs refactor of object and objectarray
This commit is contained in:
+40
-16
@@ -1,30 +1,54 @@
|
||||
#ifndef FLOWERS_H
|
||||
#define FLOWERS_H
|
||||
|
||||
#include <object.h>
|
||||
#include "array.h"
|
||||
|
||||
ObjectArray CreateFlowers(Texture2D texture, float frameWidth, float rotation, float fieldSize)
|
||||
typedef enum {
|
||||
CHILD,
|
||||
TEEN,
|
||||
ADULT
|
||||
} AGE;
|
||||
|
||||
typedef struct {
|
||||
Sprite sprite;
|
||||
Vector2 position;
|
||||
AGE age;
|
||||
} Flower;
|
||||
|
||||
Array* CreateFlowers(Texture2D texture, float frameWidth, float rotation, float fieldSize)
|
||||
{
|
||||
ObjectArray flowers = CreateObjectArray(&(Object){
|
||||
.sprite = {
|
||||
.texture = texture,
|
||||
.sourceRec = {0.0f, 0.0f, frameWidth, frameWidth},
|
||||
.destRec = {0.0f, 0.0f, frameWidth, frameWidth},
|
||||
.origin = {frameWidth / 2, frameWidth / 2},
|
||||
.rotation = rotation,
|
||||
.color = WHITE},
|
||||
.position = {0.0f, 0.0f}},
|
||||
10);
|
||||
Array* flowers = CreateArray(10);
|
||||
|
||||
if (!flowers.data)
|
||||
{
|
||||
if(!flowers) {
|
||||
printf("Memory allocation failed.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
SetRandomPositionForObjectArray(&flowers, (Rectangle){-fieldSize, -fieldSize, fieldSize * 2, fieldSize * 2});
|
||||
|
||||
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
|
||||
};
|
||||
AddElementToArray(flowers, flower);
|
||||
}
|
||||
return flowers;
|
||||
}
|
||||
|
||||
void RenderFlower(void* element)
|
||||
{
|
||||
Flower* f = (Flower*)element;
|
||||
if (!f) return;
|
||||
RenderSprite(&(f->sprite));
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // FLOWERS_H
|
||||
|
||||
Reference in New Issue
Block a user