feat: flower plant on player location
This commit is contained in:
+15
-3
@@ -16,6 +16,8 @@ typedef struct {
|
|||||||
float ageTimer;
|
float ageTimer;
|
||||||
} Flower;
|
} Flower;
|
||||||
|
|
||||||
|
Flower DEFAULT_FLOWER;
|
||||||
|
|
||||||
Array* CreateFlowers(Texture2D texture, float frameWidth, float rotation, float fieldSize)
|
Array* CreateFlowers(Texture2D texture, float frameWidth, float rotation, float fieldSize)
|
||||||
{
|
{
|
||||||
Array* flowers = CreateArray(10);
|
Array* flowers = CreateArray(10);
|
||||||
@@ -25,9 +27,7 @@ Array* CreateFlowers(Texture2D texture, float frameWidth, float rotation, float
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) {
|
DEFAULT_FLOWER = (Flower){
|
||||||
Flower* flower = malloc(sizeof(Flower));
|
|
||||||
*flower = (Flower){
|
|
||||||
.sprite = {
|
.sprite = {
|
||||||
.texture = texture,
|
.texture = texture,
|
||||||
.sourceRec = {0.0f, 0.0f, frameWidth, frameWidth},
|
.sourceRec = {0.0f, 0.0f, frameWidth, frameWidth},
|
||||||
@@ -39,11 +39,23 @@ Array* CreateFlowers(Texture2D texture, float frameWidth, float rotation, float
|
|||||||
.age = CHILD,
|
.age = CHILD,
|
||||||
.ageTimer = 0.0f
|
.ageTimer = 0.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
Flower* flower = malloc(sizeof(Flower));
|
||||||
|
*flower = DEFAULT_FLOWER;
|
||||||
|
flower->sprite.destRec = (Rectangle){(float)GetRandomValue(-fieldSize,fieldSize), (float)GetRandomValue(-fieldSize,fieldSize), frameWidth, frameWidth};
|
||||||
AddElementToArray(flowers, flower);
|
AddElementToArray(flowers, flower);
|
||||||
}
|
}
|
||||||
return flowers;
|
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) {
|
void UpdateFlower(void* element) {
|
||||||
Flower* f = (Flower*)element;
|
Flower* f = (Flower*)element;
|
||||||
|
|||||||
+2
-2
@@ -101,7 +101,7 @@ void UpdateGame(GameState *g, View *currentView, bool *running)
|
|||||||
UpdateMouse(&g->mouse, &g->camera);
|
UpdateMouse(&g->mouse, &g->camera);
|
||||||
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, g->flowers);
|
||||||
UpdateArray(g->flowers, UpdateFlower);
|
UpdateArray(g->flowers, UpdateFlower);
|
||||||
// UpdateBee(&g->bee1, &g->flowers, &g->hive);
|
// UpdateBee(&g->bee1, &g->flowers, &g->hive);
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,7 @@ void RenderGame(GameState *g, const State *appState, Flags *flags)
|
|||||||
{
|
{
|
||||||
RenderPostFX(&g->postFX[i], &g->target);
|
RenderPostFX(&g->postFX[i], &g->target);
|
||||||
}
|
}
|
||||||
DrawText(TextFormat("%d", g->player.inventar.seedCount), 10, 10, 50, WHITE);
|
DrawText(TextFormat("Flower Seeds: %d", g->player.inventar.flowerSeedCount), 10, 10, 50, WHITE);
|
||||||
|
|
||||||
if (flags->showFPS)
|
if (flags->showFPS)
|
||||||
{
|
{
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
int seedCount;
|
int flowerSeedCount;
|
||||||
} Inventar;
|
} Inventar;
|
||||||
|
|
||||||
#endif // INVENTAR_H
|
#endif // INVENTAR_H
|
||||||
|
|||||||
+7
-4
@@ -5,7 +5,9 @@
|
|||||||
#include <animation.h>
|
#include <animation.h>
|
||||||
#include <physics.h>
|
#include <physics.h>
|
||||||
#include <input.h>
|
#include <input.h>
|
||||||
|
#include <array.h>
|
||||||
|
|
||||||
|
#include "flowers.h"
|
||||||
#include "inventar.h"
|
#include "inventar.h"
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
@@ -70,7 +72,7 @@ Player CreatePlayer(PlayerAnimationState animState, SelectedTool selectedTool, T
|
|||||||
.color = WHITE},
|
.color = WHITE},
|
||||||
.animation = {.state = animState, .currentFrame = 0, .maxFrame = maxFrame, .framesCounter = 0, .framesSpeed = framesSpeed, .animTimer = 0.0f},
|
.animation = {.state = animState, .currentFrame = 0, .maxFrame = maxFrame, .framesCounter = 0, .framesSpeed = framesSpeed, .animTimer = 0.0f},
|
||||||
.physics = {.position = startPosition, .direction = (Vector2){0.0f, 0.0f}, .speed = speed},
|
.physics = {.position = startPosition, .direction = (Vector2){0.0f, 0.0f}, .speed = speed},
|
||||||
.inventar = {.seedCount = 6}};
|
.inventar = {.flowerSeedCount = 6}};
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdatePlayerAnimationState(int *state, SelectedTool *selectedTool, Vector2 *dir)
|
void UpdatePlayerAnimationState(int *state, SelectedTool *selectedTool, Vector2 *dir)
|
||||||
@@ -129,11 +131,12 @@ void UpdatePlayerAnimationState(int *state, SelectedTool *selectedTool, Vector2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdatePlayer(Player *player)
|
void UpdatePlayer(Player *player, Array* flowers)
|
||||||
{
|
{
|
||||||
if (IsKeyPressed(KEY_SPACE) && player->inventar.seedCount > 0)
|
if (IsKeyPressed(KEY_SPACE) && player->inventar.flowerSeedCount > 0)
|
||||||
{
|
{
|
||||||
player->inventar.seedCount--;
|
AddFlower(flowers, player->sprite.destRec);
|
||||||
|
player->inventar.flowerSeedCount--;
|
||||||
}
|
}
|
||||||
Vector2 dir = GetDirectionVector();
|
Vector2 dir = GetDirectionVector();
|
||||||
UpdatePlayerAnimationState(&player->animation.state, &player->selectedTool, &dir);
|
UpdatePlayerAnimationState(&player->animation.state, &player->selectedTool, &dir);
|
||||||
|
|||||||
Reference in New Issue
Block a user