From 615a153a761e27a74159ae8efd934bc2c6d3693c Mon Sep 17 00:00:00 2001 From: JingYiJun Date: Mon, 30 May 2022 22:57:23 +0800 Subject: [PATCH] Fixed variable desktop resolution problems --- Makefile | 2 +- src/element/Fruit.cpp | 4 +--- src/element/Fruit.h | 1 - src/element/Snake.cpp | 2 +- src/element/TitleSprite.cpp | 2 +- 5 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 7c981f8..f6702fe 100644 --- a/Makefile +++ b/Makefile @@ -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)) diff --git a/src/element/Fruit.cpp b/src/element/Fruit.cpp index 04d5dcf..0d7d72b 100644 --- a/src/element/Fruit.cpp +++ b/src/element/Fruit.cpp @@ -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); diff --git a/src/element/Fruit.h b/src/element/Fruit.h index e1f92de..0c85b63 100644 --- a/src/element/Fruit.h +++ b/src/element/Fruit.h @@ -8,7 +8,6 @@ namespace sfSnake { sf::CircleShape shape_; int score_; - static float Radius; Fruit(sf::Vector2f position, sf::Color color, int score); diff --git a/src/element/Snake.cpp b/src/element/Snake.cpp index 61b721d..2ff84ee 100644 --- a/src/element/Snake.cpp +++ b/src/element/Snake.cpp @@ -138,7 +138,7 @@ void Snake::checkFruitCollisions(std::deque &fruits) { if (dis( i->shape_.getPosition(), toWindow(headnode)) < - nodeRadius_ + i->Radius) + nodeRadius_ + i->shape_.getRadius()) toRemove = i; } diff --git a/src/element/TitleSprite.cpp b/src/element/TitleSprite.cpp index 80aa478..1d50e53 100644 --- a/src/element/TitleSprite.cpp +++ b/src/element/TitleSprite.cpp @@ -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); }