Skip to content

Commit

Permalink
Fixed variable desktop resolution problems
Browse files Browse the repository at this point in the history
  • Loading branch information
JingYiJun committed May 30, 2022
1 parent 6ab04ff commit 615a153
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CXX_FLAGS=-g -static -std=c++17 -Wall -O2 -DSFML_STATIC #-Wl,--stack=268435456
rm=rm -fr
mkdir=mkdir2 -p

TARGET=main
TARGET=sfSnakePro
BUILD_DIR=build
SRC_DIR= src src/screen src/element
SRCS = $(foreach dir, $(SRC_DIR), $(wildcard $(dir)/*.cpp))
Expand Down
4 changes: 1 addition & 3 deletions src/element/Fruit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

using namespace sfSnake;

float Fruit::Radius = 5.0f;

Fruit::Fruit(sf::Vector2f position, sf::Color color, int score)
: score_(score)
{
shape_.setRadius(Fruit::Radius);
shape_.setRadius(Game::GlobalVideoMode.width / 256.0f);
setOriginMiddle(shape_);
shape_.setPosition(position);
shape_.setFillColor(color);
Expand Down
1 change: 0 additions & 1 deletion src/element/Fruit.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace sfSnake
{
sf::CircleShape shape_;
int score_;
static float Radius;

Fruit(sf::Vector2f position, sf::Color color, int score);

Expand Down
2 changes: 1 addition & 1 deletion src/element/Snake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void Snake::checkFruitCollisions(std::deque<Fruit> &fruits)
{
if (dis(
i->shape_.getPosition(), toWindow(headnode)) <
nodeRadius_ + i->Radius)
nodeRadius_ + i->shape_.getRadius())
toRemove = i;
}

Expand Down
2 changes: 1 addition & 1 deletion src/element/TitleSprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TitleSprite::TitleSprite()
titleSprite_.setTexture(titleTexture_);

sf::FloatRect titleSpriteBounds = setOriginMiddle(titleSprite_);
titleSprite_.setScale(titleSpriteBounds.width / Game::GlobalVideoMode.width / 5.0 * 4.0, titleSpriteBounds.width / Game::GlobalVideoMode.width / 5.0 * 4.0);
titleSprite_.setScale(Game::GlobalVideoMode.width / titleSpriteBounds.width * 0.5f, Game::GlobalVideoMode.width / titleSpriteBounds.width * 0.5f);
titleSprite_.setPosition(Game::GlobalVideoMode.width / 2, Game::GlobalVideoMode.height / 4);
}

Expand Down

0 comments on commit 615a153

Please sign in to comment.