/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.oSKqgoNbNL6/rev.867
*
* authors:
* yamato misaki
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
int i=0;
int ground;
int r=10;
int d=r*2;
int x,vx;
int state=0;
//0:着地、1:空中
float y,vy;
float g=0.2;
float tx,ty,tvx,tvy;
void setup() {
vx=random(1,3);
vy=0;
size(300, 300);
ground=height-50;
tx=width/2;
ty=height/2;
tvx=tvy=0.0;
x=width/2;
y=ground-r;
smooth();
frameRate(30);
strokeWeight(1);
}
void jump(){noStroke();
fill(200,10,10,255);
ellipse(x,y,d,d);
if(mousePressed && state==0)
{
vy=-6;
state=1;
}
vy+=g;
y+=vy;
x=mouseX;
if(y>ground-r)
{
y=ground-r;
state=0;
}
}
void trace(){
//相手への向きを求める
float dx=x-tx;
float dy=y-ty;
//単位ベクトルを求める
float norm=sqrt((dx*dx)+(dy*dy));
dx/=norm;
dy/=norm;
//大きさを調節、速度へ
tvx=2.0*dx;
tvy=2.0*dy;
//速度を座標に
tx+=tvx;
ty+=tvy;
fill(0,100,0,255);
ellipse(tx,ty,r,r);
}
void draw() {
background(255);
stroke (0);
line (0,ground,width,ground);
jump();
trace();
}