Skip to content

Commit

Permalink
Updated Menu Design
Browse files Browse the repository at this point in the history
  • Loading branch information
BlockadeRunner committed Oct 28, 2021
1 parent 8553859 commit 5f67906
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
Binary file added resources/btn_LoadGame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added resources/menu_temp_background2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 48 additions & 9 deletions src/state_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
#include "state_menu.hpp"
#include "state_playing.hpp"

// MAKE SURE TO ADD PNGs TO DEBUG FOLDER BEFORE RUNNING!!!!

This comment has been minimized.

Copy link
@aaronamk

aaronamk Oct 28, 2021

Member

You should just add the png's you have been using to your branch, makes it easier



StateMenu::StateMenu(std::shared_ptr<StateController> sc) : State(sc) {

// (DONT ERASE!) This is example code being used for the rest of the menu design
////////////////////////////////////////////////////////////////////////////////////////////
/*
text.setString("Start playing big noob!");
text.setCharacterSize(100);
text.setPosition(sf::Vector2f(200, 200));
Expand All @@ -15,45 +22,77 @@ StateMenu::StateMenu(std::shared_ptr<StateController> sc) : State(sc) {
if (!font.loadFromFile("../fonts/arial.ttf"))
std::cout << "can't load font" << std::endl;
else text.setFont(font);


*/
////////////////////////////////////////////////////////////////////////////////////////////


}


void StateMenu::draw(sf::RenderWindow &window) const {
// (DONT ERASE!) This is example code being used for the rest of the menu design
////////////////////////////////////////////////////////////////////////////////////////////
/*
// window.draw button
sf::CircleShape circle(50);
circle.setFillColor(sf::Color::Red);
circle.setPosition(sf::Vector2f(100, 100));
window.draw(circle);
window.draw(text);
// window.draw(text);
sf::Texture texture;
*/


// Menu Background
sf::Texture menu_bkg_texture;
if (!menu_bkg_texture.loadFromFile("../resources/menu_temp_background2.png"))
{
std::cout << "can't load background sprite" << std::endl;
}
sf::Sprite menu_bkg;
menu_bkg.setTexture(menu_bkg_texture);
menu_bkg.setPosition(sf::Vector2f(0, 0));
window.draw(menu_bkg);

if (!texture.loadFromFile("btn_newGame.png"))
// New Game Button
sf::Texture new_game_button_texture;
if (!new_game_button_texture.loadFromFile("../resources/btn_newGame.png"))
{
std::cout << "can't load button sprite" << std::endl;
}

sf::Sprite new_game_button;
new_game_button.setTexture(texture);

new_game_button.setTexture(new_game_button_texture);
new_game_button.setPosition(sf::Vector2f(540, 300));
window.draw(new_game_button);

// Load Game Button
sf::Texture load_game_button_texture;
if (!load_game_button_texture.loadFromFile("../resources/btn_LoadGame.png"))
{
std::cout << "can't load button sprite" << std::endl;
}
sf::Sprite load_game_button;
load_game_button.setTexture(load_game_button_texture);
load_game_button.setPosition(sf::Vector2f(540, 400));
window.draw(load_game_button);

}


void StateMenu::handle_event(const sf::Event &e) {
int mouse_x = sf::Mouse::getPosition(_state_controller->window()).x;
int mouse_y = sf::Mouse::getPosition(_state_controller->window()).y;

switch (e.type) {
// play button switches state playing
case sf::Event::MouseButtonPressed:
// TODO: temporary crap, later use a button actor check collision
// with the mouse pointer:
if (sf::Mouse::getPosition(_state_controller->window()).x < 150)
if (540 < mouse_x < 799)

This comment has been minimized.

Copy link
@aaronamk

aaronamk Oct 28, 2021

Member

This sort of manual hard-coded stuff can be avoided by creating a button class that holds a position and size, and a way to check if a position vector (in this case, the mouse position vector) is inside of it. This would look something like:

if (play_button.collides(glob::convert_vect(sf::Mouse::getPosition(_state_controller->window()))) {
	...
}

Exact implementation of this depends on the way we want to work collisions, see #8.

_state_controller->states().push(
std::make_shared<StatePlaying>(_state_controller));
break;
Expand Down

0 comments on commit 5f67906

Please sign in to comment.