From 49f64b9ce687a6002871d2fb9b057f1bc2b436a3 Mon Sep 17 00:00:00 2001 From: David Croft Date: Mon, 3 Feb 2020 17:10:37 +0000 Subject: [PATCH] fixed quit bug and layout --- main.cpp | 130 +++++++++++++++++++++++++++---------------------------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/main.cpp b/main.cpp index 39013da..0177813 100644 --- a/main.cpp +++ b/main.cpp @@ -4,76 +4,76 @@ int main() { - // === create the world === - World world( 100, 100 ); // 100 tiles by 100 - View display( world, 60, 30 ); // create a view window of 60 by 30 tiles + // === create the world === + World world( 100, 100 ); // 100 tiles by 100 + View display( world, 60, 30 ); // create a view window of 60 by 30 tiles - // === create a player === - Entity player( '#', 20, 20, Terminal::Color::FG_RED, Terminal::Color::BG_GREEN ); - int playerHealth = 100; - int playerMoves = 100; - - // === create some next boxes === - TextBox healthBox( 65, 10, 15 ); - TextBox moveBox( 65, 15, 15 ); - - display.add( healthBox ); - display.add( moveBox ); - - // === populate the world === - world.fill( Tile('-', Terminal::Color::FG_WHITE, Terminal::Color::BG_GREEN ) ); - - Tile water( 'w', Terminal::Color::FG_BLUE, Terminal::Color::BG_BLUE ); - world.get( 10, 10 ) = water; - world.get( 20, 35 ) = water; - - world.add( player ); + // === create a player === + Entity player( '#', 20, 20, Terminal::Color::FG_RED, Terminal::Color::BG_GREEN ); + int playerHealth = 100; + int playerMoves = 100; + + // === create some next boxes === + TextBox healthBox( 65, 10, 15 ); + TextBox moveBox( 65, 15, 15 ); + + display.add( healthBox ); + display.add( moveBox ); + + // === populate the world === + world.fill( Tile('-', Terminal::Color::FG_WHITE, Terminal::Color::BG_GREEN ) ); + + Tile water( 'w', Terminal::Color::FG_BLUE, Terminal::Color::BG_BLUE ); + world.get( 10, 10 ) = water; + world.get( 20, 35 ) = water; + + world.add( player ); - // === set up the screen === - Terminal::clear(); // wipe it - Terminal::cursor(false); // turn cursor off - - Keyboard keys; - keys.grab(); // dont display key presses on screen + // === set up the screen === + Terminal::clear(); // wipe it + Terminal::cursor(false); // turn cursor off + + Keyboard keys; + keys.grab(); // dont display key presses on screen - char c = 0; + char c = 0; while( c != 'q' ) - { - // display player stats - healthBox.clear(); - healthBox << "Health: " << playerHealth; - - moveBox.clear(); - moveBox << "Moves: " << playerMoves; - - // move the viewpoint so it centers on the player - display.x = player.x - display.width/2; - display.y = player.y - display.height/2; - - display.draw(); - - const char c = keys.get(); - bool moved = true; - switch( c ) - { - case 'w': player.up(); break; - case 's': player.down(); break; - case 'a': player.left(); break; - case 'd': player.right(); break; - default: moved = false; break; - } - - if( moved ) - { - playerMoves -= 1; - - if( world.get( player.x, player.y ).contents == 'w' ) // player is in water - playerHealth -= 1; - } + { + // display player stats + healthBox.clear(); + healthBox << "Health: " << playerHealth; + + moveBox.clear(); + moveBox << "Moves: " << playerMoves; + + // move the viewpoint so it centers on the player + display.x = player.x - display.width/2; + display.y = player.y - display.height/2; + + display.draw(); + + c = keys.get(); // get keyboard input + bool moved = true; + switch( c ) + { + case 'w': player.up(); break; + case 's': player.down(); break; + case 'a': player.left(); break; + case 'd': player.right(); break; + default: moved = false; break; + } + + if( moved ) + { + playerMoves -= 1; + + if( world.get( player.x, player.y ).contents == 'w' ) // player is in water + playerHealth -= 1; + } } keys.release(); - Terminal::cursor(true); - + Terminal::cursor(true); + return 0; -} \ No newline at end of file +}