Compare commits
1 Commits
main
...
optimizing
| Author | SHA1 | Date | |
|---|---|---|---|
| 6da3cb66fa |
@@ -57,6 +57,33 @@ class AppMenu {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sf::Text createText(int fontSize = 2) const {
|
||||||
|
sf::Text newText(this->pressStartFont, "", this->settings->getWindowSizeMultiplier() * fontSize);
|
||||||
|
newText.setFillColor(sf::Color::Black);
|
||||||
|
newText.setOutlineColor(sf::Color::White);
|
||||||
|
newText.setOutlineThickness(0);
|
||||||
|
|
||||||
|
return newText;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTextPosition(sf::Text& text, float xPos, float yPos) const {
|
||||||
|
float sizeMultiplier = this->settings->getWindowSizeMultiplier();
|
||||||
|
|
||||||
|
text.setOrigin(sf::Vector2f({0, text.getLocalBounds().size.y / 2}));
|
||||||
|
text.setPosition(sf::Vector2f({sizeMultiplier * xPos, sizeMultiplier * yPos}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTitlePosition(sf::Text& text, float yPos) const {
|
||||||
|
float sizeMultiplier = this->settings->getWindowSizeMultiplier();
|
||||||
|
|
||||||
|
text.setOrigin({text.getLocalBounds().getCenter().x, text.getLocalBounds().size.y / 2});
|
||||||
|
text.setPosition(sf::Vector2f({sizeMultiplier * 40.f, sizeMultiplier * yPos}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTextOutline(sf::Text& text, bool hasOutline) const {
|
||||||
|
text.setOutlineThickness(hasOutline * (this->settings->getWindowSizeMultiplier() / 2));
|
||||||
|
}
|
||||||
|
|
||||||
void placeText(sf::Text& text, const std::optional<PlayerCursor>& playerCursor, const sf::String& string, float xPos, float yPos, const std::optional<sf::Vector2u>& cursorPos) const {
|
void placeText(sf::Text& text, const std::optional<PlayerCursor>& playerCursor, const sf::String& string, float xPos, float yPos, const std::optional<sf::Vector2u>& cursorPos) const {
|
||||||
float sizeMultiplier = this->settings->getWindowSizeMultiplier();
|
float sizeMultiplier = this->settings->getWindowSizeMultiplier();
|
||||||
|
|
||||||
|
|||||||
@@ -10,12 +10,13 @@
|
|||||||
|
|
||||||
InfoAppMenu::InfoAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
InfoAppMenu::InfoAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
||||||
AppMenu(menuStack, settings, renderWindow),
|
AppMenu(menuStack, settings, renderWindow),
|
||||||
playerCursor({4}),
|
playerCursor({INFO_SECTIONS_COUNT}),
|
||||||
sectionsName(
|
sectionsName(
|
||||||
"< ABOUT >",
|
"< ABOUT >",
|
||||||
|
"< PIECES TYPES >",
|
||||||
|
"< 0 DEGREES ROTATIONS >",
|
||||||
"< ROTATION SYSTEM >",
|
"< ROTATION SYSTEM >",
|
||||||
"< SCORING >",
|
"< SCORING >"
|
||||||
"< 0 DEGREES ROTATIONS >"
|
|
||||||
),
|
),
|
||||||
sectionsContent(
|
sectionsContent(
|
||||||
"This game is written in C++,\n"
|
"This game is written in C++,\n"
|
||||||
@@ -27,6 +28,25 @@ InfoAppMenu::InfoAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<S
|
|||||||
"to them in any ways.\n"
|
"to them in any ways.\n"
|
||||||
"Current version: beta.",
|
"Current version: beta.",
|
||||||
|
|
||||||
|
"There is multiple pieces type in\n"
|
||||||
|
"the selection screen. Use theses\n"
|
||||||
|
"categories for size of at least 7.\n"
|
||||||
|
"Convex, Holeless and Others are\n"
|
||||||
|
"all mutually exclusive.\n"
|
||||||
|
"Others have holes inside them, and\n"
|
||||||
|
"Convex are presumably easier to\n"
|
||||||
|
"play with than Holeless.",
|
||||||
|
|
||||||
|
"This games introduces 0 degrees\n"
|
||||||
|
"rotations, which work by simpling\n"
|
||||||
|
"moving the piece down and kicking\n"
|
||||||
|
"it as is, allowing for new kinds\n"
|
||||||
|
"of kicks.\n"
|
||||||
|
"As a leniency mechanic, when a\n"
|
||||||
|
"piece spawns it will automatically\n"
|
||||||
|
"try a 0 degrees rotations if it\n"
|
||||||
|
"spawned inside a wall.",
|
||||||
|
|
||||||
"This game uses its own\n"
|
"This game uses its own\n"
|
||||||
"Rotation Sytem, called AutoRS.\n"
|
"Rotation Sytem, called AutoRS.\n"
|
||||||
"The rotation center is always the\n"
|
"The rotation center is always the\n"
|
||||||
@@ -46,25 +66,48 @@ InfoAppMenu::InfoAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<S
|
|||||||
"and doubles the score gained.\n"
|
"and doubles the score gained.\n"
|
||||||
"A spin is detected when the piece is\n"
|
"A spin is detected when the piece is\n"
|
||||||
"locked in place, a mini-spin simply\n"
|
"locked in place, a mini-spin simply\n"
|
||||||
"when the last move was a kick.",
|
"when the last move was a kick."
|
||||||
|
),
|
||||||
|
sectionNameText(this->createText()),
|
||||||
|
sectionContentText(this->createText()),
|
||||||
|
renderTexture(this->renderWindow->getSize()),
|
||||||
|
sprite(this->renderTexture.getTexture()) {
|
||||||
|
|
||||||
"This games introduces 0 degrees\n"
|
this->setTextOutline(this->sectionNameText, true);
|
||||||
"rotations, which work by simpling\n"
|
|
||||||
"moving the piece down and kicking\n"
|
this->sectionContentText.setLineSpacing((float) this->settings->getWindowSizeMultiplier() / 8);
|
||||||
"it as is, allowing for new kinds\n"
|
|
||||||
"of kicks.\n"
|
|
||||||
"As a leniency mechanic, when a\n"
|
|
||||||
"piece spawns it will automatically\n"
|
|
||||||
"try a 0 degrees rotations if it\n"
|
|
||||||
"spawned inside a wall."
|
|
||||||
) {
|
|
||||||
|
|
||||||
|
this->sectionNameText.setString(this->sectionsName[this->playerCursor.getPosition().x]);
|
||||||
|
this->setTitlePosition(this->sectionNameText, 10.f);
|
||||||
|
|
||||||
|
this->sectionContentText.setString(this->sectionsContent[this->playerCursor.getPosition().x]);
|
||||||
|
this->setTextPosition(this->sectionContentText, 5.f, 30.f);
|
||||||
|
|
||||||
|
this->renderTexture.clear(sf::Color(200, 200, 200));
|
||||||
|
this->renderTexture.draw(this->sectionNameText);
|
||||||
|
this->renderTexture.draw(this->sectionContentText);
|
||||||
|
this->renderTexture.display();
|
||||||
|
this->sprite.setTexture(this->renderTexture.getTexture());
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfoAppMenu::computeFrame() {
|
void InfoAppMenu::computeFrame() {
|
||||||
this->updateMetaBinds();
|
this->updateMetaBinds();
|
||||||
this->playerCursor.updatePosition();
|
this->playerCursor.updatePosition();
|
||||||
|
|
||||||
|
if (this->playerCursor.movedLeft() || this->playerCursor.movedRight()) {
|
||||||
|
this->sectionNameText.setString(this->sectionsName[this->playerCursor.getPosition().x]);
|
||||||
|
this->setTitlePosition(this->sectionNameText, 10.f);
|
||||||
|
|
||||||
|
this->sectionContentText.setString(this->sectionsContent[this->playerCursor.getPosition().x]);
|
||||||
|
this->setTextPosition(this->sectionContentText, 5.f, 30.f);
|
||||||
|
|
||||||
|
this->renderTexture.clear(sf::Color(200, 200, 200));
|
||||||
|
this->renderTexture.draw(this->sectionNameText);
|
||||||
|
this->renderTexture.draw(this->sectionContentText);
|
||||||
|
this->renderTexture.display();
|
||||||
|
this->sprite.setTexture(this->renderTexture.getTexture());
|
||||||
|
}
|
||||||
|
|
||||||
if (this->escReleased) {
|
if (this->escReleased) {
|
||||||
this->menuStack->pop();
|
this->menuStack->pop();
|
||||||
}
|
}
|
||||||
@@ -73,15 +116,7 @@ void InfoAppMenu::computeFrame() {
|
|||||||
void InfoAppMenu::drawFrame() const {
|
void InfoAppMenu::drawFrame() const {
|
||||||
this->renderWindow->clear(sf::Color(200, 200, 200));
|
this->renderWindow->clear(sf::Color(200, 200, 200));
|
||||||
|
|
||||||
sf::Text text(this->pressStartFont, "", this->settings->getWindowSizeMultiplier() * 2);
|
this->renderWindow->draw(sprite);
|
||||||
text.setFillColor(sf::Color(0, 0, 0));
|
|
||||||
text.setOutlineColor(sf::Color(255, 255, 255));
|
|
||||||
|
|
||||||
this->placeTitle(text, this->playerCursor, this->sectionsName[this->playerCursor.getPosition().x], 10.f, this->playerCursor.getPosition());
|
|
||||||
|
|
||||||
text.setLineSpacing((float) this->settings->getWindowSizeMultiplier() / 8);
|
|
||||||
text.setOutlineThickness(0);
|
|
||||||
this->placeText(text, {}, this->sectionsContent[this->playerCursor.getPosition().x], 5.f, 30.f, {});
|
|
||||||
|
|
||||||
this->renderWindow->display();
|
this->renderWindow->display();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,18 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
static const int INFO_SECTIONS_COUNT = 5;
|
||||||
|
|
||||||
|
|
||||||
class InfoAppMenu : public AppMenu {
|
class InfoAppMenu : public AppMenu {
|
||||||
private:
|
private:
|
||||||
PlayerCursor playerCursor;
|
PlayerCursor playerCursor;
|
||||||
sf::String sectionsName[4];
|
sf::String sectionsName[INFO_SECTIONS_COUNT];
|
||||||
sf::String sectionsContent[4];
|
sf::String sectionsContent[INFO_SECTIONS_COUNT];
|
||||||
|
sf::Text sectionNameText;
|
||||||
|
sf::Text sectionContentText;
|
||||||
|
sf::RenderTexture renderTexture;
|
||||||
|
sf::Sprite sprite;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InfoAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
|
InfoAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
|
||||||
|
|||||||
@@ -42,6 +42,13 @@ void PlayerCursor::updatePosition() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PlayerCursor::moved() const {
|
||||||
|
return (this->movedLeft()
|
||||||
|
|| this->movedRight()
|
||||||
|
|| this->movedUp()
|
||||||
|
|| this->movedDown());
|
||||||
|
}
|
||||||
|
|
||||||
bool PlayerCursor::movedLeft() const {
|
bool PlayerCursor::movedLeft() const {
|
||||||
return this->shouldMove(this->leftDAS);
|
return this->shouldMove(this->leftDAS);
|
||||||
}
|
}
|
||||||
@@ -115,7 +122,7 @@ const sf::Vector2u& PlayerCursor::getPosition() const {
|
|||||||
bool PlayerCursor::shouldMove(int DAS) const {
|
bool PlayerCursor::shouldMove(int DAS) const {
|
||||||
return (DAS == 1
|
return (DAS == 1
|
||||||
|| (DAS > MENU_DAS && (DAS % 5) == 0)
|
|| (DAS > MENU_DAS && (DAS % 5) == 0)
|
||||||
|| (DAS > (FRAMES_PER_SECOND * 2)));
|
|| (DAS > (MENU_DAS * 4)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerCursor::moveLeft() {
|
void PlayerCursor::moveLeft() {
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ class PlayerCursor {
|
|||||||
|
|
||||||
void updatePosition();
|
void updatePosition();
|
||||||
|
|
||||||
|
bool moved() const;
|
||||||
|
|
||||||
bool movedLeft() const;
|
bool movedLeft() const;
|
||||||
|
|
||||||
bool movedRight() const;
|
bool movedRight() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user