aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathansmith117 <thenathansmithsmith@gmail.com>2024-02-16 17:31:41 +0000
committernathansmith117 <thenathansmithsmith@gmail.com>2024-02-16 17:31:41 +0000
commit2a3b0c6057d913d931d5db361b004c89e78d0385 (patch)
tree89524e8030f126381b4346169919d7cda3287250
parent12b80da7f61df440a6e3252012436fb0baebe073 (diff)
downloadPenguinYippies-2a3b0c6057d913d931d5db361b004c89e78d0385.tar.gz
PenguinYippies-2a3b0c6057d913d931d5db361b004c89e78d0385.tar.bz2
PenguinYippies-2a3b0c6057d913d931d5db361b004c89e78d0385.zip
Animation working
-rw-r--r--src/animation.c11
-rw-r--r--src/animation.h1
-rw-r--r--src/assets.h15
-rw-r--r--src/gameCommon.h4
-rw-r--r--src/mainMenu.c13
-rw-r--r--src/mainMenu.h2
6 files changed, 41 insertions, 5 deletions
diff --git a/src/animation.c b/src/animation.c
index deb764c..52210ae 100644
--- a/src/animation.c
+++ b/src/animation.c
@@ -29,7 +29,7 @@ Animation createAnimation(AnimationAsset* asset, double delay)
animation.height = asset->image.height;
animation.delay = delay;
- animation.lastTime = -1; // -1 for no last time.
+ animation.lastTime = -1.0; // -1.0 for no last time.
return animation;
}
@@ -44,14 +44,14 @@ void setAnimationFrame(Animation* animation, int frame)
animation->currentFrame = frame;
unsigned int nextFrameDataOffset = animation->width * animation->height * 4 * frame;
- UpdateTexture(animation->texture, ((unsigned int*)animation->asset->image.data) + nextFrameDataOffset);
+ UpdateTexture(animation->texture, ((unsigned char*)animation->asset->image.data) + nextFrameDataOffset);
}
void runAnimation(Animation* animation)
{
double currentTime = GetTime();
- if (animation->lastTime == -1 || currentTime - animation->lastTime >= animation->delay)
+ if (animation->lastTime == -1.0 || currentTime - animation->lastTime >= animation->delay)
{
// Count the frames up.
int newFrame = animation->currentFrame + 1;
@@ -67,3 +67,8 @@ void runAnimation(Animation* animation)
animation->lastTime = currentTime;
}
}
+
+void pauseAnimation(Animation* animation)
+{
+ animation->lastTime = -1.0;
+}
diff --git a/src/animation.h b/src/animation.h
index 963af74..6a632eb 100644
--- a/src/animation.h
+++ b/src/animation.h
@@ -40,5 +40,6 @@ void closeAnimation(Animation* animation);
void setAnimationFrame(Animation* animation, int frame);
void runAnimation(Animation* animation);
+void pauseAnimation(Animation* animation);
#endif
diff --git a/src/assets.h b/src/assets.h
index 8dd9e51..8b2b533 100644
--- a/src/assets.h
+++ b/src/assets.h
@@ -2,6 +2,7 @@
#include "animation.h"
#define ASSETS_NAME_MAX 100
+
#define TEXTURE_ASSET_COUNT 4
#define ANIMATION_ASSET_COUNT 2
@@ -12,6 +13,20 @@
extern const char textureAssetsNames[TEXTURE_ASSET_COUNT][ASSETS_NAME_MAX];
extern const char animationAssetsNames[ANIMATION_ASSET_COUNT][ASSETS_NAME_MAX];
+enum
+{
+ MAIN_SCREEN_BACKGROUND_TEXTURE,
+ PENGUIN_BACKGROUND_BACKGROUND,
+ TO_EMPERORS_EMPORIUM_ICON_TEXTURE,
+ TO_GAME_ICON_TEXTURE
+};
+
+enum
+{
+ BUTTON_BOX_ANIMATION,
+ PENGUIN_LOL_ANIMATION
+};
+
typedef struct Assets {
Texture textures[TEXTURE_ASSET_COUNT];
AnimationAsset animations[ANIMATION_ASSET_COUNT];
diff --git a/src/gameCommon.h b/src/gameCommon.h
index fd6f999..c46671c 100644
--- a/src/gameCommon.h
+++ b/src/gameCommon.h
@@ -5,8 +5,8 @@
#include <raylib.h>
#include <raymath.h>
-#define WINDOW_WIDTH 640
-#define WINDOW_HEIGHT 480
+#define WINDOW_WIDTH 1280
+#define WINDOW_HEIGHT 720
#ifndef GAME_COMMON_H
#define GAME_COMMON_H
diff --git a/src/mainMenu.c b/src/mainMenu.c
index ec8bd95..e5d3b60 100644
--- a/src/mainMenu.c
+++ b/src/mainMenu.c
@@ -1,14 +1,27 @@
#include "mainMenu.h"
#include "game.h"
+#include "assets.h"
+#include <raylib.h>
void initMainMenu(MainMenu* mainMenu, Game* game)
{
+ mainMenu->startButtonAnimation = createAnimation(
+ &game->assets.animations[BUTTON_BOX_ANIMATION],
+ ANIMATION_DEFAULT_DELAY
+ );
}
void updateMainMenu(MainMenu* mainMenu, Game* game)
{
+ ClearBackground(RAYWHITE);
+
+ DrawTextureEx(mainMenu->startButtonAnimation.texture, (Vector2){100.0, 100.0}, 0.0, 1.0, WHITE);
+ runAnimation(&mainMenu->startButtonAnimation);
+
+ DrawFPS(0, 0);
}
void closeMainMenu(MainMenu* mainMenu)
{
+ closeAnimation(&mainMenu->startButtonAnimation);
}
diff --git a/src/mainMenu.h b/src/mainMenu.h
index c8b9fb3..f2722a3 100644
--- a/src/mainMenu.h
+++ b/src/mainMenu.h
@@ -1,9 +1,11 @@
#include "gameCommon.h"
+#include "animation.h"
#ifndef MAIN_MENU_H
#define MAIN_MENU_H
typedef struct MainMenu {
+ Animation startButtonAnimation;
} MainMenu;
void initMainMenu(MainMenu* mainMenu, Game* game);