Skip to content
Permalink
Browse files
fixed quit bug and layout
  • Loading branch information
ac0745 committed Feb 3, 2020
1 parent 7c65d53 commit 49f64b9ce687a6002871d2fb9b057f1bc2b436a3
Showing 1 changed file with 65 additions and 65 deletions.
130 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;
}
}

0 comments on commit 49f64b9

Please sign in to comment.