need help trying to make my rocket always point towards the mouse
in
Programming Questions
•
1 year ago
hey, im trying to make the rocket always point towards the mouse so it looks like its flying in this direction,
have tried other rotate codes to make this work but i can't !
PImage bg;
PImage mi;
int x = 0;
int a =250;
int b =350;
float tx = 0;
float ty = 0;
int dotCount = 10;
float[] xn = new float [dotCount];
float[] yn = new float [dotCount];
//changes speed of ellipses
float[] s = new float [dotCount];
void setup () {
size (1000, 500);
smooth ();
bg = loadImage("stars.jpg");
mi = loadImage("mouse.png");
background(bg);
}
void draw () {
//int i = 0;
int l = 0;
//while (i < dotCount)
{
/*start points of ellipses
xn[l] = (tx+random(60));
yn[l] = (ty+random(150));
s[i] = random (50);
i = i + 1;
}*/
background(bg); //removes smear left by shapes moving
tx += (mouseX-tx)/30.0;
ty += (mouseY-ty)/30.0;
/* fill (169, 40, 146, 100);
int k = 0;
while (k < dotCount) {
ellipse (xn[k], yn[k], 20, 20);
ellipse (xn[l], yn[l], 20, 20);
k = k + 1;
*/
}
image(mi,tx,ty);
/* triangle (tx, ty, tx+100, ty-75, tx+100, ty+75);
fill (169, 40, 146, 75);
triangle (tx+40, ty, tx+80, ty-30, tx+80, ty+30);*/
//triangle (mouseX+100, mouseY+100, mouseX+100,mouseY+150, mouseX+150, mouseY+50);
/* makes ellipses move
xn[k] = xn[k]+s[k];
xn[l] = xn[l]+s[l];
yn[k] = yn[k]+s[k];
yn[l] = yn[l]+s[l];
//makes them keep going accross page.
/*if (xn[k] > tx) {
xn[k] = 0;
}
k = k + 1;
*/
if (xn[l] > tx) {
xn[l] = 0;
}
l = l + 1;
}
1