PImage background;
PImage bow;
PImage arrow;
float startx = 100;
float starty = 300;
float x = startx;
float y = starty;
float yvel = -10;
float xvel = 0;
float grav = 0.2;
int lastShot = 0;
int score = 0;
int shots = 0;
void setup(){
size(600,400);
background = loadImage("https://static-content-1301607230.cos.na-ashburn.myqcloud.com/images/Fun3a/fantasy-bg.jpg");
bow = loadImage("https://www.freeiconspng.com/thumbs/bow-and-arrow-png/bow-and-arrow-png-transparent--1.png");
arrow = loadImage("https://cdn4.iconfinder.com/data/icons/archery-2/500/yul284_13_flying_arrow_logo_silhouette_sport_vintage_bow-512.png");
textSize(20);
}
void draw(){
background(100);
image(background,0,0,width,height);
fill(255,255,255);
noStroke();
// ellipse(x,y,10,10);
image(arrow, x, y, 20, 20);
x = x + xvel;
y = y + yvel;
yvel = yvel + grav;
text("last shot: " + lastShot,50,70);
text("score: " + score,50,100);
text("shots: " + shots,50,130);
drawTarget();
if(x > width){
lastShot = (int)(height/2 - abs(y-(height/2)));
score = score + lastShot;
x = -500;
xvel = 0;
}
image(bow, startx-50, starty - 50, 100, 100);
drawArc();
}
void mousePressed(){
x = startx;
y = starty;
yvel = (mouseY - starty)*0.05;
xvel = (mouseX - startx)*0.05;
shots += 1;
}
void drawArc(){
float yvel2 = (mouseY - starty)*0.05;
float xvel2 = (mouseX - startx)*0.05;
float x2 = startx;
float y2 = starty;
strokeWeight(5);
stroke(0,255,0);
for(int i = 0; i < 10; i++){
point(x2,y2);
x2 += xvel2*2;
y2 += yvel2*2;
yvel2 += grav*2;
}
}
void drawTarget() {
fill(255,0,0);
ellipse(width-200,height/2,40,40);
fill(255);
ellipse(width-200, height/2,30,30);
fill(255,0,0);
ellipse(width-200,height/2,20,20);
fill(255);
ellipse(width-200,height/2, 10, 10);
}