Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

Commit

Permalink
Reread and commented Overworld.[ch]pp
Browse files Browse the repository at this point in the history
And maybe fixed the issue #73 ? I can't compile with the computer I'm
using so I don't know.
  • Loading branch information
jlppc committed Oct 15, 2018
1 parent 204ec16 commit 82b0cd4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 41 deletions.
64 changes: 30 additions & 34 deletions src/opmon/view/Overworld.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

/*
Overworld.cpp
Author : Cyrion
Contributors : BAKFR, torq, Navet56
File under GNU GPL v3.0 license
*/
#include "Overworld.hpp"
#include "../model/objects/Enums.hpp"
#include <algorithm>
Expand Down Expand Up @@ -113,6 +118,7 @@ namespace OpMon {
}

void Overworld::printElements(sf::RenderTexture &frame) {
//"i" is the element's id
for(std::string const &i : current->getAnimatedElements()) {
data.incrementElementCounter(i);
if(data.getElementCounter(i) >= data.getElementTextures(i).size()) {
Expand All @@ -129,10 +135,12 @@ namespace OpMon {
current = data.getCurrentMap();
character.setPosition(pos.x SQUARES - 16, pos.y SQUARES);
resetCamera();
//If the music is the same, the program must do nothing. Else, the music will reboot and it's ugly.
if(musicPath != current->getBg()) {
setMusic(current->getBg());
}

//Recretes the layers
delete(layer1);
delete(layer2);
delete(layer3);
Expand All @@ -141,13 +149,6 @@ namespace OpMon {
layer3 = new MapLayer(current->getDimensions(), current->getLayer3());
tpCount = 0;

/*
for(auto itor = current->getEvents().begin(); itor != current->getEvents().end(); ++itor){
eventsSprites.try_emplace(itor, new sf::Sprite());
eventsSprites[itor].setPosition();
eventsSprites[itor].setTexture(itor->getTexture());
}
*/
}

void Overworld::pause() {
Expand All @@ -162,7 +163,7 @@ namespace OpMon {
: data(data) {
current = data.getMap(mapId);
character.setTexture(data.getTexturePP((unsigned int)Side::TO_DOWN));
data.getPlayer().tp(mapId, sf::Vector2i(2, 4));
data.getPlayer().tp(mapId, sf::Vector2i(2, 4));//TODO : Add a parameter to configure the default player's position
character.setPosition(2 SQUARES - 16, 4 SQUARES);
camera.setSize(sf::Vector2f(16 SQUARES, 16 SQUARES));
resetCamera();
Expand Down Expand Up @@ -190,6 +191,7 @@ namespace OpMon {

if(initPlayerAnimation){
startPlayerAnimationTime = Utils::Time::getElapsedMilliseconds();
charaStartPos = character.getPosition();
initPlayerAnimation = false;
}

Expand Down Expand Up @@ -218,11 +220,9 @@ namespace OpMon {
debugText.setCharacterSize(40);
fpsPrint.setPosition(0, 50);
fpsPrint.setFont(data.getUiDataPtr()->getFont());
//fpsPrint.setSfmlColor(sf::Color(127, 127, 127));
fpsPrint.setCharacterSize(48);
std::ostringstream oss;
oss << "Position : " << data.getPlayer().getPosition().getPosition().x << " - " << data.getPlayer().getPosition().getPosition().y << std::endl
<< "PxPosition : " << character.getPosition().x << " - " << character.getPosition().y << std::endl;
oss << "Position : " << data.getPlayer().getPosition().getPosition().x << " - " << data.getPlayer().getPosition().getPosition().y << std::endl << "PxPosition : " << character.getPosition().x << " - " << character.getPosition().y << std::endl;
coordPrint.setString(oss.str());
coordPrint.setFont(data.getUiDataPtr()->getFont());
coordPrint.setPosition(0, 100);
Expand Down Expand Up @@ -255,23 +255,6 @@ namespace OpMon {
}
}

//Sets the character's texture.
if(data.getPlayer().getPosition().isAnim() && !anims) {
character.setTexture(data.getWalkingPP((unsigned int)data.getPlayer().getPosition().getDir()));
animsCounter++;
anims = animsCounter > 8;

} else if(data.getPlayer().getPosition().isAnim() && anims) {
character.setTexture(data.getWalkingPP2((unsigned int)data.getPlayer().getPosition().getDir()));
animsCounter++;
if(animsCounter > 16) {
anims = false;
animsCounter = 0;
}
} else if(!data.getPlayer().getPosition().isAnim()) {
character.setTexture(data.getTexturePP((unsigned int)data.getPlayer().getPosition().getDir()));
}

if(!is_in_dialog && data.getPlayer().getPosition().isAnim()) {
if(data.getPlayer().getPosition().isMoving()) {
switch(data.getPlayer().getPosition().getDir()) {
Expand All @@ -291,13 +274,26 @@ namespace OpMon {
break;
}
}

const int currentTime = Utils::Time::getElapsedMilliseconds();
if(currentTime - startPlayerAnimationTime >= (7 * 1000 / 30)){ // assuming there is 30 frames per second.
data.getPlayer().getPosition().stopMove();
}
}

//Sets the character's texture.
if(data.getPlayer().getPosition().isAnim() && !anims) {
character.setTexture(data.getWalkingPP((unsigned int)data.getPlayer().getPosition().getDir()));
animsCounter++;
anims = animsCounter > 8;

} else if(data.getPlayer().getPosition().isAnim() && anims) {
character.setTexture(data.getWalkingPP2((unsigned int)data.getPlayer().getPosition().getDir()));
animsCounter++;
if(animsCounter > 16) {
data.getPlayer().getPosition().stopMove();//Stops the caracter's movement
anims = false;
animsCounter = 0;
}
} else if(!data.getPlayer().getPosition().isAnim()) {
character.setTexture(data.getTexturePP((unsigned int)data.getPlayer().getPosition().getDir()));
}

//Drawing character
frame.draw(character);
//Drawing the events above the player
Expand Down
14 changes: 7 additions & 7 deletions src/opmon/view/Overworld.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/*
Overworld.hpp
Author : Jlppc
File under the license GPL-3.0
http://opmon-game.ga
Contains Overworld namespace
Author : Cyrion
Contributor : BAKFR
File under GNU GPL v3.0 license
*/
#ifndef OVERWORLD_HPP
#define OVERWORLD_HPP
Expand Down Expand Up @@ -89,8 +88,8 @@ namespace OpMon {
}

/**
* Events can call this method to start a new dialog with the player.
*/
* Events can call this method to start a new dialog with the player.
*/
void startDialog(std::vector<sf::String> const &dialogs);

void startPlayerAnimation() {
Expand All @@ -112,6 +111,7 @@ namespace OpMon {

sf::View camera;
sf::Sprite character;
sf::Vector2f charaStartPos;
Model::Map *current = nullptr;

std::string musicPath = "";
Expand All @@ -120,7 +120,7 @@ namespace OpMon {
MapLayer *layer2 = nullptr;
MapLayer *layer3 = nullptr;
Dialog *dialog = nullptr;
//Indicate the frame of the walking animation that must be used.
//Indicate the frame of the walking animation that must be used. (The animation has two frames)
bool anims = false;

int fpsCounter = 0;
Expand Down

0 comments on commit 82b0cd4

Please sign in to comment.