font and sound
This commit is contained in:
@@ -16,10 +16,15 @@ typedef struct {
|
||||
const char* path;
|
||||
} SoundtrackAsset;
|
||||
|
||||
typedef struct {
|
||||
const char* path;
|
||||
} SoundAsset;
|
||||
|
||||
typedef struct {
|
||||
const TextureAsset *textureAssets;
|
||||
const ShaderAsset *shaderAssets;
|
||||
const SoundtrackAsset *soundtrackAssets;
|
||||
const SoundAsset *soundAssets;
|
||||
} Assets;
|
||||
|
||||
#endif // ASSET_H
|
||||
|
||||
+11
-1
@@ -14,6 +14,7 @@ typedef struct
|
||||
Sprite sprite;
|
||||
Vector2 notClicked;
|
||||
Vector2 clicked;
|
||||
bool isHovered;
|
||||
} ImageButton;
|
||||
|
||||
typedef struct
|
||||
@@ -72,18 +73,27 @@ void PrintImageButton(const ImageButton btn) {
|
||||
printf(" clicked: x = %f, y = %f\n", btn.clicked.x, btn.clicked.y);
|
||||
}
|
||||
|
||||
int isImageButtonClicked(ImageButton *b){
|
||||
int isImageButtonClicked(ImageButton *b, Sound soundHover, Sound soundClick){
|
||||
if (CheckCollisionPointRec(GetMousePosition(), b->sprite.destRec)) {
|
||||
|
||||
if (!b->isHovered) {
|
||||
PlaySound(soundHover);
|
||||
b->isHovered = true;
|
||||
}
|
||||
|
||||
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)){
|
||||
UpdateSpriteSourceRec(&b->sprite, &b->clicked);
|
||||
}
|
||||
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
PlaySound(soundClick);
|
||||
b->isHovered = false;
|
||||
UpdateSpriteSourceRec(&b->sprite, &b->notClicked);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
UpdateSpriteSourceRec(&b->sprite, &b->notClicked);
|
||||
b->isHovered = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
+13
-3
@@ -11,18 +11,27 @@
|
||||
typedef struct {
|
||||
Assets assets;
|
||||
Texture2D textures[MENU_TEX_COUNT];
|
||||
Sound sounds[MENU_SOUND_COUNT];
|
||||
ImageElement board;
|
||||
ImageButton playButton;
|
||||
ImageButton quitButton;
|
||||
} MenuState;
|
||||
|
||||
void InitMenu(MenuState *m){
|
||||
|
||||
m->assets = (Assets){
|
||||
.textureAssets = menuTextureAssets
|
||||
.textureAssets = menuTextureAssets,
|
||||
.soundAssets = menuSoundAssets
|
||||
};
|
||||
|
||||
for (int i = 0; i < MENU_TEX_COUNT; i++){
|
||||
m->textures[i] = LoadTexture(m->assets.textureAssets[i].path);
|
||||
}
|
||||
|
||||
for (int i = 0; i < MENU_SOUND_COUNT; i++){
|
||||
m->sounds[i] = LoadSound(m->assets.soundAssets[i].path);
|
||||
}
|
||||
|
||||
int menuScale = 4;
|
||||
int screenWidth = GetScreenWidth();
|
||||
int screenHeight = GetScreenHeight();
|
||||
@@ -73,12 +82,12 @@ void InitMenu(MenuState *m){
|
||||
|
||||
void UpdateMenu(MenuState *m, State *state){
|
||||
|
||||
if (isImageButtonClicked(&m->playButton)){
|
||||
if (isImageButtonClicked(&m->playButton, m->sounds[HOVER_SOUND], m->sounds[CLICK_SOUND])){
|
||||
state->gameStarted = true;
|
||||
state->currentScreen = GAMEPLAY;
|
||||
}
|
||||
|
||||
if (isImageButtonClicked(&m->quitButton) || (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE))) {
|
||||
if (isImageButtonClicked(&m->quitButton, m->sounds[HOVER_SOUND], m->sounds[CLICK_SOUND]) || (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE))) {
|
||||
state->running = false;
|
||||
}
|
||||
|
||||
@@ -97,6 +106,7 @@ 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]); } }
|
||||
}
|
||||
|
||||
|
||||
@@ -13,4 +13,15 @@ const TextureAsset menuTextureAssets[MENU_TEX_COUNT] = {
|
||||
{"assets/SproutLandsUI/Spritesheets/Settingmenu.png", 128.0f, 144.0f, 180.0f},
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
HOVER_SOUND,
|
||||
CLICK_SOUND,
|
||||
MENU_SOUND_COUNT
|
||||
} MenuSoundID;
|
||||
|
||||
const SoundAsset menuSoundAssets[MENU_SOUND_COUNT] = {
|
||||
{"assets/audio/WAV/Minimalist1.wav"},
|
||||
{"assets/audio/WAV/Abstract1.wav"}
|
||||
};
|
||||
|
||||
#endif // MENUASSETS_H
|
||||
|
||||
+1
-2
@@ -9,7 +9,6 @@
|
||||
#include "game/menu.h"
|
||||
#include "game/game.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
State state;
|
||||
Display display;
|
||||
@@ -31,7 +30,7 @@ int main(void)
|
||||
InitAudioDevice();
|
||||
|
||||
Application app;
|
||||
app.state.currentScreen = MENU;
|
||||
app.state.currentScreen = LOGO;
|
||||
app.state.running = true;
|
||||
app.state.gameStarted = false;
|
||||
app.display = display;
|
||||
|
||||
Reference in New Issue
Block a user