Skip to content

Instantly share code, notes, and snippets.

@FreedomGrenade
Created October 17, 2014 01:26
Show Gist options
  • Save FreedomGrenade/16284a55a1b05ae50b3a to your computer and use it in GitHub Desktop.
Save FreedomGrenade/16284a55a1b05ae50b3a to your computer and use it in GitHub Desktop.
import java.util.*;
ArrayList<Bullet> bullets = new ArrayList<Bullet>();
int bulletDelay = 200;
int lastShot = millis();
void setup() {
size(400, 400);
colorMode(HSB, 360, 100, 100, 100);
}
void draw() {
float y = mouseY;
float rectfill = map(mouseX, 0, width, 0, 150); //fill of bar
background(0, 0, 100);
noCursor();
noFill();
strokeWeight(3);//thickerrectangle
rectMode(CENTER);
rect(width/2, 20, 150, 20);
rectMode(CORNER);
fill(360, 0, 0);
rect(125, 10, rectfill, 17);
strokeWeight(5);
fill(0, 0, 100);
ellipse(50, y, 50, 50);//body
fill(0, 0, 0);
arc(50, y+14, 18, 16, radians(-180), radians(0));//tounge
noFill();
ellipse(50, y + 7, 36, 16);//mouth
fill(0, 0, 100);
arc(38, y + 28, 21, 21, radians(-180), radians(0), PIE);//left eye
arc(64, y + 28, 21, 21, radians(-180), radians(0), PIE);//right eye
fill(0, 0, 0);//eyefill
ellipse(45, y - 10, 7.5, 7.5);//left eye
ellipse(65, y - 10, 7.5, 7.5);//right eye
//bullet
if (mouseButton == LEFT && (millis() - lastShot) > bulletDelay) {
bullets.add(new Bullet(50, y+10, map(mouseX,0,width,1,8)));
lastShot = millis();
}
bulletStuff();
}
public void bulletStuff() {
Iterator<Bullet> i = bullets.listIterator();
while (i.hasNext()) {
Bullet b = i.next();
b.draw();
if (b.update()) i.remove();
}
println(bullets.size());
}
public class Bullet {
float x;
float y;
float accel;
public Bullet(float x, float y, float accel) {
this.x = x;
this.y = y;
this.accel = accel;
}
public boolean update() {
x+=accel;
if (x >= width + 5 || x<= -5) return true;
return false;
}
public void draw() {
fill(312, 53, 99);
ellipse(x,y,5,5);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment