Skip to content

Commit

Permalink
Added permafrost map
Browse files Browse the repository at this point in the history
  • Loading branch information
Piterson25 committed Dec 18, 2022
1 parent 6cf147f commit a9dea34
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 28 deletions.
2 changes: 2 additions & 0 deletions Defnight/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ GameState::GameState(const float& gridSize, sf::RenderWindow* window, GameSettin

float offsetY = 0.f;
if (map_name == "desert") offsetY = 48.f;
else if (map_name == "permafrost") offsetY = 96.f;
size_t t = 0;
const sf::Vector2f tile = sf::Vector2f(calcX(64, vm), calcY(64, vm));
if (mapa.is_open()) {
Expand Down Expand Up @@ -289,6 +290,7 @@ void GameState::update(const float& dt)
this->player->animation(dt);
this->player->abilityCounter(dt);
this->playerGUI->updateArmor();
this->playerGUI->updateAttack();
this->playerGUI->update_ability(dt);

}
Expand Down
29 changes: 27 additions & 2 deletions Defnight/MainMenuState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ void MainMenuState::initGUI()
this->mapView.setSize(sf::Vector2f(static_cast<float>(vm.width), static_cast<float>(vm.height)));
this->mapView.setCenter(static_cast<float>(vm.width / 2), static_cast<float>(vm.height / 2));

if (const uint8_t m = static_cast<uint8_t>(Random::Float() * 2.f); m == 0) {
if (const uint8_t m = static_cast<uint8_t>(Random::Float() * 3.f); m == 0) {
this->map_texture.loadFromFile("external/assets/ruins.png");
}
else {
else if (m == 1) {
this->map_texture.loadFromFile("external/assets/desert.png");
}
else {
this->map_texture.loadFromFile("external/assets/permafrost.png");
}

this->map.setTexture(this->map_texture);
this->map.setScale(calcScale(4, vm), calcScale(4, vm));
Expand Down Expand Up @@ -92,6 +95,9 @@ void MainMenuState::initGUI()
this->sprite_buttons["SELECT_MAP2"] = new gui::ButtonSprite("external/assets/select_map.png", calcX(472, vm), calcY(248, vm), calcScale(1, vm), false);
this->sprites["MAP2"] = new gui::Sprite("external/assets/desert.png", calcX(496, vm), calcY(272, vm), calcScale(0.5f, vm), false);
this->texts["DESERT"] = new gui::Text(&this->font, this->lang["DESERT"], calcChar(32, vm), calcX(624, vm), calcY(200, vm), sf::Color(255, 255, 255), true);
this->sprite_buttons["SELECT_MAP3"] = new gui::ButtonSprite("external/assets/select_map.png", calcX(920, vm), calcY(248, vm), calcScale(1, vm), false);
this->sprites["MAP3"] = new gui::Sprite("external/assets/permafrost.png", calcX(944, vm), calcY(272, vm), calcScale(0.5f, vm), false);
this->texts["PERMAFROST"] = new gui::Text(&this->font, this->lang["PERMAFROST"], calcChar(32, vm), calcX(1072, vm), calcY(200, vm), sf::Color(255, 255, 255), true);


// PAGE 3
Expand Down Expand Up @@ -325,6 +331,22 @@ void MainMenuState::update(const float& dt)
this->page = 3;
this->sprite_buttons["SELECT_MAP2"]->setTransparent();
}

this->sprite_buttons["SELECT_MAP1"]->update(this->mousePosWindow);
if (this->sprite_buttons["SELECT_MAP1"]->isPressed() && !this->getMouseClick()) {
this->setMouseClick(true);
this->map_name = "ruins";
this->page = 3;
this->sprite_buttons["SELECT_MAP1"]->setTransparent();
}

this->sprite_buttons["SELECT_MAP3"]->update(this->mousePosWindow);
if (this->sprite_buttons["SELECT_MAP3"]->isPressed() && !this->getMouseClick()) {
this->setMouseClick(true);
this->map_name = "permafrost";
this->page = 3;
this->sprite_buttons["SELECT_MAP3"]->setTransparent();
}
break;
case 3:
this->sprite_buttons["GO_BACK"]->update(this->mousePosWindow);
Expand Down Expand Up @@ -450,9 +472,12 @@ void MainMenuState::draw(sf::RenderTarget* target)
this->sprite_buttons["SELECT_MAP1"]->draw(*target);
this->sprites["MAP2"]->draw(*target);
this->sprite_buttons["SELECT_MAP2"]->draw(*target);
this->sprites["MAP3"]->draw(*target);
this->sprite_buttons["SELECT_MAP3"]->draw(*target);

this->texts["RUINS"]->draw(*target);
this->texts["DESERT"]->draw(*target);
this->texts["PERMAFROST"]->draw(*target);
break;
case 3:
this->sprites["GO_BACK"]->draw(*target);
Expand Down
50 changes: 25 additions & 25 deletions Defnight/MonsterSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,51 +129,51 @@ void MonsterSystem::monsterCollision(Monster* mob)
{
for (const auto& monster : monsters) {
if (vectorDistance(mob->getPosition(), monster->getPosition()) < 2 * monster->getGlobalBounds().width) {
sf::FloatRect monsterBounds = mob->getGlobalBounds();
sf::FloatRect goblinBounds = monster->getGlobalBounds();
sf::FloatRect mobBounds = mob->getGlobalBounds();
sf::FloatRect monsterBounds = monster->getGlobalBounds();

sf::FloatRect nextPos = monsterBounds;
sf::FloatRect nextPos = mobBounds;
nextPos.left += mob->getVelocity().x;
nextPos.top += mob->getVelocity().y;

if (goblinBounds.intersects(nextPos))
if (monsterBounds.intersects(nextPos))
{
//Dolna kolizja
if (monsterBounds.top < goblinBounds.top
&& monsterBounds.top + monsterBounds.height < goblinBounds.top + goblinBounds.height
&& monsterBounds.left < goblinBounds.left + goblinBounds.width
&& monsterBounds.left + monsterBounds.width > goblinBounds.left)
if (mobBounds.top < monsterBounds.top
&& mobBounds.top + mobBounds.height < monsterBounds.top + monsterBounds.height
&& mobBounds.left < monsterBounds.left + monsterBounds.width
&& mobBounds.left + mobBounds.width > monsterBounds.left)
{
mob->setVeloctiy(sf::Vector2f(mob->getVelocity().x, 0.f));
mob->setPosition(monsterBounds.left, goblinBounds.top - monsterBounds.height);
mob->setPosition(mobBounds.left, monsterBounds.top - mobBounds.height);
}
//Gorna kolizja
else if (monsterBounds.top > goblinBounds.top
&& monsterBounds.top + monsterBounds.height > goblinBounds.top + goblinBounds.height
&& monsterBounds.left < goblinBounds.left + goblinBounds.width
&& monsterBounds.left + monsterBounds.width > goblinBounds.left)
else if (mobBounds.top > monsterBounds.top
&& mobBounds.top + mobBounds.height > monsterBounds.top + monsterBounds.height
&& mobBounds.left < monsterBounds.left + monsterBounds.width
&& mobBounds.left + mobBounds.width > monsterBounds.left)
{
mob->setVeloctiy(sf::Vector2f(mob->getVelocity().x, 0.f));
mob->setPosition(monsterBounds.left, goblinBounds.top + goblinBounds.height);
mob->setPosition(mobBounds.left, monsterBounds.top + monsterBounds.height);
}

//Prawa kolizja
else if (monsterBounds.left < goblinBounds.left
&& monsterBounds.left + monsterBounds.width < goblinBounds.left + goblinBounds.width
&& monsterBounds.top < goblinBounds.top + goblinBounds.height
&& monsterBounds.top + monsterBounds.height > goblinBounds.top)
else if (mobBounds.left < monsterBounds.left
&& mobBounds.left + mobBounds.width < monsterBounds.left + monsterBounds.width
&& mobBounds.top < monsterBounds.top + monsterBounds.height
&& mobBounds.top + mobBounds.height > monsterBounds.top)
{
mob->setVeloctiy(sf::Vector2f(0.f, mob->getVelocity().y));
mob->setPosition(goblinBounds.left - monsterBounds.width, monsterBounds.top);
mob->setPosition(monsterBounds.left - mobBounds.width, mobBounds.top);
}
//Lewa kolizja
else if (monsterBounds.left > goblinBounds.left
&& monsterBounds.left + monsterBounds.width > goblinBounds.left + goblinBounds.width
&& monsterBounds.top < goblinBounds.top + goblinBounds.height
&& monsterBounds.top + monsterBounds.height > goblinBounds.top)
else if (mobBounds.left > monsterBounds.left
&& mobBounds.left + mobBounds.width > monsterBounds.left + monsterBounds.width
&& mobBounds.top < monsterBounds.top + monsterBounds.height
&& mobBounds.top + mobBounds.height > monsterBounds.top)
{
mob->setVeloctiy(sf::Vector2f(0.f, mob->getVelocity().y));
mob->setPosition(goblinBounds.left + goblinBounds.width, monsterBounds.top);
mob->setPosition(monsterBounds.left + monsterBounds.width, mobBounds.top);
}
}
}
Expand Down Expand Up @@ -309,8 +309,8 @@ void MonsterSystem::update(Player* player, PlayerGUI* playerGUI, ProjectileSyste
else {
monster->AI(this->tileMap, player, dt);
if (monster->hasVelocity()) {
monster->obstacleCollision(this->tileMap);
monsterCollision(&(*monster));
monster->obstacleCollision(this->tileMap);
monster->move();
monster->update(dt);
}
Expand Down
Binary file modified Defnight/external/assets/desert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Defnight/external/assets/permafrost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Defnight/external/assets/tiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Defnight/external/config/game_settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
0
0
1
10
20
50
polish
1 change: 1 addition & 0 deletions Defnight/external/languages/english.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ NO No
CHOOSE_MAP Choose map:
RUINS Ruins
DESERT Desert
PERMAFROST Permafrost
CHOOSE_HERO Choose character:
CHOOSE Choose
WARRIOR Warrior
Expand Down
1 change: 1 addition & 0 deletions Defnight/external/languages/polish.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ NO Nie
CHOOSE_MAP Wybierz mape:
RUINS Ruiny
DESERT Pustynia
PERMAFROST Zmarzlina
CHOOSE_HERO Wybierz postac:
CHOOSE Wybierz
WARRIOR Wojownik
Expand Down
32 changes: 32 additions & 0 deletions Defnight/external/maps/permafrost.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@@##@######@###@@#@@@@@@@@####@@
# # @ #
@ # @ #
# @@ ## # @####### #
@ ## @@ # #
@ @
@ @#@@#### @
##@##@@### @@ #
@ ## @
@ @
# @@# # #
@ #@ ## @
# # #
# #
# #
# S #
# #
@ @
@ @
# # # #
# # @ #
# # @ @
@######@@# @@ @##@@##@@
@ #@ @ #
# @ #
# # @ #
# @ @ #
@ @ @ # #
@ @ # #@@
# @# ###@
@ @# #@##
@@#@#@@#@@@###@#@#####@###@@@@#@

0 comments on commit a9dea34

Please sign in to comment.