player now a human with animation depending on direction and movement
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 9.6 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 311 B |
|
After Width: | Height: | Size: 298 B |
|
After Width: | Height: | Size: 306 B |
|
After Width: | Height: | Size: 299 B |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 805 B |
|
After Width: | Height: | Size: 810 B |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 749 B |
|
After Width: | Height: | Size: 761 B |
|
After Width: | Height: | Size: 3.4 KiB |
@@ -14,6 +14,7 @@
|
|||||||
#include "flowers.h"
|
#include "flowers.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
PLAYER,
|
||||||
FLOWER,
|
FLOWER,
|
||||||
BEE,
|
BEE,
|
||||||
GRASS,
|
GRASS,
|
||||||
@@ -21,11 +22,12 @@ typedef enum {
|
|||||||
TEX_COUNT
|
TEX_COUNT
|
||||||
} TextureID;
|
} TextureID;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PostProcessing postFX;
|
PostProcessing postFX;
|
||||||
MyMusic ambient;
|
MyMusic ambient;
|
||||||
RenderTexture2D target;
|
RenderTexture2D target;
|
||||||
Texture2D flowerTexture, beeTexture, floorTexture, hiveTexture;
|
|
||||||
Floor floor;
|
Floor floor;
|
||||||
Object hive;
|
Object hive;
|
||||||
ObjectArray flowers;
|
ObjectArray flowers;
|
||||||
@@ -33,11 +35,12 @@ typedef struct {
|
|||||||
Bee bee1;
|
Bee bee1;
|
||||||
Camera2D camera;
|
Camera2D camera;
|
||||||
Mouse mouse;
|
Mouse mouse;
|
||||||
|
Image image;
|
||||||
TextureAsset textureAssets[TEX_COUNT];
|
TextureAsset textureAssets[TEX_COUNT];
|
||||||
Texture2D textures[TEX_COUNT];
|
Texture2D textures[TEX_COUNT];
|
||||||
} GameState;
|
} GameState;
|
||||||
|
|
||||||
void InitGame(GameState* g){
|
void InitGame(GameState* g, Display *display){
|
||||||
|
|
||||||
InitAudioDevice();
|
InitAudioDevice();
|
||||||
|
|
||||||
@@ -45,29 +48,32 @@ void InitGame(GameState* g){
|
|||||||
|
|
||||||
g->ambient = CreateMusic("assets/beez.mp3");
|
g->ambient = CreateMusic("assets/beez.mp3");
|
||||||
|
|
||||||
|
g->textureAssets[PLAYER] = (TextureAsset){"assets/character/character.png", 64.0f, 64.0f, 180.0f};
|
||||||
g->textureAssets[FLOWER] = (TextureAsset){"assets/flower.png", 16.0f, 16.0f, 45.0f};
|
g->textureAssets[FLOWER] = (TextureAsset){"assets/flower.png", 16.0f, 16.0f, 45.0f};
|
||||||
g->textureAssets[BEE] = (TextureAsset){"assets/character_bee.png", 16.0f, 16.0f, 0.0f};
|
g->textureAssets[BEE] = (TextureAsset){"assets/character_bee.png", 16.0f, 16.0f, 0.0f};
|
||||||
g->textureAssets[GRASS] = (TextureAsset){"assets/grass.png", 16.0f, 16.0f, 0.0f};
|
g->textureAssets[GRASS] = (TextureAsset){"assets/grass.png", 16.0f, 16.0f, 0.0f};
|
||||||
g->textureAssets[HIVE] = (TextureAsset){"assets/hive.png", 32.0f, 32.0f, 0.0f};
|
g->textureAssets[HIVE] = (TextureAsset){"assets/hive.png", 32.0f, 32.0f, 0.0f};
|
||||||
|
|
||||||
|
g->textures[PLAYER] = LoadTexture(g->textureAssets[PLAYER].path);
|
||||||
g->textures[FLOWER] = LoadTexture(g->textureAssets[FLOWER].path);
|
g->textures[FLOWER] = LoadTexture(g->textureAssets[FLOWER].path);
|
||||||
g->textures[BEE] = LoadTexture(g->textureAssets[BEE].path);
|
g->textures[BEE] = LoadTexture(g->textureAssets[BEE].path);
|
||||||
g->textures[GRASS] = LoadTexture(g->textureAssets[GRASS].path);
|
g->textures[GRASS] = LoadTexture(g->textureAssets[GRASS].path);
|
||||||
g->textures[HIVE] = LoadTexture(g->textureAssets[HIVE].path);
|
g->textures[HIVE] = LoadTexture(g->textureAssets[HIVE].path);
|
||||||
|
|
||||||
|
g->player = CreatePlayer(g->textures[PLAYER], g->textureAssets[PLAYER].frameWidth, 4, 5, g->hive.position, g->textureAssets[PLAYER].rotation, 50.0f);
|
||||||
g->flowers = CreateFlowers(g->textures[FLOWER], g->textureAssets[FLOWER].frameWidth, g->textureAssets[FLOWER].rotation, 50.0f);
|
g->flowers = CreateFlowers(g->textures[FLOWER], g->textureAssets[FLOWER].frameWidth, g->textureAssets[FLOWER].rotation, 50.0f);
|
||||||
g->player = CreatePlayer(g->textures[BEE], g->textureAssets[BEE].frameWidth, 4, 10, g->hive.position, 50.0f);
|
|
||||||
g->floor = CreateFloor(g->textures[GRASS], g->textureAssets[GRASS].frameWidth);
|
g->floor = CreateFloor(g->textures[GRASS], g->textureAssets[GRASS].frameWidth);
|
||||||
g->hive = CreateHive(g->textures[HIVE], g->textureAssets[HIVE].frameWidth);
|
g->hive = CreateHive(g->textures[HIVE], g->textureAssets[HIVE].frameWidth);
|
||||||
g->bee1 = CreateBee(g->textures[BEE], g->textureAssets[BEE].frameWidth, 4, 10, g->hive.position, 10.0f, &g->flowers, &g->hive);
|
g->bee1 = CreateBee(g->textures[BEE], g->textureAssets[BEE].frameWidth, 4, 10, g->hive.position, 10.0f, &g->flowers, &g->hive);
|
||||||
|
|
||||||
g->camera = CreateCamera(GetScreenWidth(), GetScreenHeight(), g->player.physics.position, 10.0f);
|
g->camera = CreateCamera(display->width, display->height, g->player.physics.position, 5.0f);
|
||||||
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f);
|
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f);
|
||||||
|
|
||||||
g->target = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
|
g->target = LoadRenderTexture(display->width, display->height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateGame(GameState* g, State *state){
|
void UpdateGame(GameState* g, State *state){
|
||||||
|
SetTargetFPS(0);
|
||||||
UpdatePostFX(&g->postFX);
|
UpdatePostFX(&g->postFX);
|
||||||
UpdateMusic(&g->ambient);
|
UpdateMusic(&g->ambient);
|
||||||
UpdateMouse(&g->mouse, &g->camera);
|
UpdateMouse(&g->mouse, &g->camera);
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ void UpdateLogo(LogoState *l, State *state) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (l->state == 4) { // State 4: Transition to GAMEPLAY
|
else if (l->state == 4) { // State 4: Transition to GAMEPLAY
|
||||||
SetTargetFPS(0);
|
|
||||||
state->currentScreen = MENU;
|
state->currentScreen = MENU;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,21 +5,33 @@
|
|||||||
#include "../engine/physics.h"
|
#include "../engine/physics.h"
|
||||||
#include "../engine/input.h"
|
#include "../engine/input.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
IDLE_UP,
|
||||||
|
IDLE_LEFT,
|
||||||
|
IDLE_DOWN,
|
||||||
|
IDLE_RIGHT,
|
||||||
|
WALKING_UP,
|
||||||
|
WALKING_LEFT,
|
||||||
|
WALKING_DOWN,
|
||||||
|
WALKING_RIGHT
|
||||||
|
} PlayerState;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
PlayerState state;
|
||||||
Sprite sprite;
|
Sprite sprite;
|
||||||
Animation animation;
|
Animation animation;
|
||||||
Physics physics;
|
Physics physics;
|
||||||
} Player;
|
} Player;
|
||||||
|
|
||||||
Player CreatePlayer(Texture2D texture, float frameWidth, int maxFrame, int framesSpeed, Vector2 startPosition, float speed){
|
Player CreatePlayer(Texture2D texture, float frameWidth, int maxFrame, int framesSpeed, Vector2 startPosition, float rotation, float speed){
|
||||||
return (Player){
|
return (Player){
|
||||||
.sprite = {
|
.sprite = {
|
||||||
.texture = texture,
|
.texture = texture,
|
||||||
.frameSize = {frameWidth, frameWidth},
|
.frameSize = {frameWidth, frameWidth},
|
||||||
.sourceRec = {0.0f, 0.0f, frameWidth, frameWidth},
|
.sourceRec = {0.0f,0.0f, frameWidth, frameWidth},
|
||||||
.destRec = {0.0f, 0.0f, frameWidth, frameWidth},
|
.destRec = {0.0f, 0.0f, frameWidth, frameWidth},
|
||||||
.origin = {frameWidth / 2, frameWidth / 2},
|
.origin = {frameWidth / 2, frameWidth / 2},
|
||||||
.rotation = 0.0f,
|
.rotation = rotation,
|
||||||
.color = WHITE
|
.color = WHITE
|
||||||
},
|
},
|
||||||
.animation = {
|
.animation = {
|
||||||
@@ -37,12 +49,34 @@ Player CreatePlayer(Texture2D texture, float frameWidth, int maxFrame, int frame
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UpdateState(PlayerState *state) {
|
||||||
|
Vector2 dir = GetDirectionVector();
|
||||||
|
|
||||||
|
if (dir.x == 0 && dir.y == 0) {
|
||||||
|
switch (*state) {
|
||||||
|
case WALKING_DOWN: *state = IDLE_DOWN; break;
|
||||||
|
case WALKING_UP: *state = IDLE_UP; break;
|
||||||
|
case WALKING_RIGHT: *state = IDLE_RIGHT; break;
|
||||||
|
case WALKING_LEFT: *state = IDLE_LEFT; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (dir.y == -1) *state = WALKING_DOWN;
|
||||||
|
else if (dir.y == 1) *state = WALKING_UP;
|
||||||
|
else if (dir.x == 1) *state = WALKING_RIGHT;
|
||||||
|
else if (dir.x == -1) *state = WALKING_LEFT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void UpdatePlayer(Player* player){
|
void UpdatePlayer(Player* player){
|
||||||
UpdatePhysics(&player->physics, GetDirectionVector());
|
UpdatePhysics(&player->physics, GetDirectionVector());
|
||||||
UpdateSpriteRotation(&player->sprite, &player->physics.direction);
|
UpdateState(&player->state);
|
||||||
|
// UpdateSpriteRotation(&player->sprite, &player->physics.direction);
|
||||||
UpdateSpriteDestRec(&player->sprite, &player->physics.position);
|
UpdateSpriteDestRec(&player->sprite, &player->physics.position);
|
||||||
UpdateAnimation(&player->animation, GetFrameTime());
|
UpdateAnimation(&player->animation, GetFrameTime());
|
||||||
UpdateSpriteSourceRec(&player->sprite, &(Vector2){player->sprite.frameSize.x, player->sprite.frameSize.x * player->animation.currentFrame});
|
UpdateSpriteSourceRec(&player->sprite, &(Vector2){player->sprite.frameSize.x * player->state, player->sprite.frameSize.y * player->animation.currentFrame});
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // PLAYER_H
|
#endif // PLAYER_H
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ typedef struct {
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
Application app;
|
Application app;
|
||||||
app.state.currentScreen = LOGO;
|
app.state.currentScreen = GAMEPLAY;
|
||||||
app.state.running = true;
|
app.state.running = true;
|
||||||
app.state.gameStarted = false;
|
app.state.gameStarted = false;
|
||||||
app.display.name = "The Last Hive";
|
app.display.name = "The Last Hive";
|
||||||
@@ -31,7 +31,7 @@ int main(void)
|
|||||||
|
|
||||||
InitLogo(&app.logo);
|
InitLogo(&app.logo);
|
||||||
InitMenu(&app.menu);
|
InitMenu(&app.menu);
|
||||||
InitGame(&app.game);
|
InitGame(&app.game,&app.display);
|
||||||
|
|
||||||
while (app.state.running)
|
while (app.state.running)
|
||||||
{
|
{
|
||||||
|
|||||||