Skip to content

Commit

Permalink
logging mode with console argument
Browse files Browse the repository at this point in the history
key release working fine
h button decreases lives
  • Loading branch information
denitdao committed May 26, 2019
1 parent 64f6f88 commit 587df2c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
21 changes: 16 additions & 5 deletions firstSFML/Hero.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Hero : public Actor {
sprite.move(distance);
chooseTexture();
}
void controle(sf::RenderWindow &window) {
void controle(sf::RenderWindow &window, Scoreboard &board) {
sf::Event _event;
// keypress detection

Expand All @@ -64,17 +64,28 @@ class Hero : public Actor {
exit(0);
}
case sf::Event::KeyReleased: {
if (sf::Keyboard::Up)
if (_event.key.code == sf::Keyboard::Up) {
upArrowPressed = false;
if (sf::Keyboard::Down)
myLog(Logger::DEBUG) << "Key up released" << endl;
}
if (_event.key.code == sf::Keyboard::Down) {
downArrowPressed = false;
if (sf::Keyboard::Left) {
myLog(Logger::DEBUG) << "Key down released" << endl;
}
if (_event.key.code == sf::Keyboard::Left) {
textureCounter = 1;
leftArrowPressed = false;
myLog(Logger::DEBUG) << "Key Left released" << endl;
}
if (sf::Keyboard::Right) {
if (_event.key.code == sf::Keyboard::Right) {
textureCounter = 1;
rightArrowPressed = false;
myLog(Logger::DEBUG) << "Key Right released" << endl;
}
if (_event.key.code == sf::Keyboard::H) {
this->respawn();
board.looseHeart();
myLog(Logger::DEBUG) << "Key H released" << endl;
}
break;
}
Expand Down
Binary file not shown.
5 changes: 4 additions & 1 deletion firstSFML/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ class Logger {
m_stream << output;
return *this;
}

void ChangeMaxLogLevel(int step) {
m_maxLogLevel = step;
(*this)(INFO) << "Max logger mode - " << m_maxLogLevel << endl;
}
// to finish getting input and flush it into the stream
Logger& operator<<(ManipFn manip) { // endl, flush, setw, setfill, etc.
manip(m_stream);
Expand Down
12 changes: 10 additions & 2 deletions firstSFML/firstSFML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ void changeScreen(sf::RenderWindow &window, string sceneName) {
window.clear();
window.draw(sceneScreen);
window.display();
_event.type = sf::Event::GainedFocus; // to avoid empty stack
// if stack is empty, event window closed will auto work
while (window.isOpen()) {
window.pollEvent(_event);
if (sceneName == "images/ending_screen.png") { // special behaviour on end screen
Expand All @@ -47,6 +49,7 @@ void changeScreen(sf::RenderWindow &window, string sceneName) {
window.pollEvent(_event);
if (_event.type == sf::Event::Closed) {
window.close();
cout << "closing" << endl;
exit(0);
}
endGamePlayer.autoMoveOn({ x_move_speed, 0 }, toright);
Expand Down Expand Up @@ -187,7 +190,7 @@ int gamePlay(sf::RenderWindow &window, Scoreboard &board) {
myLog(Logger::DEBUG) << "LOADED" << endl;
}

player.controle(window); // get user input
player.controle(window, board); // get user input
bot1.autoMoveOn({ x_move_speed, 0 });
bot2.autoMoveOn({ x_move_speed, 0 });
bot3.autoMoveOn({ x_move_speed, 0 });
Expand Down Expand Up @@ -246,6 +249,7 @@ int gamePlay(sf::RenderWindow &window, Scoreboard &board) {
if (player.inJump == false) {
player.checkCollision(map[player.xMap - 1][player.yMap - 1]); // left top
player.checkCollision(map[player.xMap + 1][player.yMap - 1]); // right top
player.checkCollision(map[player.xMap][player.yMap - 1]); // top
player.checkCollision(map[player.xMap + 1][player.yMap]); // right
player.checkCollision(map[player.xMap - 1][player.yMap]); // left
}
Expand Down Expand Up @@ -295,7 +299,11 @@ int gamePlay(sf::RenderWindow &window, Scoreboard &board) {
return level.current_level;
}

int main() {
int main(int argc, char* argv[]) {
if (argc == 2) {
myLog.ChangeMaxLogLevel(atoi(argv[1]));
}

Scoreboard board;
sf::RenderWindow window(sf::VideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y), "King's Valley", sf::Style::Default);
//window.setFramerateLimit(100);
Expand Down

0 comments on commit 587df2c

Please sign in to comment.