Vendored
+3
-1
@@ -2,6 +2,8 @@
|
|||||||
"files.associations": {
|
"files.associations": {
|
||||||
"asset.h": "c",
|
"asset.h": "c",
|
||||||
"stdlib.h": "c",
|
"stdlib.h": "c",
|
||||||
"view.h": "c"
|
"view.h": "c",
|
||||||
|
"__node_handle": "c",
|
||||||
|
"font.h": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vendored
+96
@@ -0,0 +1,96 @@
|
|||||||
|
#ifndef ARRAY_H
|
||||||
|
#define ARRAY_H
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void** elements;
|
||||||
|
unsigned int count;
|
||||||
|
unsigned int capacity;
|
||||||
|
} Array;
|
||||||
|
|
||||||
|
Array* CreateArray(unsigned int initCapacity){
|
||||||
|
Array* array = malloc(sizeof(Array));
|
||||||
|
if (!array) return NULL;
|
||||||
|
|
||||||
|
array->elements = malloc(sizeof(void* ) * initCapacity);
|
||||||
|
if (!array->elements) {
|
||||||
|
free(array);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
array->count = 0;
|
||||||
|
array->capacity = initCapacity;
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
int AddElementToArray(Array* array, void* element){
|
||||||
|
if(array->count >= array->capacity) {
|
||||||
|
unsigned int newCapacity = array->capacity * 2;
|
||||||
|
void** newElements = realloc(array->elements, sizeof(void*) * newCapacity);
|
||||||
|
if (!newElements) return 0;
|
||||||
|
|
||||||
|
array->elements = newElements;
|
||||||
|
array->capacity = newCapacity;
|
||||||
|
}
|
||||||
|
array->elements[array->count++] = element;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NORMAL REMOVE
|
||||||
|
// int RemoveElementFromArray(Array* array, unsigned int index){
|
||||||
|
// if (index >= array->count) return 0;
|
||||||
|
|
||||||
|
// for (unsigned int i = index; i < array->count - 1; i++) {
|
||||||
|
// array->elements[i] = array->elements[i + 1];
|
||||||
|
// }
|
||||||
|
|
||||||
|
// array->count--;
|
||||||
|
// return 1;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// SWAP AND POP REMOVE
|
||||||
|
int RemoveElementFromArray(Array* array, unsigned int index) {
|
||||||
|
if (index >= array->count) return 0;
|
||||||
|
|
||||||
|
array->elements[index] = array->elements[array->count - 1];
|
||||||
|
|
||||||
|
array->count--;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* GetRandomElementFromArray(Array* array){
|
||||||
|
if (array == NULL || array->elements == NULL || array->count == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
int randomIndex = GetRandomValue(0, (int)array->count-1);
|
||||||
|
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;
|
||||||
|
for (unsigned int i = 0; i < array->count; i++) {
|
||||||
|
renderFunc(array->elements[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FreeArray(Array** array) {
|
||||||
|
if (!array || !*array) return;
|
||||||
|
|
||||||
|
free((*array)->elements);
|
||||||
|
(*array)->elements = NULL;
|
||||||
|
|
||||||
|
free(*array);
|
||||||
|
*array = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // ARRAY_H
|
||||||
+72
-15
@@ -1,30 +1,87 @@
|
|||||||
#ifndef FLOWERS_H
|
#ifndef FLOWERS_H
|
||||||
#define FLOWERS_H
|
#define FLOWERS_H
|
||||||
|
|
||||||
#include <object.h>
|
#include "array.h"
|
||||||
|
|
||||||
ObjectArray CreateFlowers(Texture2D texture, float frameWidth, float rotation, float fieldSize)
|
typedef enum {
|
||||||
{
|
CHILD,
|
||||||
ObjectArray flowers = CreateObjectArray(&(Object){
|
TEEN,
|
||||||
.sprite = {
|
ADULT
|
||||||
.texture = texture,
|
} AGE;
|
||||||
.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);
|
|
||||||
|
|
||||||
if (!flowers.data)
|
typedef struct {
|
||||||
|
Sprite sprite;
|
||||||
|
Vector2 position;
|
||||||
|
AGE age;
|
||||||
|
float ageTimer;
|
||||||
|
} Flower;
|
||||||
|
|
||||||
|
Flower DEFAULT_FLOWER;
|
||||||
|
|
||||||
|
Array* CreateFlowers(Texture2D texture, float frameWidth, float rotation, float fieldSize)
|
||||||
{
|
{
|
||||||
|
Array* flowers = CreateArray(10);
|
||||||
|
|
||||||
|
if(!flowers) {
|
||||||
printf("Memory allocation failed.\n");
|
printf("Memory allocation failed.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetRandomPositionForObjectArray(&flowers, (Rectangle){-fieldSize, -fieldSize, fieldSize * 2, fieldSize * 2});
|
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 = DEFAULT_FLOWER;
|
||||||
|
flower->sprite.destRec = (Rectangle){(float)GetRandomValue(-fieldSize,fieldSize), (float)GetRandomValue(-fieldSize,fieldSize), frameWidth, frameWidth};
|
||||||
|
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) {
|
||||||
|
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;
|
||||||
|
if (!f) return;
|
||||||
|
RenderSprite(&(f->sprite));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // FLOWERS_H
|
#endif // FLOWERS_H
|
||||||
|
|||||||
+10
-7
@@ -7,6 +7,8 @@
|
|||||||
#include <postfx.h>
|
#include <postfx.h>
|
||||||
#include <soundtrack.h>
|
#include <soundtrack.h>
|
||||||
#include <asset.h>
|
#include <asset.h>
|
||||||
|
#include <array.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "gameassets.h"
|
#include "gameassets.h"
|
||||||
#include "floor.h"
|
#include "floor.h"
|
||||||
@@ -24,7 +26,7 @@ typedef struct
|
|||||||
RenderTexture2D target;
|
RenderTexture2D target;
|
||||||
Floor floor;
|
Floor floor;
|
||||||
Object hive;
|
Object hive;
|
||||||
ObjectArray flowers;
|
Array* flowers;
|
||||||
Player player;
|
Player player;
|
||||||
Bee bee1;
|
Bee bee1;
|
||||||
Camera2D camera;
|
Camera2D camera;
|
||||||
@@ -65,7 +67,7 @@ void InitGame(GameState *g, Window *window)
|
|||||||
|
|
||||||
// Animated Entities
|
// Animated Entities
|
||||||
g->player = CreatePlayer(IDLE_DOWN, HOE, g->textures[PLAYER], g->assets.textureAssets[PLAYER].frameWidth, 4, 2, g->hive.position, g->assets.textureAssets[PLAYER].rotation, 50.0f);
|
g->player = CreatePlayer(IDLE_DOWN, HOE, g->textures[PLAYER], g->assets.textureAssets[PLAYER].frameWidth, 4, 2, g->hive.position, g->assets.textureAssets[PLAYER].rotation, 50.0f);
|
||||||
g->bee1 = CreateBee(FLYING, g->textures[BEE], g->assets.textureAssets[BEE].frameWidth, 4, 10, g->hive.position, 10.0f, &g->flowers, &g->hive);
|
// g->bee1 = CreateBee(FLYING, g->textures[BEE], g->assets.textureAssets[BEE].frameWidth, 4, 10, g->hive.position, 10.0f, &g->flowers, &g->hive);
|
||||||
|
|
||||||
// I/O
|
// I/O
|
||||||
g->camera = CreateCamera(window->width, window->height, g->player.physics.position, 10.0f);
|
g->camera = CreateCamera(window->width, window->height, g->player.physics.position, 10.0f);
|
||||||
@@ -99,15 +101,16 @@ 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);
|
||||||
UpdateBee(&g->bee1, &g->flowers, &g->hive);
|
UpdateArray(g->flowers, UpdateFlower);
|
||||||
|
// UpdateBee(&g->bee1, &g->flowers, &g->hive);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderComponents(GameState *g)
|
void RenderComponents(GameState *g)
|
||||||
{
|
{
|
||||||
RenderFloor(&g->floor);
|
RenderFloor(&g->floor);
|
||||||
RenderSprite(&g->hive.sprite);
|
RenderSprite(&g->hive.sprite);
|
||||||
RenderObjectArray(&g->flowers);
|
RenderArray(g->flowers, RenderFlower);
|
||||||
RenderSprite(&g->player.sprite);
|
RenderSprite(&g->player.sprite);
|
||||||
RenderSprite(&g->bee1.sprite);
|
RenderSprite(&g->bee1.sprite);
|
||||||
}
|
}
|
||||||
@@ -127,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)
|
||||||
{
|
{
|
||||||
@@ -155,7 +158,7 @@ void CleanupGame(GameState *g)
|
|||||||
UnloadMusicStream(g->soundtracks[i].music);
|
UnloadMusicStream(g->soundtracks[i].music);
|
||||||
}
|
}
|
||||||
UnloadRenderTexture(g->target);
|
UnloadRenderTexture(g->target);
|
||||||
free(g->flowers.data);
|
FreeArray(&g->flowers);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // GAME_H
|
#endif // GAME_H
|
||||||
|
|||||||
@@ -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},
|
||||||
|
|||||||
+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