PC VIEW
VR VIEW
Download Link
Code Snippets
-
class Particle {
PVector position;
PVector velocity;
PVector acceleration;
PVector size;
float lifespan;
//Constructs the particle
Particle() {
acceleration = new PVector(0.1, 0.1);
velocity = new PVector(0, 0);
position = new PVector(Character.characterPosition.x, Character.characterPosition.y+20);
size = new PVector(8, 8);
lifespan = 30.0;
}
//Whenever the character runs
void Run() {
Update();
ParticleUpdate();
draw();
}
void Update()
{
position.add(velocity);
lifespan -= 2.0;
}
//Creates the particles
void draw() {
stroke(100, lifespan);
fill(205, 190, 123);
ellipse(position.x, position.y, size.x, size.y);
}
//Here i write the boolean to delete the particle when its dead( <0)
boolean isDead() {
if (lifespan <= 0)
{
return true;
} else
{
return false;
}
}
//With particle update I check the direction where the player is watching and i add speed to the particle in the oposite way
void ParticleUpdate()
{
if (Character.moveUp == true)
{
velocity = new PVector(random(-2, 2), 1);
}
if (Character.moveDown == true)
{
velocity = new PVector(random(-2, 2), -1);
}
if (Character.moveLeft == true)
{
velocity = new PVector(1, random(-2, 2));
}
if (Character.moveRight == true)
{
velocity = new PVector(-1, random(-2, 2));
}
}
}
//Handles the particles
class ParticleSystem
{
//Creates ArrayList for the particles
ArrayList<Particle> particles = new ArrayList<Particle>();
int nParticles = 20;
ParticleSystem()
{
particles = new ArrayList<Particle>();
setup();
}
//Spawns particles
void setup()
{
Spawn();
}
//Checks if the player is using the hook. If true then there wil be no particles
void draw()
{
if (HookStatement.hooks == null || !HookStatement.hooks.hitWall)
{
if (particles.size() == 0)
{
Spawn();
}
for (int i = 0; i < particles.size(); i++)
{
Particle p = particles.get(i);
p.Run();
if (p.isDead())
{
particles.remove(i);
particles.add(new Particle());
}
}
} else
{
particles.clear();
}
}
void Spawn()
{
for (int i = 0; i < nParticles; i++)
{
particles.add(new Particle());
}
}
}
-
class Health
{
//Health var's
float health = 30;
float maxHealth = 30;
float rectWidth;
float rectHeight;
boolean death;
PVector pos = new PVector();
Timer timer = new Timer();
int showHitIndicatorTime = 200;
boolean showIndicator = false;
void draw(PVector HealthPosition)
{
if (showIndicator && timer.timePassed(showHitIndicatorTime))
{
showIndicator = false;
}
pos = HealthPosition;
//Change color
if (health <= 10)
{
fill(255, 0, 0);
} else if (health <= 20)
{
fill(255, 200, 0);
} else
{
fill(0, 255, 0);
}
//Draw bar
noStroke();
rectMode(CORNER);
// Get fraction 0->1 and multiply it by width of bar
float drawWidth = (health / maxHealth) * rectWidth;
rect(HealthPosition.x-rectWidth/2, HealthPosition.y - 30, drawWidth, rectHeight);
//Outline
stroke(0);
strokeWeight(2);
noFill();
rect(HealthPosition.x-rectWidth/2, HealthPosition.y - 30, rectWidth, rectHeight);
rectMode(CENTER);
strokeWeight(0);
}
//If something takes damage
void TakeDamage(int amount_of_dmg)
{
showIndicator = true;
timer.timer_reset();
health -= amount_of_dmg;
if (health < 1)
{
Death();
}
}
//Adds health
void GetHealth(int amount_health)
{
health += amount_health;
}
//Reset health
void ResetHealth()
{
health = maxHealth;
}
void Death()
{
}
}
-
class Bullet
{
PVector bulletPosition = new PVector();
PVector bulletVelocity = new PVector();
float bulletDmg = 5;
PImage sprites = new PImage();
int direction = 1; // 0=up 1=down 2=left 3=right
final float bulletSpeed = 7f;
Bullet(float startX, float startY, int direction)
{
//Starting variables
bulletPosition.x = startX;
bulletPosition.y = startY;
this.direction = direction;
//Changes bullet speed according on direction
if (direction == 0)
{
bulletVelocity.y = -bulletSpeed;
}
else if (direction == 1)
{
bulletVelocity.y = bulletSpeed;
}
else if (direction == 2)
{
bulletVelocity.x = -bulletSpeed;
}
else if (direction == 3)
{
bulletVelocity.x = bulletSpeed;
}
else if (direction == 4)
{
bulletVelocity.x = -bulletSpeed;
bulletVelocity.y = -bulletSpeed;
}
else if (direction == 5)
{
bulletVelocity.x = bulletSpeed;
bulletVelocity.x = bulletSpeed;
bulletVelocity.y = -bulletSpeed;
}
else if (direction == 6)
{
bulletVelocity.x = bulletSpeed;
bulletVelocity.x = -bulletSpeed;
bulletVelocity.y = bulletSpeed;
}
else if (direction == 7)
{
bulletVelocity.x = bulletSpeed;
bulletVelocity.x = bulletSpeed;
bulletVelocity.y = bulletSpeed;
}
sprites = loadImage("images/Bullet.png");
}
void draw()
{
//Show the image based on the direction using the array
image(sprites, bulletPosition.x + Screenshake.shakeValue.x, bulletPosition.y + Screenshake.shakeValue.y);
// Add velocity to position
bulletPosition.x += bulletVelocity.x;
bulletPosition.y += bulletVelocity.y;
}
}
Gameplay.
This is a game play of an old version of the game. After this we did a little more polish and added some nice effects to make it more fun.