Last active
January 29, 2017 01:59
-
-
Save Siunami/536fd843f42e1ba6d02f7b41868ffc4c to your computer and use it in GitHub Desktop.
Processing Sketch
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
public class Shooter { | |
float x; | |
float y; | |
color colour = color(random(0,255), random(0,255), random(0,255)); | |
float xspeed = random(-10,10); | |
float yspeed = random(-10,10); | |
Shooter(float x, float y) { | |
this.x = x; | |
this.y = y; | |
} | |
void updatePosition() { | |
if ((this.x + this.xspeed) > width){ | |
this.x = this.x + this.xspeed - width; | |
} else if ((this.x + this.xspeed) < 0){ | |
this.x = this.x + this.xspeed + width; | |
} else { | |
this.x += this.xspeed; | |
} | |
if ((this.y + this.yspeed) > height){ | |
this.y = this.y + this.yspeed - height; | |
} else if ((this.y + this.yspeed) < 0){ | |
this.y = this.y + this.yspeed + height; | |
} else { | |
this.y += this.yspeed; | |
} | |
} | |
void displayShooter(){ | |
fill(this.colour); | |
ellipse(this.x, this.y, 5, 5); | |
} | |
} | |
ArrayList<Shooter> objects = new ArrayList<Shooter>(); | |
void setup(){ | |
size(800,600); | |
background(255); | |
} | |
void draw(){ | |
background(255); | |
noStroke(); | |
objects.add(new Shooter(mouseX, mouseY)); | |
for(int i = 0; i < objects.size(); i++){ | |
objects.get(i).displayShooter(); | |
objects.get(i).updatePosition(); | |
} | |
// Manages how many objects are on the screen to avoid lag | |
if (objects.size() > 60){ | |
objects.remove(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment