-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3bdd833
Showing
34 changed files
with
3,252 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
#include "Animation.h" | ||
|
||
Animation::Animation(const sf::Texture& data, bool dir, sf::Sprite& sprite, int size) | ||
: m_data(data), m_dir(dir), m_sprite(sprite),m_size(size), m_totalTime(0),m_current(0) | ||
{ | ||
initializeTexture(size); | ||
m_sprite.setTexture(data); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// This function is used to shift between the different sprites that | ||
// an object have. | ||
void Animation::staticShift(sf::Time deltaTime, float switchTime) | ||
{ | ||
m_totalTime += deltaTime.asSeconds(); // Counting the time passed into a member. | ||
if (m_totalTime > switchTime) // Inc case the time is larger then SwitchTime | ||
{ // We change the sprite. | ||
m_totalTime -= switchTime; | ||
m_current++; | ||
if (m_current >= m_size - 1) | ||
m_current = 0; | ||
|
||
m_uvRect.left = m_uvRect.width * m_current; // Here we decide which sprite we will take. | ||
m_sprite.setTextureRect(m_uvRect); | ||
} | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// This function flips the sprite to change direction he posing to. | ||
void Animation::setDirection(bool Direction) | ||
{ | ||
if (Direction) | ||
{ | ||
m_uvRect.left = m_current * m_uvRect.width; | ||
m_uvRect.width = std::abs(m_uvRect.width); | ||
} | ||
else | ||
{ | ||
m_uvRect.left = (m_current+1) * std::abs(m_uvRect.width); | ||
m_uvRect.width = -std::abs(m_uvRect.width); | ||
} | ||
m_sprite.setTextureRect(m_uvRect); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void Animation::initializeTexture(int size) | ||
{ | ||
m_size = size; | ||
m_uvRect.width = (m_data.getSize().x) / m_size; | ||
m_uvRect.height = m_data.getSize().y; | ||
m_sprite.setTextureRect(m_uvRect); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void Animation::changeMarioTexture(const sf::Texture& data, int size) | ||
{ | ||
m_data = data; | ||
m_sprite.setTexture(data); | ||
initializeTexture(size); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// This function only handles the player sprite. | ||
void Animation::updatePlayer(bool direction,bool standing, bool fire, | ||
bool inAir, bool duck, float velocity, sf::Time deltaTime) | ||
{ | ||
if (fire) // Player shoots | ||
{ | ||
fireFunc(); | ||
return; | ||
} | ||
if (duck) // Player Ducking | ||
{ | ||
duckFunc(); | ||
return; | ||
} | ||
if (standing && !inAir) // Player Standing | ||
{ | ||
standFunc(); | ||
return; | ||
} | ||
|
||
m_totalTime += deltaTime.asSeconds(); | ||
|
||
if (inAir) // Player Jumping | ||
m_current = PLAYER_JUMP; | ||
|
||
|
||
// Player slipping | ||
else if (direction == LEFT && velocity > 0 || | ||
direction == RIGHT && velocity < 0) | ||
m_current = PLAYER_SLIP; | ||
|
||
// Player Walking | ||
else if (m_totalTime > SWITCH) | ||
{ | ||
m_totalTime -= SWITCH; | ||
m_current++; | ||
|
||
if (m_current > PLAYER_WALK_END) | ||
m_current = PLAYER_WALK_FIRST; | ||
} | ||
|
||
m_uvRect.left = m_uvRect.width * m_current; | ||
m_sprite.setTextureRect(m_uvRect); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void Animation::duckFunc() | ||
{ | ||
m_current = PLAYER_D; | ||
m_uvRect.height /= 2; | ||
m_uvRect.left = m_uvRect.width * m_current; | ||
m_sprite.setTextureRect(m_uvRect); | ||
m_uvRect.height *= 2; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void Animation::fireFunc() | ||
{ | ||
m_current = PLAYER_FIRE; | ||
m_uvRect.left = m_uvRect.width * m_current; | ||
m_sprite.setTextureRect(m_uvRect); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void Animation::standFunc() | ||
{ | ||
m_current = PLAYER_STAND; | ||
m_uvRect.left = m_uvRect.width * m_current; | ||
m_sprite.setTextureRect(m_uvRect); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void Animation::setDeadSprite() | ||
{ | ||
setDirection(LEFT); | ||
m_uvRect.left = std::abs(m_uvRect.width) * m_size; | ||
m_sprite.setTextureRect(m_uvRect); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// This function Handle the animation of a flag going down. | ||
void Animation::pullingFlag(sf::Time deltaTime) | ||
{ | ||
m_totalTime += deltaTime.asSeconds(); | ||
if (m_totalTime > SWITCH) | ||
{ | ||
m_totalTime -= SWITCH; | ||
m_current++; | ||
if (m_current > PULLING_PIC+1) | ||
m_current = PULLING_PIC; | ||
|
||
m_uvRect.left = m_uvRect.width * m_current; | ||
m_sprite.setTextureRect(m_uvRect); | ||
} | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
Animation::~Animation() | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "AudioHolder.h" | ||
|
||
AudioHolder::AudioHolder() | ||
{ | ||
// Uploading the audio from resources. | ||
m_tracks[AUDIO_KILL].loadFromFile("enemykill.wav"); | ||
m_tracks[AUDIO_JUMP].loadFromFile("jump.wav"); | ||
m_tracks[AUDIO_FIRE].loadFromFile("fireball.wav"); | ||
m_tracks[AUDIO_COIN].loadFromFile("coin.wav"); | ||
m_tracks[AUDIO_FINISH_STAGE].loadFromFile("poledown.wav"); | ||
m_tracks[AUDIO_LOST].loadFromFile("youlost.wav"); | ||
m_tracks[AUDIO_BUMP].loadFromFile("bump.wav"); | ||
m_tracks[AUDIO_PAUSE].loadFromFile("pause.wav"); | ||
m_tracks[AUDIO_DEATH].loadFromFile("death.wav"); | ||
m_tracks[AUDIO_BACKGROUND].loadFromFile("background.ogg"); | ||
m_tracks[AUDIO_SUPER].loadFromFile("supermushroom.wav"); | ||
m_tracks[AUDIO_WON].loadFromFile("won.wav"); | ||
|
||
m_sound[AUDIO_KILL].setBuffer(m_tracks[AUDIO_KILL]); | ||
m_sound[AUDIO_JUMP].setBuffer(m_tracks[AUDIO_JUMP]); | ||
m_sound[AUDIO_FIRE].setBuffer(m_tracks[AUDIO_FIRE]); | ||
m_sound[AUDIO_COIN].setBuffer(m_tracks[AUDIO_COIN]); | ||
m_sound[AUDIO_FINISH_STAGE].setBuffer(m_tracks[AUDIO_FINISH_STAGE]); | ||
m_sound[AUDIO_LOST].setBuffer(m_tracks[AUDIO_LOST]); | ||
m_sound[AUDIO_BUMP].setBuffer(m_tracks[AUDIO_BUMP]); | ||
m_sound[AUDIO_PAUSE].setBuffer(m_tracks[AUDIO_PAUSE]); | ||
m_sound[AUDIO_DEATH].setBuffer(m_tracks[AUDIO_DEATH]); | ||
m_sound[AUDIO_BACKGROUND].setBuffer(m_tracks[AUDIO_BACKGROUND]); | ||
m_sound[AUDIO_SUPER].setBuffer(m_tracks[AUDIO_SUPER]); | ||
m_sound[AUDIO_WON].setBuffer(m_tracks[AUDIO_WON]); | ||
|
||
m_sound[AUDIO_BACKGROUND].setLoop(true); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void AudioHolder::playSound(int element) | ||
{ | ||
m_sound[element].play(); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void AudioHolder::stopBGSound() | ||
{ | ||
m_sound[AUDIO_BACKGROUND].pause(); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
AudioHolder& AudioHolder::instance() | ||
{ | ||
static AudioHolder instance; | ||
return instance; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
AudioHolder :: ~AudioHolder() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "BadMushroom.h" | ||
|
||
BadMushroom::BadMushroom(int row, int col) | ||
: Enemy(TextureHolder::instance().getEnemy(I_BADMUSHROOM), LEFT, BAD_MUSH_SIZE, row ,col) | ||
{ | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void BadMushroom::move(sf::Time deltaTime) | ||
{ | ||
if (!m_dead) | ||
{ | ||
sideMove(deltaTime, ENEMY_SPEED); | ||
m_animation.staticShift(deltaTime, SWITCH); | ||
m_animation.setDirection(m_dir); | ||
} | ||
else if (m_tortoiseKill) | ||
handleDeathTortoise(deltaTime); | ||
|
||
else | ||
handleDeath(deltaTime); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
BadMushroom::~BadMushroom() | ||
{ | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "Block.h" | ||
|
||
Block::Block(int row, int col) : UnPickable(row,col) | ||
{ | ||
m_sprite.setTexture(TextureHolder::instance().getTextures(BLOCK)); | ||
m_sprite.setScale(BLOCK_SCALE, BLOCK_SCALE); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
Block::~Block() | ||
{ | ||
} |
Oops, something went wrong.