2018-01-15 13:19:51 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
#include <SDL2/SDL_image.h>
|
2018-01-18 15:19:04 +01:00
|
|
|
#include "gamestate.h"
|
2018-01-18 15:45:33 +01:00
|
|
|
#include "main.h"
|
2018-01-18 15:19:04 +01:00
|
|
|
|
2018-01-15 13:19:51 +01:00
|
|
|
|
2018-01-18 15:45:33 +01:00
|
|
|
SDL_Texture * TITLE_Texture;
|
|
|
|
SDL_Texture * PLAYBUTTON_Texture;
|
|
|
|
SDL_Texture * SKINSBUTTON_Texture;
|
|
|
|
SDL_Texture * LEVELBUTTON_Texture;
|
|
|
|
SDL_Texture * SETTINGSBUTTON_Texture;
|
|
|
|
SDL_Texture * HIGHSCORESBUTTON_Texture;
|
|
|
|
SDL_Texture * QUITBUTTON_Texture;
|
2018-01-15 14:08:09 +01:00
|
|
|
|
|
|
|
SDL_Rect TITLE_Rect;
|
|
|
|
SDL_Rect PLAYBUTTON_Rect;
|
2018-01-18 11:44:54 +01:00
|
|
|
SDL_Rect SETTINGSBUTTON_Rect;
|
|
|
|
SDL_Rect LEVELBUTTON_Rect;
|
|
|
|
SDL_Rect SKINSBUTTON_Rect;
|
|
|
|
SDL_Rect HIGHSCORESBUTTON_Rect;
|
|
|
|
SDL_Rect QUITBUTTON_Rect;
|
2018-01-15 13:19:51 +01:00
|
|
|
|
2018-01-18 15:45:33 +01:00
|
|
|
int clickInRect(SDL_MouseButtonEvent b, SDL_Rect * area_rect) {
|
2018-01-18 13:18:48 +01:00
|
|
|
return (((b.x) >= (area_rect->x)) && ((b.x) <= ((area_rect->x) + (area_rect->w))) && ((b.y) >= (area_rect->y)) && ((b.y) <= ((area_rect->y) + (area_rect->h))));
|
|
|
|
}
|
|
|
|
|
2018-01-18 15:45:33 +01:00
|
|
|
void Load_Textures(SDL_Renderer * renderer) {
|
2018-01-15 13:55:57 +01:00
|
|
|
TITLE_Texture = IMG_LoadTexture(renderer, "assets/images/breaking_button.png");
|
2018-01-18 15:45:33 +01:00
|
|
|
TITLE_Rect = (SDL_Rect) {.x = 685, .y = 50, .w = 550, .h = 250 };
|
2018-01-15 13:19:51 +01:00
|
|
|
|
2018-01-15 14:08:09 +01:00
|
|
|
PLAYBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/play_button.png");
|
2018-01-18 15:45:33 +01:00
|
|
|
PLAYBUTTON_Rect = (SDL_Rect) {.x = 497, .y = 400, .w = 313, .h = 178 };
|
2018-01-18 11:44:54 +01:00
|
|
|
|
|
|
|
SKINSBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/skins_button.png");
|
2018-01-18 15:45:33 +01:00
|
|
|
SKINSBUTTON_Rect = (SDL_Rect) {.x = 1110, .y = 400, .w = 313, .h = 178 };
|
2018-01-18 11:44:54 +01:00
|
|
|
|
|
|
|
LEVELBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/level_button.png");
|
2018-01-18 15:45:33 +01:00
|
|
|
LEVELBUTTON_Rect = (SDL_Rect) {.x = 497, .y = 700, .w = 313, .h = 178 };
|
2018-01-18 11:44:54 +01:00
|
|
|
|
|
|
|
SETTINGSBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/settings_button.png");
|
2018-01-18 15:45:33 +01:00
|
|
|
SETTINGSBUTTON_Rect = (SDL_Rect) {.x = 1110, .y = 700, .w = 313, .h = 178 };
|
2018-01-18 11:44:54 +01:00
|
|
|
|
|
|
|
HIGHSCORESBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/highscores_button.png");
|
2018-01-18 15:45:33 +01:00
|
|
|
HIGHSCORESBUTTON_Rect = (SDL_Rect) {.x = 1557, .y = 120, .w = 313, .h = 178 };
|
2018-01-18 11:44:54 +01:00
|
|
|
|
|
|
|
QUITBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/quit_button.png");
|
2018-01-18 15:45:33 +01:00
|
|
|
QUITBUTTON_Rect = (SDL_Rect) {.x = 50, .y = 896, .w = 235, .h = 134 };
|
|
|
|
} /* Load_Textures */
|
2018-01-15 13:19:51 +01:00
|
|
|
|
2018-01-18 15:45:33 +01:00
|
|
|
void Startmenu_Draw(SDL_Renderer * renderer) {
|
2018-01-15 14:08:09 +01:00
|
|
|
SDL_RenderCopy(renderer, TITLE_Texture, NULL, &TITLE_Rect);
|
|
|
|
SDL_RenderCopy(renderer, PLAYBUTTON_Texture, NULL, &PLAYBUTTON_Rect);
|
2018-01-18 11:44:54 +01:00
|
|
|
SDL_RenderCopy(renderer, SKINSBUTTON_Texture, NULL, &SKINSBUTTON_Rect);
|
|
|
|
SDL_RenderCopy(renderer, LEVELBUTTON_Texture, NULL, &LEVELBUTTON_Rect);
|
|
|
|
SDL_RenderCopy(renderer, SETTINGSBUTTON_Texture, NULL, &SETTINGSBUTTON_Rect);
|
|
|
|
SDL_RenderCopy(renderer, HIGHSCORESBUTTON_Texture, NULL, &HIGHSCORESBUTTON_Rect);
|
|
|
|
SDL_RenderCopy(renderer, QUITBUTTON_Texture, NULL, &QUITBUTTON_Rect);
|
2018-01-15 13:19:51 +01:00
|
|
|
}
|
2018-01-18 13:18:48 +01:00
|
|
|
|
2018-01-18 16:13:54 +01:00
|
|
|
void button_clicked(SDL_MouseButtonEvent b, GameState gameState) {
|
|
|
|
if (gameState == MainMenu) {
|
|
|
|
if (clickInRect(b, &PLAYBUTTON_Rect) == 1) {
|
|
|
|
GAME_ChangeState(Game);
|
|
|
|
} else if (clickInRect(b, &SKINSBUTTON_Rect) == 1) {
|
|
|
|
GAME_ChangeState(SkinSelect);
|
|
|
|
} else if (clickInRect(b, &LEVELBUTTON_Rect) == 1) {
|
|
|
|
GAME_ChangeState(LevelSelect);
|
|
|
|
} else if (clickInRect(b, &SETTINGSBUTTON_Rect) == 1) {
|
|
|
|
GAME_ChangeState(Settings);
|
|
|
|
} else if (clickInRect(b, &HIGHSCORESBUTTON_Rect) == 1) {
|
|
|
|
GAME_ChangeState(Highscores);
|
|
|
|
} else if (clickInRect(b, &QUITBUTTON_Rect) == 1) {
|
|
|
|
GAME_Escape();
|
|
|
|
}
|
2018-01-18 15:45:33 +01:00
|
|
|
}
|
2018-01-18 13:18:48 +01:00
|
|
|
}
|