Skip to content

Commit

Permalink
Fixed many issues and made game better
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-Belliveau committed Mar 4, 2019
1 parent bcd4c57 commit 1ee6f77
Show file tree
Hide file tree
Showing 16 changed files with 253 additions and 122 deletions.
51 changes: 51 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"files.associations": {
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
"chrono": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"fstream": "cpp",
"functional": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"memory": "cpp",
"new": "cpp",
"numeric": "cpp",
"optional": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"type_traits": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"__config": "cpp",
"__nullptr": "cpp",
"algorithm": "cpp"
}
}
Binary file modified GameFiles/Bounce.wav
Binary file not shown.
Binary file modified GameFiles/Coin.wav
Binary file not shown.
Binary file modified GameFiles/Death.wav
Binary file not shown.
Binary file modified GameFiles/Jump.wav
Binary file not shown.
Binary file modified GameFiles/Overworld.wav
Binary file not shown.
Binary file modified GameFiles/Win.wav
Binary file not shown.
Binary file modified Levels/L6.lvl
Binary file not shown.
Binary file modified Levels/L7.lvl
Binary file not shown.
Binary file modified Levels/L8.lvl
Binary file not shown.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

**Mac (SFML REQUIRED):** `clang++ -o UpsideDown.out ./src/*.cpp -framework sfml-window -framework sfml-graphics -framework sfml-system -framework sfml-graphics -framework sfml-audio -std=c++17 -O3`

**Windows:** Extract the DLLs into the root of the project and run the exe.

*This game relys on other files in the project folder, keep everything where it is*

To run the game run `./UpsideDown.out`

### When Changing sound files, it does not need to be `.wav`, it can be `.ogg` or `.flac`

#### You will need https://www.sfml-dev.org/download.php to compile the game

## What is a `.lvl`
Expand Down
152 changes: 104 additions & 48 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ const Game::GameTypeLink Game::GameTypeList[GameTypeCount] = {
}
}, {
GameType::MoveRight,
{"Move Right", sf::Color(64, 196, 0), 64, 0, 1.0/3.0,
{"Move Right", sf::Color(64, 196, 0), 64, 1, 4.0/9.0,
TypeProps::MoveRight | TypeProps::StopStorm
}
}, {
GameType::MoveLeft,
{"Move Left", sf::Color(64, 196, 0), 64, 0, -1.0/3.0,
{"Move Left", sf::Color(64, 196, 0), 64, 1, -4.0/9.0,
TypeProps::MoveLeft | TypeProps::StopStorm
}
}, {
Expand Down Expand Up @@ -112,45 +112,54 @@ const Game::GameTypeData Game::GetTypeData(GameType input)
return GameTypeList[RANDOMIZE(GET_GLOBAL_FRAME())%GameTypeCount].data;
}


void Game::loadBufferFromFile(sf::SoundBuffer& buf, const std::string& name)
{
for(const std::string& ext : SOUND_EXTENTIONS)
if(buf.loadFromFile(SOUND_DIRECTORY + name + ext))
break;
}

/****************************/
/***** INSTANCE MEMBERS *****/
/****************************/

Game::Game()
{
loadWorld(START_LEVEL);
coinBuffer.loadFromFile("./GameFiles/Coin.wav");
loadBufferFromFile(coinBuffer, "Coin");
coinSound.setBuffer(coinBuffer);
coinSound.setPitch(COIN_PITCH);
coinSound.setVolume(COIN_VOL);
coinSound.setLoop(false);

jumpBuffer.loadFromFile("./GameFiles/Jump.wav");
loadBufferFromFile(jumpBuffer, "Jump");
jumpSound.setBuffer(jumpBuffer);
jumpSound.setPitch(JUMP_PITCH);
jumpSound.setVolume(JUMP_VOL);
jumpSound.setLoop(false);

bounceBuffer.loadFromFile("./GameFiles/Bounce.wav");
loadBufferFromFile(bounceBuffer, "Bounce");
bounceSound.setBuffer(bounceBuffer);
bounceSound.setPitch(BOUNCE_PITCH);
bounceSound.setVolume(BOUNCE_VOL);
bounceSound.setLoop(false);

deathBuffer.loadFromFile("./GameFiles/Death.wav");
loadBufferFromFile(deathBuffer, "Death");
deathSound.setBuffer(deathBuffer);
deathSound.setPitch(DEATH_PITCH);
deathSound.setVolume(DEATH_VOL);
deathSound.setLoop(false);

winBuffer.loadFromFile("./GameFiles/Win.wav");
loadBufferFromFile(winBuffer, "Win");
winSound.setBuffer(winBuffer);
winSound.setPitch(WIN_PITCH);
winSound.setVolume(WIN_VOL);
winSound.setLoop(false);

overworldBuffer.loadFromFile("./GameFiles/Overworld.wav");
overworldMusic.setBuffer(overworldBuffer);
for(const std::string& ext : SOUND_EXTENTIONS)
if(overworldMusic.openFromFile(SOUND_DIRECTORY + "Overworld" + ext))
break;
overworldMusic.setPitch(OVERWORLD_PITCH);
overworldMusic.setVolume(OVERWORLD_VOL);
overworldMusic.setLoop(true);
Expand Down Expand Up @@ -181,30 +190,30 @@ bool Game::resetKey()

bool Game::upKey()
{
return sf::Keyboard::isKeyPressed(sf::Keyboard::Up)
|| sf::Keyboard::isKeyPressed(sf::Keyboard::W)
|| joyYAxis() < -Y_JOYSTICK_DEAD_ZONE;
return (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)
|| sf::Keyboard::isKeyPressed(sf::Keyboard::W)
|| joyYAxis() < -Y_JOYSTICK_DEAD_ZONE) && !cheatKey();
}

bool Game::downKey()
{
return sf::Keyboard::isKeyPressed(sf::Keyboard::Down)
|| sf::Keyboard::isKeyPressed(sf::Keyboard::S)
|| joyYAxis() > Y_JOYSTICK_DEAD_ZONE;
return (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)
|| sf::Keyboard::isKeyPressed(sf::Keyboard::S)
|| joyYAxis() > Y_JOYSTICK_DEAD_ZONE) && !cheatKey();
}

bool Game::leftKey()
{
return sf::Keyboard::isKeyPressed(sf::Keyboard::Left)
|| sf::Keyboard::isKeyPressed(sf::Keyboard::A)
|| joyXAxis() < -X_JOYSTICK_DEAD_ZONE;
return (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)
|| sf::Keyboard::isKeyPressed(sf::Keyboard::A)
|| joyXAxis() < -X_JOYSTICK_DEAD_ZONE) && !cheatKey();
}

bool Game::rightKey()
{
return sf::Keyboard::isKeyPressed(sf::Keyboard::Right)
|| sf::Keyboard::isKeyPressed(sf::Keyboard::D)
|| joyXAxis() > X_JOYSTICK_DEAD_ZONE;
return (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)
|| sf::Keyboard::isKeyPressed(sf::Keyboard::D)
|| joyXAxis() > X_JOYSTICK_DEAD_ZONE) && !cheatKey();
}

bool Game::jumpKey(GravityType gravity)
Expand Down Expand Up @@ -239,6 +248,16 @@ bool Game::editorCheatKey()
return cheatKey() && sf::Keyboard::isKeyPressed(sf::Keyboard::E);
}

bool Game::soundKey()
{
return cheatKey() && sf::Keyboard::isKeyPressed(sf::Keyboard::S);
}

bool Game::musicKey()
{
return cheatKey() && sf::Keyboard::isKeyPressed(sf::Keyboard::M);
}

/********************/
/***** GAMELOOP *****/
/********************/
Expand Down Expand Up @@ -312,7 +331,7 @@ void Game::goalLoop()
if(player.x >= GAME_LENGTH
|| getPlayerData().getProp(TypeProps::Goal))
{
winSound.play();
if(playSounds) winSound.play();
loadWorld(level + 1);
}
}
Expand All @@ -323,34 +342,27 @@ bool Game::cheatLoop()
// Developer Key Combos
if(flyCheatKey())
{
setCheater();
if(player.x > 0 && leftKey())
player.x -= 1;

if(player.x <= GAME_LENGTH && rightKey())
player.x += 1;

if(player.y > 0 && upKey())
player.y -= 1;
enableFly = !enableFly;
while(flyCheatKey()){}
}

if(player.y < GAME_HEIGHT - 1 && downKey())
player.y += 1;

if(enableFly)
{
setCheater();
if(player.x > 0 && leftKey()) player.x -= 1;
if(player.x <= GAME_LENGTH && rightKey()) player.x += 1;
if(player.y > 0 && upKey()) player.y -= 1;
if(player.y < GAME_HEIGHT - 1 && downKey()) player.y += 1;
cameraLoop();
return true;
} else if(levelCheatKey())
}

if(levelCheatKey())
{
setCheater();
if(leftKey())
{
level--;
while(leftKey());
} else if(rightKey())
{
level++;
while(rightKey());
}
level++;
loadWorld(level);
while(levelCheatKey()) {}
return true;
}

Expand All @@ -366,7 +378,7 @@ void Game::trapLoop()
{
if(player.x >= START_SIZE && !getWinner())
{
deathSound.play();
if(playSounds) deathSound.play();
++deaths;
}

Expand Down Expand Up @@ -395,7 +407,7 @@ void Game::jumpLoop()
{
if(canJump)
{
jumpSound.play();
if(playSounds) jumpSound.play();
gravity = GravityType(-gravity);
}
canJump = false;
Expand All @@ -410,7 +422,7 @@ void Game::bounceLoop()
{
if(canBounce)
{
bounceSound.play();
if(playSounds) bounceSound.play();
gravity = GravityType(-gravity);
canJump = false;
}
Expand Down Expand Up @@ -467,7 +479,7 @@ void Game::coinLoop()
{
if(getPlayerData().getProp(TypeProps::Coin))
{
coinSound.play();
if(playSounds) coinSound.play();

// Count Coin
++coins;
Expand Down Expand Up @@ -503,6 +515,24 @@ void Game::coinLoop()

void Game::soundLoop()
{
if(soundKey())
{
playSounds = !playSounds;
while(soundKey()){}
}

if(musicKey())
{
if(overworldMusic.getStatus() == sf::Sound::Playing)
{
overworldMusic.pause();
} else {
overworldMusic.play();
}

while(musicKey()){}
}

if(getPlayerData().getProp(TypeProps::LowGravity))
{
overworldMusic.setPitch(OVERWORLD_PITCH / LOWGRAVITY_PITCH);
Expand Down Expand Up @@ -550,6 +580,15 @@ IntType Game::loadWorld(const IntType inLevel)
return loadWorld(level + 1);

updateLevelHash();

if(!getWinner())
{
coins = 0;
levelCoins[level] = 0;
for(IntType i = 1; i < level; ++i)
{ coins += levelCoins[i]; }
}

reset();
return level;
}
Expand Down Expand Up @@ -627,6 +666,8 @@ const Byte* Game::returnWorldPixels(bool focus)

HashType Game::updateLevelHash()
{
#define ROTATE(x, rot) (((x) << (rot)) | ((x) >> (sizeof(x)*8 - (rot))))

HashType oldHash = hash; hash = 0;
HashType oldCoins = maxCoins; maxCoins = 0;
HashType oldFinalLevel = finalLevel; finalLevel = 0;
Expand Down Expand Up @@ -679,12 +720,22 @@ HashType Game::updateLevelHash()

if(hash != oldHash
|| finalLevel != oldFinalLevel) setCheater();

#undef ROTATE

return hash;
}

/*****************************/
/***** GETTERS / SETTERS *****/
/*****************************/
void Game::setSound(bool value)
{
playSounds = value;
if(playSounds) overworldMusic.pause();
else overworldMusic.play();
}


IntType Game::getCameraX() const
{
Expand Down Expand Up @@ -780,6 +831,11 @@ bool Game::getCheater() const
return hasCheated;
}

bool Game::getFlying() const
{
return enableFly;
}

bool Game::getWinner() const
{
return level == 0;
Expand Down
Loading

0 comments on commit 1ee6f77

Please sign in to comment.