xxxxxxxxxx
55
let velocity = 60;
let distance = 0;
let deceleration = 3;
let shooting = 0;
let range;
let test;
let angle = 30;
function setup() {
createCanvas(800, 800);
frameRate(60);
angleMode(DEGREES);
background(220);
range = pow(velocity - deceleration, 2) / (2 * deceleration);
noFill();
end = range / 90;
}
function draw() {
background(220);
harpoon();
if(shooting === 1){
velocity -= deceleration;
distance += velocity;
}
else if(shooting === -1){
distance -= velocity;
}
if(velocity < 0){
velocity = distance / 15;
shooting = -1;
}
if(distance < 0){
distance = 0;
shooting = 0;
velocity = 60;
}
}
function harpoon() {
beginShape();
for(let i = 0; i < distance; i++){
vertex(sin(angle) * i, (sin(i * 6) * cos(distance / end) * (2 * range - distance - i) / 40 + 400));
}
endShape();
}
function mousePressed() {
shooting = 1;
}