Skip to content

Commit

Permalink
Add new menu background, attack animation, tiles, etc. fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgebaptista committed Mar 9, 2022
1 parent f3526da commit fad9251
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 11 deletions.
26 changes: 26 additions & 0 deletions can-you-survive/Enemy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,32 @@ void Enemy::Movement(float elapsedTime, float totalTime, Vector2f mapBounds)
}
}

if (m_attacked)
{
m_attackAnimTimer += elapsedTime;

if (m_attackAnimTimer > 0.1)
{
// if rect is at the right most of the sprite sheet stop animation and reset
if (rectSourceAttack.left == 320)
{
rectSourceAttack.left = 0;
m_attacked = false;
}
// else just jump to the right one
else rectSourceAttack.left += 64;

// set the sprite to the correct texture and rect properties
m_AttackedSprite = Sprite(m_AttackedTexture, rectSourceAttack);

// set the animate timer back to 0
m_attackAnimTimer = 0;

m_AttackedSprite.setPosition(m_Position);
m_AttackedSprite.setOrigin(32, 32);
}
}

//Depending on number, change position


Expand Down
2 changes: 1 addition & 1 deletion can-you-survive/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ void Engine::run()
// chance to spawn on this tile
if ((rand() % 20) >= 18)
{
for (iterSF = lpSeaFish.begin(); iterSF != lpSeaFish.end(); ++iterSF)
for (iterSF = lpSeaFish.begin(); iterSF != lpSeaFish.end(); iterSF++)
{
if (!((*iterSF)->getActive()))
{
Expand Down
3 changes: 3 additions & 0 deletions can-you-survive/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class Engine
Color blackoutCDarken;
Color blackoutCLighten;

Texture backgroundTexture;
Sprite background;

Font font;

// Text for MENU m_State
Expand Down
14 changes: 6 additions & 8 deletions can-you-survive/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ void Engine::input()
{
playText.setString(aboutStream.str());
select = true;
playText.setPosition(100, 100);
playText.setPosition(500, 100);
playText.setCharacterSize(25);
}
if (Keyboard::isKeyPressed(Keyboard::Num3) && select == false)
{
playText.setString(instructionsStream.str());
select = true;
playText.setPosition(100, 100);
playText.setPosition(500, 100);
playText.setCharacterSize(35);
}
if (Keyboard::isKeyPressed(Keyboard::Num4) && select == false) {
playText.setString(referenceStream.str());
select = true;
playText.setPosition(100, 100);
playText.setPosition(500, 100);
playText.setCharacterSize(25);
}
if (Keyboard::isKeyPressed(Keyboard::Num5) && select == false) {
Expand Down Expand Up @@ -228,12 +228,10 @@ void Engine::input()
pause = true;

// Reset all sea fish
for (iterSF = lpSeaFish.begin(); iterSF != lpSeaFish.end(); ++iterSF)
for (iterSF = lpSeaFish.begin(); iterSF != lpSeaFish.end(); iterSF++)
{
if ((*iterSF)->getActive())
{
(*iterSF)->setActive(false);
}
(*iterSF)->setActive(false);
(*iterSF)->setPosition(-1000, -1000);
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions can-you-survive/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,32 @@ void Player::Movement(float elapsedTime, float totalTime, Vector2f mapBounds)
}
}

if (m_attacked)
{
m_attackAnimTimer += elapsedTime;

if (m_attackAnimTimer > 0.1)
{
// if rect is at the right most of the sprite sheet stop animation and reset
if (rectSourceAttack.left == 320)
{
rectSourceAttack.left = 0;
m_attacked = false;
}
// else just jump to the right one
else rectSourceAttack.left += 64;

// set the sprite to the correct texture and rect properties
m_AttackedSprite = Sprite(m_AttackedTexture, rectSourceAttack);

// set the animate timer back to 0
m_attackAnimTimer = 0;

m_AttackedSprite.setPosition(m_Position);
m_AttackedSprite.setOrigin(32, 32);
}
}

// set origin and position
m_Sprite.setOrigin(32, 32);
m_Sprite.setPosition(m_Position);
Expand Down
19 changes: 19 additions & 0 deletions can-you-survive/PolarBear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ PolarBear::PolarBear(Vector2f position)

moveTime = 0;
m_damage = 5;

m_AttackedTexture.loadFromFile("graphics/attack.png");
rectSourceAttack = sf::IntRect(0, 0, 64, 64);
m_AttackedSprite = Sprite(m_AttackedTexture, rectSourceAttack);
m_AttackedSprite.setOrigin(32, 32);

m_attacked = false;
m_attackAnimTimer = 0;
}

//Used to spawn new polarbear when they die
Expand Down Expand Up @@ -47,6 +55,7 @@ int PolarBear::Attack()
void PolarBear::ReduceHealth(int reduce)
{
health = health - reduce;
m_attacked = true;
}

//Return the global bounds of the polar bear
Expand All @@ -67,6 +76,16 @@ Sprite PolarBear::getSprite()
return m_Sprite;
}

Sprite PolarBear::getAttackedSprite()
{
return m_AttackedSprite;
}

bool PolarBear::isAttacked()
{
return m_attacked;
}

//Check if alive and if not
bool PolarBear::isAlive()
{
Expand Down
13 changes: 13 additions & 0 deletions can-you-survive/PolarBear.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class PolarBear
//Returns the sprite
Sprite getSprite();

Sprite getAttackedSprite();

bool isAttacked();

//Will return health
int getHealth();

Expand Down Expand Up @@ -78,5 +82,14 @@ class PolarBear

// control animation speed
float m_animateTimer;

// Control attacked animation

Texture m_AttackedTexture;
Sprite m_AttackedSprite;
IntRect rectSourceAttack;

bool m_attacked;
float m_attackAnimTimer;
};
#endif
8 changes: 6 additions & 2 deletions can-you-survive/SetupUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ void Engine::setupUI()
blackoutS.setTexture(blackoutT);
blackoutS.scale(4.0, 4.0);

backgroundTexture.loadFromFile("graphics/menu.png");
background.setTexture(backgroundTexture);
background.setPosition(0, 0);

//All the text used for the game
font.loadFromFile("fonts/KOMIKAP_.ttf");

Expand Down Expand Up @@ -49,11 +53,11 @@ void Engine::setupUI()
"\nJorge Baptista" <<
"\n" <<
"\n Artist:" <<
"\n Isabelle Rellinghaus";
"\n Isabell Rellinghaus";
playText.setString(playStream.str());
playText.setCharacterSize(75);
playText.setFillColor(Color::White);
playText.setPosition(550, 400);
playText.setPosition(700, 400);

//introText font
introText.setFont(font);
Expand Down
6 changes: 6 additions & 0 deletions can-you-survive/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ void Engine::draw()
{
m_Window.clear(Color(0, 0, 0)); // clear the m_Window
m_Window.setView(m_HudView);
m_Window.draw(background);
m_Window.draw(playText);

}
Expand Down Expand Up @@ -36,6 +37,11 @@ void Engine::draw()
for (iter = lpPolarBears.begin(); iter != lpPolarBears.end(); ++iter)
{
m_Window.draw((*iter)->getSprite());

if ((*iter)->isAttacked())
{
m_Window.draw((*iter)->getAttackedSprite());
}
}

// Iterate through the fish list and draw each fish
Expand Down
Binary file added can-you-survive/graphics/attack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified can-you-survive/graphics/ice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added can-you-survive/graphics/menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed can-you-survive/graphics/polar.png
Binary file not shown.
Binary file removed can-you-survive/graphics/polarflip.png
Binary file not shown.
Binary file modified can-you-survive/graphics/water.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fad9251

Please sign in to comment.