diff --git a/assets/Clouds/Clouds1/1.png b/assets/Clouds/Clouds1/1.png new file mode 100644 index 0000000..9ede45f Binary files /dev/null and b/assets/Clouds/Clouds1/1.png differ diff --git a/assets/Clouds/Clouds1/2.png b/assets/Clouds/Clouds1/2.png new file mode 100644 index 0000000..b58be96 Binary files /dev/null and b/assets/Clouds/Clouds1/2.png differ diff --git a/assets/Clouds/Clouds1/3.png b/assets/Clouds/Clouds1/3.png new file mode 100644 index 0000000..a5818cc Binary files /dev/null and b/assets/Clouds/Clouds1/3.png differ diff --git a/assets/Clouds/Clouds1/4.png b/assets/Clouds/Clouds1/4.png new file mode 100644 index 0000000..c2741c7 Binary files /dev/null and b/assets/Clouds/Clouds1/4.png differ diff --git a/assets/Clouds/Clouds2/1.png b/assets/Clouds/Clouds2/1.png new file mode 100644 index 0000000..bf39b1e Binary files /dev/null and b/assets/Clouds/Clouds2/1.png differ diff --git a/assets/Clouds/Clouds2/2.png b/assets/Clouds/Clouds2/2.png new file mode 100644 index 0000000..e37d51f Binary files /dev/null and b/assets/Clouds/Clouds2/2.png differ diff --git a/assets/Clouds/Clouds2/3.png b/assets/Clouds/Clouds2/3.png new file mode 100644 index 0000000..ad3bcba Binary files /dev/null and b/assets/Clouds/Clouds2/3.png differ diff --git a/assets/Clouds/Clouds2/4.png b/assets/Clouds/Clouds2/4.png new file mode 100644 index 0000000..b9d70f1 Binary files /dev/null and b/assets/Clouds/Clouds2/4.png differ diff --git a/assets/Clouds/Clouds3/1.png b/assets/Clouds/Clouds3/1.png new file mode 100644 index 0000000..273a5a2 Binary files /dev/null and b/assets/Clouds/Clouds3/1.png differ diff --git a/assets/Clouds/Clouds3/2.png b/assets/Clouds/Clouds3/2.png new file mode 100644 index 0000000..a523b4d Binary files /dev/null and b/assets/Clouds/Clouds3/2.png differ diff --git a/assets/Clouds/Clouds3/3.png b/assets/Clouds/Clouds3/3.png new file mode 100644 index 0000000..7a9c555 Binary files /dev/null and b/assets/Clouds/Clouds3/3.png differ diff --git a/assets/Clouds/Clouds3/4.png b/assets/Clouds/Clouds3/4.png new file mode 100644 index 0000000..ca59ca6 Binary files /dev/null and b/assets/Clouds/Clouds3/4.png differ diff --git a/assets/Clouds/Clouds4/1.png b/assets/Clouds/Clouds4/1.png new file mode 100644 index 0000000..5958dc0 Binary files /dev/null and b/assets/Clouds/Clouds4/1.png differ diff --git a/assets/Clouds/Clouds4/2.png b/assets/Clouds/Clouds4/2.png new file mode 100644 index 0000000..bc17a9a Binary files /dev/null and b/assets/Clouds/Clouds4/2.png differ diff --git a/assets/Clouds/Clouds4/3.png b/assets/Clouds/Clouds4/3.png new file mode 100644 index 0000000..7b0b945 Binary files /dev/null and b/assets/Clouds/Clouds4/3.png differ diff --git a/assets/Clouds/Clouds4/4.png b/assets/Clouds/Clouds4/4.png new file mode 100644 index 0000000..f247fe2 Binary files /dev/null and b/assets/Clouds/Clouds4/4.png differ diff --git a/assets/Clouds/Clouds5/1.png b/assets/Clouds/Clouds5/1.png new file mode 100644 index 0000000..8dd4390 Binary files /dev/null and b/assets/Clouds/Clouds5/1.png differ diff --git a/assets/Clouds/Clouds5/2.png b/assets/Clouds/Clouds5/2.png new file mode 100644 index 0000000..b395da8 Binary files /dev/null and b/assets/Clouds/Clouds5/2.png differ diff --git a/assets/Clouds/Clouds5/3.png b/assets/Clouds/Clouds5/3.png new file mode 100644 index 0000000..fd8af88 Binary files /dev/null and b/assets/Clouds/Clouds5/3.png differ diff --git a/assets/Clouds/Clouds5/4.png b/assets/Clouds/Clouds5/4.png new file mode 100644 index 0000000..5b3b5ef Binary files /dev/null and b/assets/Clouds/Clouds5/4.png differ diff --git a/assets/Clouds/Clouds5/5.png b/assets/Clouds/Clouds5/5.png new file mode 100644 index 0000000..6519e85 Binary files /dev/null and b/assets/Clouds/Clouds5/5.png differ diff --git a/assets/Clouds/Clouds6/1.png b/assets/Clouds/Clouds6/1.png new file mode 100644 index 0000000..6061e45 Binary files /dev/null and b/assets/Clouds/Clouds6/1.png differ diff --git a/assets/Clouds/Clouds6/2.png b/assets/Clouds/Clouds6/2.png new file mode 100644 index 0000000..9ccc01b Binary files /dev/null and b/assets/Clouds/Clouds6/2.png differ diff --git a/assets/Clouds/Clouds6/3.png b/assets/Clouds/Clouds6/3.png new file mode 100644 index 0000000..58c2942 Binary files /dev/null and b/assets/Clouds/Clouds6/3.png differ diff --git a/assets/Clouds/Clouds6/4.png b/assets/Clouds/Clouds6/4.png new file mode 100644 index 0000000..8d30b26 Binary files /dev/null and b/assets/Clouds/Clouds6/4.png differ diff --git a/assets/Clouds/Clouds6/5.png b/assets/Clouds/Clouds6/5.png new file mode 100644 index 0000000..f7f13d0 Binary files /dev/null and b/assets/Clouds/Clouds6/5.png differ diff --git a/assets/Clouds/Clouds6/6.png b/assets/Clouds/Clouds6/6.png new file mode 100644 index 0000000..436bda0 Binary files /dev/null and b/assets/Clouds/Clouds6/6.png differ diff --git a/assets/Clouds/Clouds7/1.png b/assets/Clouds/Clouds7/1.png new file mode 100644 index 0000000..be878dc Binary files /dev/null and b/assets/Clouds/Clouds7/1.png differ diff --git a/assets/Clouds/Clouds7/2.png b/assets/Clouds/Clouds7/2.png new file mode 100644 index 0000000..b86ad59 Binary files /dev/null and b/assets/Clouds/Clouds7/2.png differ diff --git a/assets/Clouds/Clouds7/3.png b/assets/Clouds/Clouds7/3.png new file mode 100644 index 0000000..1f3df64 Binary files /dev/null and b/assets/Clouds/Clouds7/3.png differ diff --git a/assets/Clouds/Clouds7/4.png b/assets/Clouds/Clouds7/4.png new file mode 100644 index 0000000..59d9254 Binary files /dev/null and b/assets/Clouds/Clouds7/4.png differ diff --git a/assets/Clouds/Clouds8/1.png b/assets/Clouds/Clouds8/1.png new file mode 100644 index 0000000..fb04977 Binary files /dev/null and b/assets/Clouds/Clouds8/1.png differ diff --git a/assets/Clouds/Clouds8/2.png b/assets/Clouds/Clouds8/2.png new file mode 100644 index 0000000..0708297 Binary files /dev/null and b/assets/Clouds/Clouds8/2.png differ diff --git a/assets/Clouds/Clouds8/3.png b/assets/Clouds/Clouds8/3.png new file mode 100644 index 0000000..693ca85 Binary files /dev/null and b/assets/Clouds/Clouds8/3.png differ diff --git a/assets/Clouds/Clouds8/4.png b/assets/Clouds/Clouds8/4.png new file mode 100644 index 0000000..3e474a1 Binary files /dev/null and b/assets/Clouds/Clouds8/4.png differ diff --git a/assets/Clouds/Clouds8/5.png b/assets/Clouds/Clouds8/5.png new file mode 100644 index 0000000..a93171f Binary files /dev/null and b/assets/Clouds/Clouds8/5.png differ diff --git a/assets/Clouds/Clouds8/6.png b/assets/Clouds/Clouds8/6.png new file mode 100644 index 0000000..e39d0ba Binary files /dev/null and b/assets/Clouds/Clouds8/6.png differ diff --git a/assets/SproutLandsUI/Spritesheets/Mouse sprites/Triangle Mouse icon 1.png b/assets/SproutLandsUI/Spritesheets/Mouse sprites/TriangleMouseicon1.png similarity index 100% rename from assets/SproutLandsUI/Spritesheets/Mouse sprites/Triangle Mouse icon 1.png rename to assets/SproutLandsUI/Spritesheets/Mouse sprites/TriangleMouseicon1.png diff --git a/assets/SproutLandsUI/Spritesheets/UIBigPlayButtonHover.aseprite b/assets/SproutLandsUI/Spritesheets/UIBigPlayButtonHover.aseprite new file mode 100644 index 0000000..fef2bac Binary files /dev/null and b/assets/SproutLandsUI/Spritesheets/UIBigPlayButtonHover.aseprite differ diff --git a/assets/SproutLandsUI/Spritesheets/UIBigPlayButtonHover.png b/assets/SproutLandsUI/Spritesheets/UIBigPlayButtonHover.png new file mode 100644 index 0000000..ccb3341 Binary files /dev/null and b/assets/SproutLandsUI/Spritesheets/UIBigPlayButtonHover.png differ diff --git a/assets/merrygoround.wav b/assets/merrygoround.wav new file mode 100644 index 0000000..20d9eec Binary files /dev/null and b/assets/merrygoround.wav differ diff --git a/docs/roadmap.md b/docs/roadmap.md index 026e5f8..2465c55 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -7,4 +7,5 @@ - [ ] Init values should be stored in a seperate file and loaded. When clicking new game game should reload all init values - [ ] Create layers enum and render layers in their order. removes code order rendering. Group same layer (z) height object in one layer - [ ] Fix asset include rotation temporary fix with 180 -- [x] Custom Font and Title in Menu \ No newline at end of file +- [x] Custom Font and Title in Menu +- [ ] Cursord logic can be moved from game and menu to main but deactivatet at logo \ No newline at end of file diff --git a/src/engine/gamegui.h b/src/engine/gamegui.h index 9ada1d1..492c485 100644 --- a/src/engine/gamegui.h +++ b/src/engine/gamegui.h @@ -6,6 +6,7 @@ typedef enum { NOT_CLICKED, + HOVER, CLICKED } ButtonState; @@ -13,8 +14,10 @@ typedef struct { Sprite sprite; Vector2 notClicked; + Vector2 hover; Vector2 clicked; bool isHovered; + bool isClicked; } ImageButton; typedef struct @@ -22,7 +25,7 @@ typedef struct Sprite sprite; } ImageElement; -ImageButton CreateImageButton(ButtonState state, Texture2D *texture, const TextureAsset *asset, Vector2 *source, Vector2 *clicked, Rectangle *destRec){ +ImageButton CreateImageButton(ButtonState state, Texture2D *texture, const TextureAsset *asset, Vector2 *source, Vector2 *clicked, Vector2 *hover, Rectangle *destRec){ return (ImageButton){ .sprite = { .texture = *texture, @@ -34,6 +37,7 @@ ImageButton CreateImageButton(ButtonState state, Texture2D *texture, const Textu .color = WHITE }, .notClicked = (Vector2){source->x, source->y}, + .hover = *hover, .clicked = *clicked }; } @@ -52,47 +56,32 @@ ImageElement CreateImageElement(Texture2D *texture, const TextureAsset *asset, V }; } -void PrintImageButton(const ImageButton btn) { - printf("ImageButton:\n"); - printf(" Sprite.texture: id = %d\n", btn.sprite.texture.id); - printf(" Sprite.sourceRec: x = %f, y = %f, width = %f, height = %f\n", - btn.sprite.sourceRec.x, btn.sprite.sourceRec.y, - btn.sprite.sourceRec.width, btn.sprite.sourceRec.height); - printf(" Sprite.destRec: x = %f, y = %f, width = %f, height = %f\n", - btn.sprite.destRec.x, btn.sprite.destRec.y, - btn.sprite.destRec.width, btn.sprite.destRec.height); - printf(" Sprite.frameSize: x = %f, y = %f\n", - btn.sprite.frameSize.x, btn.sprite.frameSize.y); - printf(" Sprite.origin: x = %f, y = %f\n", - btn.sprite.origin.x, btn.sprite.origin.y); - printf(" Sprite.rotation: %f\n", btn.sprite.rotation); - printf(" Sprite.color: r = %d, g = %d, b = %d, a = %d\n", - btn.sprite.color.r, btn.sprite.color.g, - btn.sprite.color.b, btn.sprite.color.a); - printf(" notClicked: x = %f, y = %f\n", btn.notClicked.x, btn.notClicked.y); - printf(" clicked: x = %f, y = %f\n", btn.clicked.x, btn.clicked.y); -} - int isImageButtonClicked(ImageButton *b, Sound soundHover, Sound soundClick){ if (CheckCollisionPointRec(GetMousePosition(), b->sprite.destRec)) { if (!b->isHovered) { PlaySound(soundHover); b->isHovered = true; + UpdateSpriteSourceRec(&b->sprite, &b->hover); } if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)){ - UpdateSpriteSourceRec(&b->sprite, &b->clicked); + if (!b->isClicked) { + PlaySound(soundClick); + b->isClicked = true; + UpdateSpriteSourceRec(&b->sprite, &b->clicked); + } } if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) { - PlaySound(soundClick); + b->isClicked = false; b->isHovered = false; UpdateSpriteSourceRec(&b->sprite, &b->notClicked); return true; } } else { UpdateSpriteSourceRec(&b->sprite, &b->notClicked); + b->isClicked = false; b->isHovered = false; } return false; diff --git a/src/engine/input.h b/src/engine/input.h index eafe709..ef27022 100644 --- a/src/engine/input.h +++ b/src/engine/input.h @@ -2,6 +2,7 @@ #define INPUT_H typedef struct { + Vector2 screenPosition; Vector2 worldPosition; float zoomSpeed; float minZoom; @@ -10,17 +11,27 @@ typedef struct { float wheelMove; bool leftButton; bool rightButton; + Texture2D cursorTexture; } Mouse; -Mouse CreateMouse(float zoomSpeed, float minZoom, float maxZoom){ +Mouse CreateMouse(float zoomSpeed, float minZoom, float maxZoom, Texture2D *texture){ + HideCursor(); return (Mouse){ .zoomSpeed = zoomSpeed, .minZoom = minZoom, - .maxZoom = maxZoom + .maxZoom = maxZoom, + .cursorTexture = *texture }; } +void UpdateMouseScreen(Mouse *mouse){ + mouse->screenPosition = GetMousePosition(); + +} + void UpdateMouse(Mouse *mouse, Camera2D *camera) { + + mouse->screenPosition = GetMousePosition(); mouse->worldPosition = GetScreenToWorld2D(GetMousePosition(), *camera); mouse->leftButton = IsMouseButtonDown(MOUSE_LEFT_BUTTON); mouse->rightButton = IsMouseButtonDown(MOUSE_RIGHT_BUTTON); diff --git a/src/engine/sprite.h b/src/engine/sprite.h index 5fa1682..8fff197 100644 --- a/src/engine/sprite.h +++ b/src/engine/sprite.h @@ -40,4 +40,15 @@ void RenderSprite(const Sprite *sprite){ ); } +void PrintSprite(const Sprite *sprite) { + printf("Sprite:\n"); + printf(" Sprite.texture: id = %d\n", sprite->texture.id); + printf(" Sprite.sourceRec: x = %f, y = %f, width = %f, height = %f\n", sprite->sourceRec.x, sprite->sourceRec.y, sprite->sourceRec.width, sprite->sourceRec.height); + printf(" Sprite.destRec: x = %f, y = %f, width = %f, height = %f\n", sprite->destRec.x, sprite->destRec.y, sprite->destRec.width, sprite->destRec.height); + printf(" Sprite.frameSize: x = %f, y = %f\n", sprite->frameSize.x, sprite->frameSize.y); + printf(" Sprite.origin: x = %f, y = %f\n", sprite->origin.x, sprite->origin.y); + printf(" Sprite.rotation: %f\n", sprite->rotation); + printf(" Sprite.color: r = %d, g = %d, b = %d, a = %d\n", sprite->color.r, sprite->color.g, sprite->color.b, sprite->color.a); +} + #endif // SPRITE_H diff --git a/src/game/background.h b/src/game/background.h new file mode 100644 index 0000000..dceb670 --- /dev/null +++ b/src/game/background.h @@ -0,0 +1,70 @@ +#ifndef BACKGROUND_H +#define BACKGROUND_H +#include "../engine/sprite.h" +#include "raylib.h" + +typedef struct { + Sprite sprite; + float scrolling; + float scale; + float scrollSpeed; + Vector2 pos; +} Background; + +void InitBackground(float scrollSpeed, Background *bg, Texture2D *texture, const TextureAsset *backgroundAsset){ + bg->scrolling = 0.0f; + bg->scrollSpeed = scrollSpeed; + bg->scale = 1.0f; + bg->sprite = (Sprite){ + .texture = *texture, + .sourceRec = (Rectangle){0.0f,0.0f,backgroundAsset->frameWidth, backgroundAsset->frameHeight}, + .destRec = (Rectangle){0.0f,0.0f,(float)GetScreenWidth(),(float)GetScreenHeight()}, + .origin = (Vector2){0.0f,0.0f}, + .rotation = 0.0f, + .color = WHITE + }; +} + +void UpdateBackground(Background *bg){ + bg->scrolling -= bg->scrollSpeed; + + if (bg->scrolling <= -bg->sprite.texture.width * bg->scale) { + bg->scrolling = 0; + } + + bg->pos = (Vector2){ bg->scrolling, 0.0f }; + UpdateSpriteDestRec(&bg->sprite, &bg->pos); +} + +void RenderBackground(Background *bg){ + + Sprite temp0 = bg->sprite; + float newX0 = bg->sprite.destRec.x + bg->sprite.texture.width * bg->scale * 2; + Vector2 newPos0 = {newX0, bg->sprite.destRec.y}; + UpdateSpriteDestRec(&temp0, &newPos0); + RenderSprite(&temp0); + + Sprite temp = bg->sprite; + float newX = bg->sprite.destRec.x + bg->sprite.texture.width * bg->scale; + Vector2 newPos = {newX, bg->sprite.destRec.y}; + UpdateSpriteDestRec(&temp, &newPos); + RenderSprite(&temp); + + RenderSprite(&bg->sprite); + + Sprite temp2 = bg->sprite; + float newX2 = bg->sprite.destRec.x - bg->sprite.texture.width * bg->scale; + Vector2 newPos2 = {newX2, bg->sprite.destRec.y}; + UpdateSpriteDestRec(&temp2, &newPos2); + RenderSprite(&temp2); + + Sprite temp3 = bg->sprite; + float newX3 = bg->sprite.destRec.x - bg->sprite.texture.width * bg->scale * 2; + Vector2 newPos3 = {newX3, bg->sprite.destRec.y}; + UpdateSpriteDestRec(&temp3, &newPos3); + RenderSprite(&temp3); + + +} + +#endif // BACKGROUND_H diff --git a/src/game/game.h b/src/game/game.h index eb21544..057f236 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -64,7 +64,9 @@ void InitGame(GameState* g, Display *display){ // I/O g->camera = CreateCamera(display->width, display->height, g->player.physics.position, 10.0f); - g->mouse = CreateMouse(0.10f, 5.0f, 10.0f); + + + g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &g->textures[CURSOR]); } @@ -97,6 +99,7 @@ void RenderGame(GameState* g){ BeginMode2D(g->camera); RenderComponents(g); EndMode2D(); + DrawTextureRec(g->mouse.cursorTexture, (Rectangle){ 0, 0, g->mouse.cursorTexture.width, -g->mouse.cursorTexture.height }, (Vector2){ g->mouse.screenPosition.x, GetScreenHeight() - g->mouse.screenPosition.y - g->mouse.cursorTexture.height}, WHITE); EndTextureMode(); BeginDrawing(); ClearBackground(BLACK); diff --git a/src/game/gameassets.h b/src/game/gameassets.h index ea10e23..09a695a 100644 --- a/src/game/gameassets.h +++ b/src/game/gameassets.h @@ -12,6 +12,7 @@ typedef enum { BEE, GRASS, HIVE, + CURSOR, TEX_COUNT } TextureID; @@ -22,7 +23,8 @@ const TextureAsset texAssets[TEX_COUNT] = { {"assets/flower.png", 16.0f, 16.0f, 45.0f}, {"assets/character_bee.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}, + {"assets/SproutLandsUI/Spritesheets/Mouse sprites/TriangleMouseicon1.png", 16.0f, 16.0f, 0.0f } }; //////////////////////////////////////////////////////////////////////////// diff --git a/src/game/menu.h b/src/game/menu.h index 1aa410c..fd13e3d 100644 --- a/src/game/menu.h +++ b/src/game/menu.h @@ -7,21 +7,31 @@ #include "../engine/gamegui.h" #include "menuassets.h" #include "colors.h" +#include "../engine/input.h" +#include "background.h" +#include "../engine/soundtrack.h" typedef struct { Assets assets; + Mouse mouse; Texture2D textures[MENU_TEX_COUNT]; Sound sounds[MENU_SOUND_COUNT]; + Soundtrack soundtracks[MENU_SOUNDTRACK_COUNT]; ImageElement board; ImageButton playButton; ImageButton quitButton; + int menuScale; + Background background; + Background midground; + Background foreground; } MenuState; void InitMenu(MenuState *m){ m->assets = (Assets){ .textureAssets = menuTextureAssets, - .soundAssets = menuSoundAssets + .soundAssets = menuSoundAssets, + .soundtrackAssets = menuSoundtrackAssets }; for (int i = 0; i < MENU_TEX_COUNT; i++){ @@ -32,14 +42,26 @@ void InitMenu(MenuState *m){ m->sounds[i] = LoadSound(m->assets.soundAssets[i].path); } - int menuScale = 4; + for (int i = 0; i < MENU_SOUNDTRACK_COUNT; i++){ + m->soundtracks[i] = LoadSoundtrack(m->assets.soundtrackAssets[i].path); + } + + InitBackground(0.1f, &m->background, &m->textures[MENU_CLOUD_BACKGROUND], &m->assets.textureAssets[MENU_CLOUD_BACKGROUND]); + InitBackground(0.2f, &m->midground, &m->textures[MENU_CLOUD_MIDGROUND], &m->assets.textureAssets[MENU_CLOUD_MIDGROUND]); + InitBackground(0.3f, &m->foreground, &m->textures[MENU_CLOUD_FOREGROUND], &m->assets.textureAssets[MENU_CLOUD_FOREGROUND]); + + m->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &m->textures[MENU_CURSOR_TEX]); + + m->menuScale = 4; int screenWidth = GetScreenWidth(); int screenHeight = GetScreenHeight(); Vector2 screenCenter = {screenWidth / 2, screenHeight / 2}; - int boardWidth = screenWidth / menuScale * 3.0f; - float boardScaleFactor = (float)boardWidth / m->assets.textureAssets[BOARD].frameWidth; - int boardHeight = (int)(m->assets.textureAssets[BOARD].frameHeight * boardScaleFactor); + + + int boardWidth = screenWidth / m->menuScale * 2.5f; + float boardScaleFactor = (float)boardWidth / m->assets.textureAssets[MENU_BOARD_TEX].frameWidth; + int boardHeight = (int)(m->assets.textureAssets[MENU_BOARD_TEX].frameHeight * boardScaleFactor); Vector2 boardSource = {128.0f,0.0f}; Rectangle boardDestRec = { @@ -49,17 +71,19 @@ void InitMenu(MenuState *m){ .height = boardHeight }; - m->board = CreateImageElement(&m->textures[BOARD], &m->assets.textureAssets[BOARD], &boardSource, &boardDestRec); + m->board = CreateImageElement(&m->textures[MENU_BOARD_TEX], &m->assets.textureAssets[MENU_BOARD_TEX], &boardSource, &boardDestRec); - int buttonWidth = screenWidth / menuScale; - float buttonScaleFactor = (float)buttonWidth / m->assets.textureAssets[BIG_BUTTONS].frameWidth; - int buttonHeight = (int)(m->assets.textureAssets[BIG_BUTTONS].frameHeight * buttonScaleFactor); + int buttonWidth = screenWidth / m->menuScale; + float buttonScaleFactor = (float)buttonWidth / m->assets.textureAssets[MENU_BIG_BUTTONS_TEX].frameWidth; + int buttonHeight = (int)(m->assets.textureAssets[MENU_BIG_BUTTONS_TEX].frameHeight * buttonScaleFactor); int buttonSpacing = buttonHeight; Vector2 playButtonNotPressed = { 0.0f, 96.0f}; Vector2 quitButtonNotPressed = { 0.0f, 0.0f}; - Vector2 playButtonPressed = { 96.0f, 96.0f}; - Vector2 quitButtonPressed = { 96.0f, 0.0f}; + Vector2 playButtonHover = { 96.0f, 96.0f}; + Vector2 quitButtonHover = { 96.0f, 0.0f}; + Vector2 playButtonPressed = { 192.0f, 96.0f}; + Vector2 quitButtonPressed = { 192.0f, 0.0f}; Rectangle playButtonDestRec = { .x = screenCenter.x - (buttonWidth / 2), @@ -75,13 +99,20 @@ void InitMenu(MenuState *m){ .height = buttonHeight }; - - m->playButton = CreateImageButton(NOT_CLICKED, &m->textures[BIG_BUTTONS], &m->assets.textureAssets[BIG_BUTTONS], &playButtonNotPressed, &playButtonPressed, &playButtonDestRec); - m->quitButton = CreateImageButton(NOT_CLICKED, &m->textures[BIG_BUTTONS], &m->assets.textureAssets[BIG_BUTTONS], &quitButtonNotPressed, &quitButtonPressed, &quitButtonDestRec); + m->playButton = CreateImageButton(NOT_CLICKED, &m->textures[MENU_BIG_BUTTONS_TEX], &m->assets.textureAssets[MENU_BIG_BUTTONS_TEX], &playButtonNotPressed, &playButtonPressed, &playButtonHover, &playButtonDestRec); + m->quitButton = CreateImageButton(NOT_CLICKED, &m->textures[MENU_BIG_BUTTONS_TEX], &m->assets.textureAssets[MENU_BIG_BUTTONS_TEX], &quitButtonNotPressed, &quitButtonPressed, &quitButtonHover, &quitButtonDestRec); } void UpdateMenu(MenuState *m, State *state){ + for (int i = 0; i < MENU_SOUNDTRACK_COUNT; i++){ UpdateSoundtrack(&m->soundtracks[i]); } + + UpdateBackground(&m->background); + UpdateBackground(&m->midground); + UpdateBackground(&m->foreground); + + UpdateMouseScreen(&m->mouse); + if (isImageButtonClicked(&m->playButton, m->sounds[HOVER_SOUND], m->sounds[CLICK_SOUND])){ state->gameStarted = true; state->currentScreen = GAMEPLAY; @@ -96,11 +127,22 @@ void UpdateMenu(MenuState *m, State *state){ void RenderMenu(MenuState *m, Font *font, const char* name){ BeginDrawing(); ClearBackground(WHITE); + RenderBackground(&m->background); + RenderBackground(&m->midground); + RenderBackground(&m->foreground); renderImageElement(&m->board); renderImageButton(&m->playButton); renderImageButton(&m->quitButton); int textWidth = MeasureText(name, font->baseSize); DrawTextEx(*font, name, (Vector2){ GetScreenWidth() / 2 - textWidth / 2, textWidth / 4}, (float)font->baseSize, 2, WHITE); + DrawTexturePro( + m->mouse.cursorTexture, + (Rectangle){ 0, 0, m->mouse.cursorTexture.width, m->mouse.cursorTexture.height}, + (Rectangle){m->mouse.screenPosition.x, m->mouse.screenPosition.y, m->mouse.cursorTexture.width, m->mouse.cursorTexture.height}, + (Vector2){0.0f, 0.0f}, + 0.0f, + WHITE + ); DrawFPS(10, 10); EndDrawing(); } @@ -108,6 +150,8 @@ void RenderMenu(MenuState *m, Font *font, const char* name){ void CleanupMenu(MenuState *m){ for (int i = 0; i < MENU_SOUND_COUNT; i++){ UnloadSound(m->sounds[i]); } for (int i = 0; i < MENU_TEX_COUNT; i++){ if (m->textures[i].id > 0) { UnloadTexture(m->textures[i]); } } + for (int i = 0; i < MENU_SOUNDTRACK_COUNT; i++){ UnloadMusicStream(m->soundtracks[i].music); } + } #endif // MENU_H diff --git a/src/game/menuassets.h b/src/game/menuassets.h index 9c31ca1..115a139 100644 --- a/src/game/menuassets.h +++ b/src/game/menuassets.h @@ -3,14 +3,31 @@ #include "../engine/asset.h" typedef enum { - BIG_BUTTONS, - BOARD, + MENU_CURSOR_TEX, + MENU_BIG_BUTTONS_TEX, + MENU_BOARD_TEX, + MENU_CLOUD_BACKGROUND, + MENU_CLOUD_MIDGROUND, + MENU_CLOUD_FOREGROUND, MENU_TEX_COUNT } MenuTextureID; const TextureAsset menuTextureAssets[MENU_TEX_COUNT] = { - {"assets/SproutLandsUI/Spritesheets/UIBigPlayButton.png", 96.0f, 32.0f, 180.0f}, + {"assets/SproutLandsUI/Spritesheets/Mouse sprites/TriangleMouseicon1.png", 16.0f, 16.0f, 0.0f }, + {"assets/SproutLandsUI/Spritesheets/UIBigPlayButtonHover.png", 96.0f, 32.0f, 180.0f}, {"assets/SproutLandsUI/Spritesheets/Settingmenu.png", 128.0f, 144.0f, 180.0f}, + {"assets/Clouds/Clouds1/1.png", 576.0f, 324.0f, 180.0f}, + {"assets/Clouds/Clouds1/2.png", 576.0f, 324.0f, 180.0f}, + {"assets/Clouds/Clouds1/4.png", 576.0f, 324.0f, 180.0f} +}; + +typedef enum { + MENU_MUSIC, + MENU_SOUNDTRACK_COUNT +} MenuSoundtrackID; + +const SoundtrackAsset menuSoundtrackAssets[MENU_SOUNDTRACK_COUNT] = { + {"assets/merrygoround.wav"} }; typedef enum {