diff --git a/can-you-survive/Enemy.cpp b/can-you-survive/Enemy.cpp index 9d9d3ff..151780c 100644 --- a/can-you-survive/Enemy.cpp +++ b/can-you-survive/Enemy.cpp @@ -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 diff --git a/can-you-survive/Engine.cpp b/can-you-survive/Engine.cpp index e09d22f..3937abe 100644 --- a/can-you-survive/Engine.cpp +++ b/can-you-survive/Engine.cpp @@ -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())) { diff --git a/can-you-survive/Engine.h b/can-you-survive/Engine.h index c39fe9c..8b67ebd 100644 --- a/can-you-survive/Engine.h +++ b/can-you-survive/Engine.h @@ -106,6 +106,9 @@ class Engine Color blackoutCDarken; Color blackoutCLighten; + Texture backgroundTexture; + Sprite background; + Font font; // Text for MENU m_State diff --git a/can-you-survive/Input.cpp b/can-you-survive/Input.cpp index 23ceb87..0e98e77 100644 --- a/can-you-survive/Input.cpp +++ b/can-you-survive/Input.cpp @@ -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) { @@ -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); } } } diff --git a/can-you-survive/Player.cpp b/can-you-survive/Player.cpp index 653f356..7f8a398 100644 --- a/can-you-survive/Player.cpp +++ b/can-you-survive/Player.cpp @@ -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); diff --git a/can-you-survive/PolarBear.cpp b/can-you-survive/PolarBear.cpp index f171663..b8c7311 100644 --- a/can-you-survive/PolarBear.cpp +++ b/can-you-survive/PolarBear.cpp @@ -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 @@ -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 @@ -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() { diff --git a/can-you-survive/PolarBear.h b/can-you-survive/PolarBear.h index d634bc6..9b3bf5d 100644 --- a/can-you-survive/PolarBear.h +++ b/can-you-survive/PolarBear.h @@ -29,6 +29,10 @@ class PolarBear //Returns the sprite Sprite getSprite(); + Sprite getAttackedSprite(); + + bool isAttacked(); + //Will return health int getHealth(); @@ -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 \ No newline at end of file diff --git a/can-you-survive/SetupUI.cpp b/can-you-survive/SetupUI.cpp index f078e7f..40c939d 100644 --- a/can-you-survive/SetupUI.cpp +++ b/can-you-survive/SetupUI.cpp @@ -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"); @@ -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); diff --git a/can-you-survive/draw.cpp b/can-you-survive/draw.cpp index 34c37dc..dd55cab 100644 --- a/can-you-survive/draw.cpp +++ b/can-you-survive/draw.cpp @@ -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); } @@ -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 diff --git a/can-you-survive/graphics/attack.png b/can-you-survive/graphics/attack.png new file mode 100644 index 0000000..2acd507 Binary files /dev/null and b/can-you-survive/graphics/attack.png differ diff --git a/can-you-survive/graphics/ice.png b/can-you-survive/graphics/ice.png index cc669fa..bf50120 100644 Binary files a/can-you-survive/graphics/ice.png and b/can-you-survive/graphics/ice.png differ diff --git a/can-you-survive/graphics/menu.png b/can-you-survive/graphics/menu.png new file mode 100644 index 0000000..055059f Binary files /dev/null and b/can-you-survive/graphics/menu.png differ diff --git a/can-you-survive/graphics/polar.png b/can-you-survive/graphics/polar.png deleted file mode 100644 index 77276af..0000000 Binary files a/can-you-survive/graphics/polar.png and /dev/null differ diff --git a/can-you-survive/graphics/polarflip.png b/can-you-survive/graphics/polarflip.png deleted file mode 100644 index fa33ae4..0000000 Binary files a/can-you-survive/graphics/polarflip.png and /dev/null differ diff --git a/can-you-survive/graphics/water.png b/can-you-survive/graphics/water.png index 15cec32..c7a022a 100644 Binary files a/can-you-survive/graphics/water.png and b/can-you-survive/graphics/water.png differ