Skip to content

Commit

Permalink
begin work on game select screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Hopson97 committed Jun 5, 2018
1 parent a086bd0 commit 3b6188e
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 63 deletions.
6 changes: 4 additions & 2 deletions HopsonArcade.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="Source\Arcade\Game.cpp" />
<ClCompile Include="Source\Arcade\GameSelection\GameSelect.cpp" />
<ClCompile Include="Source\Arcade\Main.cpp" />
<ClCompile Include="Source\Arcade\StateGameSelect.cpp" />
<ClCompile Include="Source\Arcade\GameSelection\StateGameSelect.cpp" />
<ClCompile Include="Source\Framework\GUI\Button.cpp" />
<ClCompile Include="Source\Framework\GUI\StackMenu.cpp" />
<ClCompile Include="Source\Framework\GUI\Textbox.cpp" />
Expand Down Expand Up @@ -168,7 +169,8 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="Source\Arcade\Game.h" />
<ClInclude Include="Source\Arcade\StateGameSelect.h" />
<ClInclude Include="Source\Arcade\GameSelection\GameSelect.h" />
<ClInclude Include="Source\Arcade\GameSelection\StateGameSelect.h" />
<ClInclude Include="Source\Framework\GUI\Button.h" />
<ClInclude Include="Source\Framework\GUI\StackMenu.h" />
<ClInclude Include="Source\Framework\GUI\Textbox.h" />
Expand Down
6 changes: 3 additions & 3 deletions Source/Arcade/Game.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "Game.h"

#include "../SpaceInvaders/States/StateMainMenu.h"
#include "GameSelection/StateGameSelect.h"
#include "../SpaceInvaders/DisplayInfo.h"

#include <iostream>

Game::Game()
: m_window ({ 1600, 900}, "Hopson Arcade")
: m_window ({ 1280, 720}, "Hopson Arcade")
{
m_window.setPosition({m_window.getPosition().x, 0});
m_window.setFramerateLimit(60);
pushState<SpaceInvaders::StateMainMenu>(*this);
pushState<StateGameSelect>(*this);

sf::Image icon;
icon.loadFromFile("res/txrs/icon.png");
Expand Down
44 changes: 44 additions & 0 deletions Source/Arcade/GameSelection/GameSelect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "GameSelect.h"

#include "../../Framework/ResourceManager/ResourceHolder.h"

GameSelect::GameSelect(const std::string& name)
{
m_container.setSize({ WIDTH, HEIGHT });
m_thumbnail.setSize({ 256, 256 });

m_container.setOutlineThickness(2);
m_container.setOutlineColor({ 100, 100, 100 });
m_container.setFillColor({ 200, 200, 200 });

m_thumbnail.setOutlineThickness(1);
m_thumbnail.setOutlineColor({ 100, 100, 100 });
m_thumbnail.setTexture(&ResourceHolder::get().textures.get("thumbnails/" + name));
}

bool GameSelect::isClicked(const sf::Vector2i& mousePositon)
{
return m_container
.getGlobalBounds()
.contains((float)mousePositon.x, (float)mousePositon.y);
}

void GameSelect::setPosition(const sf::Vector2f position)
{
m_container.setPosition(position);
m_thumbnail.setPosition(position);
}

void GameSelect::draw(sf::RenderTarget & renderer)
{
renderer.draw(m_container);
renderer.draw(m_thumbnail);
}

SpaceInvadersSelect::SpaceInvadersSelect(const std::string & name)
: GameSelect(name) { }

std::unique_ptr<StateBase> SpaceInvadersSelect::getInitState()
{
return std::unique_ptr<StateBase>();
}
32 changes: 32 additions & 0 deletions Source/Arcade/GameSelection/GameSelect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include <string>
#include <memory>
#include <SFML/Graphics.hpp>

#include "../../Framework/States/StateBase.h"

class GameSelect
{
public:
constexpr static float WIDTH = 512;
constexpr static float HEIGHT = 256;

GameSelect(const std::string& name);
bool isClicked(const sf::Vector2i& mousePositon);

void setPosition(const sf::Vector2f position);
void draw(sf::RenderTarget& renderer);

virtual std::unique_ptr<StateBase> getInitState() = 0;

private:
sf::RectangleShape m_container;
sf::RectangleShape m_thumbnail;
};

struct SpaceInvadersSelect : public GameSelect
{
SpaceInvadersSelect(const std::string& name);
std::unique_ptr<StateBase> getInitState() override;
};
39 changes: 39 additions & 0 deletions Source/Arcade/GameSelection/StateGameSelect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "StateGameSelect.h"

#include "../Game.h"

StateGameSelect::StateGameSelect(Game& game)
: StateBase(game, "Game Select", 1280, 720)
{
registerGame(std::make_unique<SpaceInvadersSelect>("SpaceInvaders"));
registerGame(std::make_unique<SpaceInvadersSelect>("SpaceInvaders"));
registerGame(std::make_unique<SpaceInvadersSelect>("SpaceInvaders"));
registerGame(std::make_unique<SpaceInvadersSelect>("SpaceInvaders"));
registerGame(std::make_unique<SpaceInvadersSelect>("SpaceInvaders"));
}

void StateGameSelect::onOpen()
{
m_pGame->resizeWindow(1280, 720);
}


void StateGameSelect::handleEvent(sf::Event e)
{
}

void StateGameSelect::render(sf::RenderTarget& target)
{
for (auto& g : m_gameSelects) {
g->draw(target);
}
}

void StateGameSelect::registerGame(std::unique_ptr<GameSelect> gameSelect)
{
float x = 123.0f + (m_gameSelects.size() % 2 == 0 ? 0 : GameSelect::WIDTH);
float y = int(m_gameSelects.size() / 2) * (GameSelect::HEIGHT);

gameSelect->setPosition({ x, y });
m_gameSelects.push_back(std::move(gameSelect));
}
23 changes: 23 additions & 0 deletions Source/Arcade/GameSelection/StateGameSelect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <vector>

#include "GameSelect.h"

class Game;

class StateGameSelect : public StateBase
{
public:
StateGameSelect(Game& game);

void onOpen() override;

void handleEvent(sf::Event e) override;
void render(sf::RenderTarget& target) override;

private:
void registerGame(std::unique_ptr<GameSelect> gameSelect);

std::vector<std::unique_ptr<GameSelect>> m_gameSelects;
};
22 changes: 0 additions & 22 deletions Source/Arcade/StateGameSelect.cpp

This file was deleted.

35 changes: 0 additions & 35 deletions Source/Arcade/StateGameSelect.h

This file was deleted.

2 changes: 1 addition & 1 deletion Source/SpaceInvaders/States/StateHighscores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace SpaceInvaders
{
namespace
{
const auto scoresPath = "res/si/scores.txt";
const auto scoresPath = "res/SpaceInvaders/scores.txt";
}

StateHighscores::StateHighscores(Game & game, int score)
Expand Down
6 changes: 6 additions & 0 deletions res/SpaceInvaders/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name
Space Invaders

desc
Based on the 1978 arcade game.
Shoot down aliens trying to invade the Earth!
File renamed without changes.
File renamed without changes

0 comments on commit 3b6188e

Please sign in to comment.