Created
April 5, 2016 19:32
-
-
Save chasestarr/aaad4776913433a342d8cf8f8110436d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Geo { | |
PVector location, speed, acceleration; | |
Geo[] theArray; | |
Geo(PVector loc, PVector spd, Geo[] myArray) { | |
location = loc; | |
speed = spd; | |
theArray = myArray; | |
} | |
void run() { | |
display(); | |
move(); | |
bounds(); | |
mouser(); | |
collision(); | |
} | |
void display() { | |
triangle(location.x-10, location.y-10, location.x+20, location.y-20, location.x+20, location.y+20); | |
} | |
void move() { | |
location.add(speed); | |
} | |
void bounds() { | |
if (location.x > width || location.x < 0) { | |
speed.x = speed.x * -1; | |
move(); | |
} | |
if (location.y > height || location.y < 0) { | |
speed.y = speed.y * -1; | |
move(); | |
} | |
} | |
void mouser() { | |
if (mousePressed == true) { | |
PVector mouse = new PVector(mouseX, mouseY); | |
PVector direction = PVector.sub(mouse, location); | |
direction.normalize(); | |
direction.mult(.5); | |
acceleration = direction; | |
speed.add(acceleration); | |
speed.limit(2); | |
location.add(speed); | |
} | |
} | |
public PVector getLocation() { | |
return location; | |
} | |
void collision() { | |
for (int i = 0; i < theArray.length; i++) { | |
float distance = PVector.dist(this.getLocation(), theArray[i].getLocation()); | |
if (distance < 20 && theArray[i] != this) { | |
speed.x = speed.x * -1; | |
speed.y = speed.y * -1; | |
move(); | |
move(); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Inch { | |
PVector location, speed, acceleration; | |
Inch[] theArray; | |
Inch(PVector loc, PVector spd, Inch[] myArray) { | |
location = loc; | |
speed = spd; | |
theArray = myArray; | |
} | |
void run() { | |
display(); | |
move(); | |
bounds(); | |
mouser(); | |
collision(); | |
} | |
void display() { | |
rect(location.x, location.y, 70,5); | |
} | |
void move() { | |
location.add(speed); | |
} | |
void bounds() { | |
if (location.x > width || location.x < 0) { | |
speed.x = speed.x * -1; | |
move(); | |
} | |
if (location.y > height || location.y < 0) { | |
speed.y = speed.y * -1; | |
move(); | |
} | |
} | |
void mouser() { | |
if (mousePressed == true) { | |
PVector mouse = new PVector(mouseX, mouseY); | |
PVector direction = PVector.sub(mouse, location); | |
direction.normalize(); | |
direction.mult(.5); | |
acceleration = direction; | |
speed.add(acceleration); | |
speed.limit(2); | |
location.add(speed); | |
} | |
} | |
public PVector getLocation() { | |
return location; | |
} | |
void collision() { | |
for (int i = 0; i < theArray.length; i++) { | |
float distance = PVector.dist(this.getLocation(), theArray[i].getLocation()); | |
if (distance < 20 && theArray[i] != this) { | |
speed.x = speed.x * -1; | |
speed.y = speed.y * -1; | |
move(); | |
move(); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Jelly { | |
PVector location, speed, acceleration; | |
Jelly[] theArray; | |
Jelly(PVector loc, PVector spd, Jelly[] myArray) { | |
location = loc; | |
acceleration = new PVector(0,0); | |
speed = spd; | |
theArray = myArray; | |
} | |
void run() { | |
display(); | |
move(); | |
bounds(); | |
mouser(); | |
collision(); | |
} | |
void display() { | |
ellipse(location.x, location.y, random(20,40),random(20,40)); | |
} | |
void move() { | |
location.add(speed); | |
} | |
void applyForce(PVector force){ | |
int mass = 1; | |
PVector f = PVector.div(force,mass); | |
acceleration.add(f); | |
} | |
void bounds() { | |
if (location.x > width || location.x < 0) { | |
speed.x = speed.x * -1; | |
move(); | |
} | |
if (location.y > height || location.y < 0) { | |
speed.y = speed.y * -1; | |
move(); | |
} | |
} | |
void mouser() { | |
if (mousePressed == true) { | |
PVector mouse = new PVector(mouseX, mouseY); | |
PVector direction = PVector.sub(mouse, location); | |
direction.normalize(); | |
direction.mult(.5); | |
acceleration = direction; | |
speed.add(acceleration); | |
speed.limit(5); | |
location.add(speed); | |
} | |
} | |
public PVector getLocation() { | |
return location; | |
} | |
void collision() { | |
for (int i = 0; i < theArray.length; i++) { | |
float distance = PVector.dist(this.getLocation(), theArray[i].getLocation()); | |
if (distance < 20 && theArray[i] != this) { | |
speed.x = speed.x * -1; | |
speed.y = speed.y * -1; | |
move(); | |
move(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment