PImage bow;
PImage arrow;
PImage target;
PImage back;
float x = 0;
float y = 0;
float vx = 1;
float vy = 1;
float xx;
float yy;
boolean firing = false;
float arrowx = 0;
float arrowy = 0;
float arrowvx, arrowvy;
float mousex = 0;
float mousey = 0;
int shotsfired;
int numberhit;
int timer = 0;
boolean gameOver=false;
void setup () {
size (1120, 700);
bow = loadImage ("http://i.imgur.com/aUxxcyZ.png");
arrow = loadImage("http://hydra-media.cursecdn.com/skyrim.gamepedia.com/thumb/5/56/NordHeroArrow.png/200px-NordHeroArrow.png?version=6aa26de4a7d9bed40d0f2e9fd722af57");
target = loadImage("http://images.uesp.net/thumb/7/71/SR-icon-construction-Archery_Target.png/120px-SR-icon-construction-Archery_Target.png");
back = loadImage("http://i.imgur.com/QVU3ssu.jpg");
changeTarget();
}
void draw() {
// println(firing);
imageMode (CENTER);
image(back,width/2,height/2);
textSize(30);
fill(255);
text("Shots Fired :" + shotsfired, 30, 40);
textSize(30);
fill(255);
text("Shots Hit :" + numberhit, 30, 80);
image(target, xx, yy);
text((float)30-(float)timer/60, 20, 110);
if (timer>=1800) {
gameOver=true;
}
if (gameOver) {
textSize(30);
fill(255);
text("GAME OVER!", 500, 330);
textSize(30);
fill(255);
text("YOUR RATIO:", 495, 360);
textSize(30);
fill(255);
text(numberhit*1.0/shotsfired*1.0, 525, 390);
textSize(15);
fill(255);
text("Press a Key to Restart", 500, 420);
} else {
timer++;
x=mouseX;
y=mouseY;
if (x>=120) {
x = 119;
}
pushMatrix();
translate(x, y);
rotate(215*PI/180);
scale(.5);
image(bow, 0, 0);
popMatrix();
if (firing == false) {
pushMatrix();
translate(x, y);
rotate(atan2(arrowvy, arrowvx)+115*PI/180);
scale(.5);
image(arrow, 0, 0);
popMatrix();
} else {
if (arrowx<width || arrowy>height) {
arrowx+= arrowvx;
arrowy += arrowvy;
arrowvy += .1;
if (dist(arrowx, arrowy, xx, yy)<=15) {
changeTarget();
firing = false;
numberhit++;
}
pushMatrix();
translate(arrowx, arrowy);
rotate(atan2(arrowvy, arrowvx)+130*PI/180);
scale(.5);
image(arrow, 0, 0);
popMatrix();
} else {
firing = false;
arrowvy = 0;
}
}
}
}
void mousePressed () {
if (gameOver==false) {
firing = !false;
shotsfired++;
mousex=mouseX;
mousey = mouseY;
arrowvy = -5;
arrowx = mouseX;
arrowy = mouseY;
arrowvx = 12;
if (arrowx>=120) {
arrowx = 119;
}
}
}
void changeTarget() {
xx=random(500, 1120);
yy=random(300, 500);
}
void keyPressed() {
if (gameOver) {
x = 0;
y = 0;
firing = false;
mousex = 0;
mousey = 0;
shotsfired = 0;
numberhit = 0;
timer = 0;
xx = 0;
yy = 0;
changeTarget();
gameOver=false;
}
}