Skip to content

Commit

Permalink
Merge pull request #300 from Laguna1989/feature/AdjustScreenSizeAndZoom
Browse files Browse the repository at this point in the history
Adjust Default Window Size and Zoom
  • Loading branch information
Laguna1989 authored Nov 1, 2023
2 parents 7dc7490 + d711667 commit 7b61cd9
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 30 deletions.
20 changes: 15 additions & 5 deletions impl/gamelib/game_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,33 @@ class GP {
GP() = delete;

static std::string GameName() { return "MyAwesomeGame"; }

static std::string AuthorName() { return "TODO"; }

static std::string JamName() { return "TODO"; }

static std::string JamDate() { return "TODO"; }

static std::string ExplanationText()
{
return "Win the game\n[W,A,S,D] to move \n[Space] to jump\n[M/U] to mute/unmute audio";
}

static jt::Vector2f GetWindowSize() { return jt::Vector2f { 1200, 800 }; }
static float GetZoom() { return 2.0f; }
static jt::Vector2f GetWindowSize() { return jt::Vector2f { 1280, 960 }; }

static float GetZoom() { return 4.0f; }

static jt::Vector2f GetScreenSize() { return GetWindowSize() * (1.0f / GetZoom()); }

static jt::Color PaletteBackground() { return GP::getPalette().getColor(5); }
static jt::Color PaletteBackground() { return GP::getPalette().getColor(4); }

static jt::Color PaletteFontFront() { return GP::getPalette().getColor(0); }

static jt::Color PalleteFrontHighlight() { return GP::getPalette().getColor(1); }
static jt::Color PaletteFontShadow() { return GP::getPalette().getColor(6); }
static jt::Color PaletteFontCredits() { return GP::getPalette().getColor(2); }

static jt::Color PaletteFontShadow() { return GP::getPalette().getColor(2); }

static jt::Color PaletteFontCredits() { return GP::getPalette().getColor(1); }

static jt::Palette getPalette();

Expand Down
7 changes: 4 additions & 3 deletions impl/gamelib/hud/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
#include <color/color.hpp>
#include <drawable_helpers.hpp>
#include <game_interface.hpp>
#include <game_properties.hpp>
#include <hud/score_display.hpp>

std::shared_ptr<ObserverInterface<int>> Hud::getObserverScoreP1() const { return m_scoreP1Display; }

std::shared_ptr<ObserverInterface<int>> Hud::getObserverScoreP2() const { return m_scoreP2Display; }

void Hud::doCreate()
{

m_scoreP1Text = std::make_shared<jt::Text>();
m_scoreP1Text = jt::dh::createText(renderTarget(), "", 16, jt::Color { 248, 249, 254 });
m_scoreP1Text->setTextAlign(jt::Text::TextAlign::LEFT);
Expand All @@ -18,8 +19,8 @@ void Hud::doCreate()
m_scoreP1Display = std::make_shared<ScoreDisplay>(m_scoreP1Text, "P1 Score: ");

m_scoreP2Text = jt::dh::createText(renderTarget(), "", 16, jt::Color { 248, 249, 254 });
m_scoreP2Text->setTextAlign(jt::Text::TextAlign::LEFT);
m_scoreP2Text->setPosition({ 600 / 2 - 10, 4 });
m_scoreP2Text->setTextAlign(jt::Text::TextAlign::RIGHT);
m_scoreP2Text->setPosition({ GP::GetScreenSize().x - 10, 4 });

m_scoreP2Display = std::make_shared<ScoreDisplay>(m_scoreP2Text, "P2 Score: ");
}
Expand Down
1 change: 1 addition & 0 deletions impl/gamelib/hud/score_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ void ScoreDisplay::notify(int value)
{
if (value >= 0) {
m_scoreText->setText(m_textPrefix + std::to_string(value) + m_textPostfix);
m_scoreText->update(0.0f);
}
}
5 changes: 3 additions & 2 deletions impl/gamelib/state_intro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
void StateIntro::onCreate()
{
m_sprite = std::make_shared<jt::Sprite>("assets/runvs_logo.png", textureManager());
// m_sprite->setScale(jt::Vector2f { 0.5f, 0.5f });
m_sprite->setOffset(jt::OffsetMode::CENTER);
m_sprite->setOrigin(jt::OriginMode::CENTER);
// m_sprite->setOffset(jt::OffsetMode::CENTER);
m_sprite->setScale(jt::Vector2f { 0.5f, 0.5f });

m_jingle = getGame()->audio().addTemporarySound("assets/intro.mp3");
}
Expand Down
34 changes: 15 additions & 19 deletions impl/gamelib/state_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@
#include <log/license_info.hpp>
#include <math_helper.hpp>
#include <screeneffects/vignette.hpp>
#include <shape.hpp>
#include <sprite.hpp>
#include <state_game.hpp>
#include <state_manager/state_manager_transition_fade_to_black.hpp>
#include <text.hpp>
#include <tweens/tween_alpha.hpp>
#include <tweens/tween_color.hpp>
#include <tweens/tween_position.hpp>
#include <tweens/tween_scale.hpp>
#include <algorithm>
#include <iostream>

void StateMenu::onCreate()
{
Expand Down Expand Up @@ -59,26 +54,27 @@ void StateMenu::createMenuText()
createTextExplanation();
createTextCredits();
}

void StateMenu::createTextExplanation()
{
m_textExplanation
= jt::dh::createText(renderTarget(), GP::ExplanationText(), 16u, GP::PaletteFontFront());
auto const half_width = GP::GetScreenSize().x / 2.0f;
m_textExplanation->setPosition({ half_width, 180 });
m_textExplanation->setPosition({ half_width, 100 });
m_textExplanation->setShadow(GP::PaletteFontShadow(), jt::Vector2f { 2, 2 });
}

void StateMenu::createTextCredits()
{
m_textCredits = jt::dh::createText(renderTarget(),
"Created by " + GP::AuthorName() + " for " + GP::JamName() + "\n" + GP::JamDate()
+ "\n\nF9 for License Information",
16u, GP::PaletteFontCredits());
+ "\nF9 for License Information",
14u, GP::PaletteFontCredits());
m_textCredits->setTextAlign(jt::Text::TextAlign::LEFT);
m_textCredits->setPosition({ 10, GP::GetScreenSize().y - 70 });
m_textCredits->setShadow(GP::PaletteFontShadow(), jt::Vector2f { 1, 1 });

m_textVersion = jt::dh::createText(renderTarget(), "", 16u, GP::PaletteFontCredits());
m_textVersion = jt::dh::createText(renderTarget(), "", 14u, GP::PaletteFontCredits());
if (jt::BuildInfo::gitTagName() != "") {
m_textVersion->setText(jt::BuildInfo::gitTagName());
} else {
Expand All @@ -94,17 +90,17 @@ void StateMenu::createTextStart()
{
auto const half_width = GP::GetScreenSize().x / 2.0f;
m_textStart = jt::dh::createText(
renderTarget(), "Press Space to start the game", 24u, GP::PaletteFontFront());
m_textStart->setPosition({ half_width, 150 });
m_textStart->setShadow(GP::PaletteFontShadow(), jt::Vector2f { 3, 3 });
renderTarget(), "Press Space to start the game", 16u, GP::PaletteFontFront());
m_textStart->setPosition({ half_width, 70 });
m_textStart->setShadow(GP::PaletteFontShadow(), jt::Vector2f { 2, 2 });
}

void StateMenu::createTextTitle()
{
float half_width = GP::GetScreenSize().x / 2;
m_textTitle = jt::dh::createText(renderTarget(), GP::GameName(), 48u, GP::PaletteFontFront());
m_textTitle->setPosition({ half_width, 20 });
m_textTitle->setShadow(GP::PaletteFontShadow(), jt::Vector2f { 4, 4 });
m_textTitle = jt::dh::createText(renderTarget(), GP::GameName(), 32u, GP::PaletteFontFront());
m_textTitle->setPosition({ half_width, 10 });
m_textTitle->setShadow(GP::PaletteFontShadow(), jt::Vector2f { 3, 3 });
}

void StateMenu::createTweens()
Expand Down Expand Up @@ -140,10 +136,10 @@ void StateMenu::createInstructionTweenColor2()

void StateMenu::createTweenExplanation()
{
auto s2 = m_textStart->getPosition() + jt::Vector2f { -1000, 0 };
auto e2 = m_textStart->getPosition();
auto const start = m_textStart->getPosition() + jt::Vector2f { -1000, 0 };
auto const end = m_textStart->getPosition();

auto tween = jt::TweenPosition::create(m_textStart, 0.5f, s2, e2);
auto tween = jt::TweenPosition::create(m_textStart, 0.5f, start, end);
tween->setStartDelay(0.3f);
tween->setSkipFrames();

Expand Down Expand Up @@ -192,7 +188,7 @@ void StateMenu::onUpdate(float const elapsed)
checkForTransitionToStateGame();
}

void StateMenu::updateDrawables(const float& elapsed)
void StateMenu::updateDrawables(float const& elapsed)
{
m_background->update(elapsed);
m_textTitle->update(elapsed);
Expand Down
7 changes: 6 additions & 1 deletion impl/jamtemplate/sfml/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ void jt::Text::doDrawShadow(std::shared_ptr<jt::RenderTargetLayer> const sptr) c
jt::Vector2f const oldPos = fromLib(m_text->getPosition());
auto const oldCol = fromLib(m_text->getFillColor());

m_text->setPosition(toLib(oldPos + getShadowOffset()));
auto const position = oldPos + getShadowOffset();

jt::Vector2f const pos = jt::Vector2f { static_cast<float>(static_cast<int>(position.x)),
static_cast<float>(static_cast<int>(position.y)) };

m_text->setPosition(toLib(pos));
m_text->setFillColor(toLib(getShadowColor()));
sptr->draw(*m_text);

Expand Down

0 comments on commit 7b61cd9

Please sign in to comment.