Commit ee4234a3 authored by alaskalinuxuser's avatar alaskalinuxuser
Browse files

JelloStorm: added poison, teleportation, and touched up game mechanics.

parent da3f7661
No preview for this file type
......@@ -85,6 +85,10 @@ FloatRect Jello::getPosition()
return m_Sprite.getGlobalBounds();
}
Vector2f Jello::getCoordPosition()
{
return m_Sprite.getPosition();
}
Sprite Jello::getSprite()
{
......@@ -92,7 +96,7 @@ Sprite Jello::getSprite()
}
void Jello::update(float elapsedTime,
Vector2f playerLocation)
Vector2f playerLocation, int specificJello, IntRect arena)
{
float playerX = playerLocation.x;
float playerY = playerLocation.y;
......@@ -121,6 +125,32 @@ void Jello::update(float elapsedTime,
m_Position.y = m_Position.y -
m_Speed * elapsedTime;
}
if (specificJello % 2 == 0) {
// Give the jello an opportunity to randomly teleport!
// The if statement checks if it is even number.
// If it is, do this:
// Find the min/max of the arena area
int maxY = arena.height - 50;
int minY = arena.top + 50;
int maxX = arena.width - 50;
int minX = arena.left + 50;
// Generate our random number
srand((int)time(0) * specificJello);
int side = (rand() % 10);
switch (side)
{
case 0:
// left
m_Position.x = (rand() % maxX) + minX;
m_Position.y = (rand() % maxY) + minY;
break;
}
}
// Move the sprite
m_Sprite.setPosition(m_Position);
......
......@@ -50,12 +50,16 @@ public:
// Return a rectangle that is the position in the world
FloatRect getPosition();
// Return coordinate position
Vector2f getCoordPosition();
// Get a copy of the sprite to draw
Sprite getSprite();
// Update the jello each frame
void update(float elapsedTime, Vector2f playerLocation);
void update(float elapsedTime, Vector2f playerLocation,
int specificJello, IntRect arena);
};
No preview for this file type
......@@ -3,6 +3,7 @@
#include <iostream>
#include <SFML/Audio.hpp>
#include <Player.h>
#include <Poison.h>
#include <JelloStorm.h>
#include <TextureHolder.h>
#include <Arrow.h>
......@@ -66,6 +67,9 @@ int main() {
int numJellosAlive;
Jello* jellos = nullptr;
// and Poison!
Poison* poison = nullptr;
// 100 Arrows should do
Arrow arrows[100];
int currentArrow = 0;
......@@ -142,7 +146,8 @@ int main() {
"\nD - Right" <<
"\nR - Reload quiver from inventory" <<
"\nEnter - Pause the game" <<
"\nMouse - Click to shoot";
"\nMouse - Left Click to shoot" <<
"\n - Right Click to reload";
gameOverText.setString(gameOverStream.str());
// Levelling up
......@@ -402,7 +407,7 @@ int main() {
player.stopRight();
}
// Fire an arrow
// Fire an arrow with mouse click.
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
......@@ -428,7 +433,7 @@ int main() {
arrowsInQuiver--;
}
}// End fire an arrow.
}// End fire an arrow.
}// End WASD while playing
......@@ -502,6 +507,15 @@ int main() {
// Delete the previously allocated memory (if it exists)
delete[] jellos;
jellos = createHorde(numJellos, arena);
delete[] poison;
poison = new Poison[numJellos];
for (int p = 0; p < numJellos; p++)
{
// Spawn the new jello into the array
poison[p].spawn(jellos[p].getCoordPosition());
}
numJellosAlive = numJellos;
......@@ -563,12 +577,22 @@ int main() {
{
if (jellos[i].isAlive())
{
jellos[i].update(dt.asSeconds(), playerPosition);
jellos[i].update(dt.asSeconds(), playerPosition,
i, arena);
// And update the poison ring.
poison[i].update(jellos[i].getCoordPosition());
// Used for debugging
// std::cout << i;
numJellosAlive++;
} else {
// Since the Jello is dead, remove it's poison ring.
Vector2f offVect;
offVect.x = -1000000;
offVect.y = -1000000;
poison[i].update(offVect);
}
}
......@@ -749,6 +773,7 @@ int main() {
for (int i = 0; i < numJellos; i++)
{
window.draw(jellos[i].getSprite());
window.draw(poison[i].getSprite());
}
// Draw the arrows.
......@@ -809,6 +834,7 @@ int main() {
for (int i = 0; i < numJellos; i++)
{
window.draw(jellos[i].getSprite());
window.draw(poison[i].getSprite());
}
// Draw the arrows.
......
No preview for this file type
#include <sstream>
#include <Poison.h>
#include <TextureHolder.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;
void Poison::spawn(Vector2f startVect)
{
m_Sprite = Sprite(TextureHolder::GetTexture(
"graphics/poison.png"));
m_Position = startVect;
m_Sprite.setOrigin(50, 50);
m_Sprite.setPosition(m_Position);
}
bool Poison::isVis()
{
return m_Vis;
}
FloatRect Poison::getPosition()
{
return m_Sprite.getGlobalBounds();
}
Sprite Poison::getSprite()
{
return m_Sprite;
}
void Poison::update(Vector2f updateVect)
{
m_Position = updateVect;
// Move the sprite
m_Sprite.setPosition(m_Position);
}
#pragma once
#include <SFML/Graphics.hpp>
#include <cmath>
using namespace sf;
class Poison {
private:
// Where is this Poison?
Vector2f m_Position;
// A sprite for the Poison
Sprite m_Sprite;
// Is it visable?
bool m_Vis = true;
// Public prototypes go here
public:
// Find out if the poison is visable
bool isVis();
// Spawn a new Poison
void spawn(Vector2f startVect);
// Return a rectangle that is the position in the world
FloatRect getPosition();
// Get a copy of the sprite to draw
Sprite getSprite();
// Update the poison each frame
void update(Vector2f updateVect);
};
......@@ -15,6 +15,7 @@
g++ -I./ -Wall -ansi -Wextra -g -c -std=c++14 TextureHolder.cpp -o TextureHolder.o
g++ -I./ -Wall -ansi -Wextra -g -c -std=c++14 Player.cpp -o Player.o
g++ -I./ -Wall -ansi -Wextra -g -c -std=c++14 Poison.cpp -o Poison.o
g++ -I./ -Wall -ansi -Wextra -g -c -std=c++14 Arrow.cpp -o Arrow.o
g++ -I./ -Wall -ansi -Wextra -g -c -std=c++14 Jello.cpp -o Jello.o
g++ -I./ -Wall -ansi -Wextra -g -c -std=c++14 Pickup.cpp -o Pickup.o
......@@ -23,7 +24,7 @@ g++ -I./ -Wall -ansi -Wextra -g -c -std=c++14 CreateHorde.cpp -o CreateHorde.o
g++ -I./ -Wall -ansi -Wextra -g -c -std=c++14 CreateBackground.cpp -o CreateBackground.o
g++ TextureHolder.o Player.o Arrow.o Jello.o Pickup.o JelloStorm.o CreateHorde.o CreateBackground.o -o JelloStorm-app -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio
g++ TextureHolder.o Player.o Poison.o Arrow.o Jello.o Pickup.o JelloStorm.o CreateHorde.o CreateBackground.o -o JelloStorm-app -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio
./JelloStorm-app
......
JelloStorm/graphics/blue_jello.png

9.51 KB | W: | H:

JelloStorm/graphics/blue_jello.png

5.18 KB | W: | H:

JelloStorm/graphics/blue_jello.png
JelloStorm/graphics/blue_jello.png
JelloStorm/graphics/blue_jello.png
JelloStorm/graphics/blue_jello.png
  • 2-up
  • Swipe
  • Onion skin
JelloStorm/graphics/green_jello.png

9.72 KB | W: | H:

JelloStorm/graphics/green_jello.png

5.14 KB | W: | H:

JelloStorm/graphics/green_jello.png
JelloStorm/graphics/green_jello.png
JelloStorm/graphics/green_jello.png
JelloStorm/graphics/green_jello.png
  • 2-up
  • Swipe
  • Onion skin
JelloStorm/graphics/red_jello.png

9.66 KB | W: | H:

JelloStorm/graphics/red_jello.png

5.03 KB | W: | H:

JelloStorm/graphics/red_jello.png
JelloStorm/graphics/red_jello.png
JelloStorm/graphics/red_jello.png
JelloStorm/graphics/red_jello.png
  • 2-up
  • Swipe
  • Onion skin
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment