//--------------------------------------------//
//Sebastian Santamaura's Object-Oriented Toy
//Battle Blades
//"Fight to the death!"
//October 22nd, 2016
//CONTROLS:
//Click on a blade to pick it up
//place it by clicking over the arena
//Press SPACE to heal all blades
//***Inspired by BeyBlade*****
//Shoutout to Ashwin Kamath for assistance
//-------------------------------------------//
//Initialize objects
Dirt[] dir = new Dirt[500];
Stabby stab=new Stabby();
Cutter cut=new Cutter();
//Vecors for blades
PVector Rloc=new PVector();
PVector Bloc=new PVector();
//setup
void setup()
{
size(400, 400);
frameRate(60);
textSize(20);
rectMode(CENTER);
//predetermine the location of dirt
for (int a=0; a<500; a+=5)
{
dir[a]= new Dirt();
}
}
//draw
void draw()
{
//create Arena
background(224, 165, 45);
noStroke();
//choosing grounds
fill(222, 49, 22);
rect(200, 350, 400, 100);
//Dirty up arena
for (int i=0; i<500; i+=10)
{
dir[i].display();
}
//Call functions for Stabby
stab.display();
stab.pickStabby();
stab.stabbyMouse();
stab.placeStabby(stab.spawnStabbyX(), stab.spawnStabbyY());
stab.move();
//Call functions for Cutter
cut.display();
cut.pickCutter();
cut.cutterMouse();
cut.placeCutter(cut.spawnCutterX(), cut.spawnCutterY());
cut.move();
//Determines if blades are close enough to do damage
Rloc=stab.location();
Bloc=cut.location();
if (dist(Rloc.x, Rloc.y, Bloc.x, Bloc.y)<50)
{
//next best thing to actual noise
System.out.println("CLANG!");
//Stabby takes a hit
cut.defend(stab.attack());
//Cutter gets pierced
stab.defend(cut.attack());
}
}
//"Let it Rip!!!"//"In this Corner, Weighing in at 7 pounds, IS..."
class Cutter
{
//Position
PVector pos=new PVector();
//Velocity
PVector vel=new PVector();
//Booleans for battling
boolean pickedUp=false;
boolean alive=false;
boolean hit=false;
//figuring out placements
float tempPosX;
float tempPosY;
//health
int health = 200;
//Damage Dealt
float dmgDealt;
//This is to draw Cutter
void make(float posX, float posY)
{
fill(0, 0, 180);
noStroke();
ellipseMode(CENTER);
//Blades
triangle(posX-20, posY-40, posX+5, posY-35, posX, posY);
triangle(posX+40, posY-20, posX+35, posY+5, posX, posY);
triangle(posX+20, posY+40, posX-5, posY+35, posX, posY);
triangle(posX-40, posY+20, posX-35, posY-5, posX, posY);
ellipse(posX, posY, 50, 50);
fill(60);
ellipse(posX, posY, 30, 30);
fill(0, 0, 180);
ellipse(posX, posY, 20, 20);
fill(255);
//show user who's winning
text("HP:"+health, 270, 320);
}
//Shows Cutter to user
void display()
{
make(300, 350);
//If Cutter loses all health, it disappears
if (health <=0)
{
pos.x=100;
pos.y=500;
alive=false;
}
if (health>0&&alive==true)
{
make(pos.x, pos.y);
}
//resets Cutter's health
if (keyPressed)
{
if (key==' ')
{
health=200;
}
}
}
//Cutter's movement
void move()
{
if (alive==true)
{
pos.x+=vel.x;
pos.y+=vel.y;
}
//Wall Collision
if (pos.x>=375||pos.x<=25)
{
vel.x *= -1;
}
if (pos.y>=275||pos.y<=25)
{
vel.y *= -1;
}
}
//Credit to Jessica Olesky's Sweet Tea
//Picking up Cutter
void pickCutter()
{
//If the mouse is above Cutter, the user can pick up Cutter
if ((mouseX>275)&&(mouseX<325)&&(mouseY<375)&&(mouseY>325)&&(mousePressed==true)&&(pickedUp==false)&&(alive==false))
{
pickedUp= true;
}
}
//When Cutter is picked up, it is on mouse's position
void cutterMouse()
{
if (pickedUp==true)
{
make(mouseX, mouseY);
}
}
//places Cutter down on the mouse's position, and says it is "alive"
boolean placeCutter(float posX, float posY)
{
if ((pickedUp==true)&&(mouseY<300)&&(mousePressed))
{
pickedUp= false;
alive=true;
health=200;
pos.x=300;
pos.y=200;
vel.x=random(5, 9);
vel.y=vel.x/2;
}
return alive;
}
//help calculating mouseX position
float spawnCutterX()
{
if (alive==true)
{
tempPosX=mouseX;
}
return tempPosX;
}
//help calculating mouseY position
float spawnCutterY()
{
if (alive==true)
{
tempPosY=mouseY;
}
return tempPosY;
}
//When Cutter is attacked by Stabby
void defend(float hitTaken)
{
health-=hitTaken;
hit=true;
}
//When Cutter attacks Stabby
float attack()
{
if (hit==true)
{
dmgDealt=random(1, 5);
hit=false;
}
return dmgDealt;
}
//returns Cutter's location
PVector location()
{
return pos;
}
}//Ads some sort of aesthetic to the arena
class Dirt
{
PVector pos=new PVector(random(0, 400), random(0, 300));
float posX;
float posY;
float posX2;
float posY2;
//basically just a random assortment of short lines
Dirt()
{
posX=pos.x;
posY=pos.y;
posX2=pos.x+random(-5, 5);
posY2=pos.y+random(-5, 5);
}
//"This arena has seen much battle..."
void display()
{
stroke(95, 55, 5);
strokeWeight(1);
line(posX, posY, posX2, posY2);
}
}//"And in this Corner, three time CHAMPION, we have..."
class Stabby
{
//default postion
PVector pos=new PVector(100, 350);
//velocity
PVector vel=new PVector();
//booleans for lyf
boolean pickedUp=false;
boolean alive=false;
boolean hit=false;
//health
int health = 200;
//Temporary positions
float tempPosX;
float tempPosY;
//Damage
float dmgDealt;
//"Draw function"
void make(float posX, float posY)
{
fill(165, 0, 0);
noStroke();
ellipseMode(CENTER);
//Spikes
triangle(posX, posY-40, posX-5, posY-20, posX+5, posY-20);
triangle(posX+40, posY, posX+20, posY+5, posX+20, posY-5);
triangle(posX, posY+40, posX-5, posY+20, posX+5, posY+20);
triangle(posX-40, posY, posX-20, posY+5, posX-20, posY-5);
triangle(posX+30, posY-30, posX+9, posY+9, posX-10, posY-10);
triangle(posX-30, posY+30, posX-10, posY-10, posX-10, posY+20);
triangle(posX+30, posY+30, posX+10, posY-5, posX-5, posY+10);
triangle(posX-30, posY-30, posX, posY-12, posX-12, posY);
ellipse(posX, posY, 50, 50);
stroke(200);
strokeWeight(3);
line(posX-20, posY, posX+20, posY);
line(posX, posY-20, posX, posY+20);
fill(255);
//"Legend says Stabby is immortal..."
text("HP:"+health, 70, 320);
}
//Shows Stabby to the audience
void display()
{
make(100, 350);
//"In all my years, I have never seen Stabby break a spike..."
if (health <=0)
{
pos.x=300;
pos.y=500;
alive=false;
}
if (health>0&&alive==true)
{
make(pos.x, pos.y);
}
//resets health
if (keyPressed)
{
if (key==' ')
{
health=200;
}
}
}
//Stabby's unpredictable moveset
void move()
{
if (alive==true)
{
pos.add(vel);
//Wall Collision
if (pos.x>=375||pos.x<=25)
{
vel.x *= -1;
}
if (pos.y>=275||pos.y<=25)
{
vel.y *= -1;
}
}
}
//I know that Stabby and Cutter are similar, but I have been swamped with work this week
//It is ill-advised to pick up Stabby
void pickStabby()
{
if ((mouseX>75)&&(mouseX<125)&&(mouseY<375)&&(mouseY>325)&&(mousePressed==true)&&(pickedUp==false)&&(alive==false))
{
pickedUp= true;
}
}
//Stabby is picked up
void stabbyMouse()
{
if (pickedUp==true)
{
make(mouseX, mouseY);
}
}
//drop it like it's spiky
boolean placeStabby(float posX, float posY)
{
if ((pickedUp==true)&&(mouseY<300)&&(mousePressed))
{
pickedUp=false;
alive=true;
health=200;
pos.x=100;
pos.y=200;
vel.x=random(5, 9);
vel.y=vel.x/2;
}
return alive;
}
//This was a challenge
float spawnStabbyX()
{
if (alive==true)
{
int s=800-mouseX;
tempPosX=800-s;
}
return tempPosX;
}
float spawnStabbyY()
{
if (alive==true)
{
int a=800-mouseY;
tempPosY=800-a;
}
return tempPosY;
}
//"Stabby can defend himself by attacking"
void defend(float hitTaken)
{
health-=hitTaken;
hit=true;
}
//"the best defence is a good offence"
float attack()
{
if (hit==true)
{
dmgDealt=random(1, 5);
hit=false;
}
return dmgDealt;
}
//ping location
PVector location()
{
return pos;
}
}