hello. im trying to make it so that in my game when a player clicks a sprite the sprite goes into a state of ‘activated’ and then moves mouse away and when he releases the left mouse button it sends the sprite flying off in that direction. i set it up so when the mouse sprite is colliding with the sprite and clicked the sprite is set into ‘activated’ and then called a method on that sprite.
//inside main class
//when mouse sprite collides with sprite
public void collided(Sprite s1,Sprite s2){
M s3 = (M) s2;
double sX = s1.getX();
double sY = s1.getX();
double s2X = s2.getX();
double s2Y = s2.getX();
double s3X = s2X - 17.5;
double s3Y = s2Y - 17.5;
double s4X = sX - 5.5;
double s4Y = sY - 5.5;
if( Math.pow(s4X - s3X,2)+Math.pow(s4Y - s3Y,2) < Math.pow(11 + 35,2)) {
ZenGame.clickable = true;
ZenGame.clickIt(s3);
}
if(ZenGame.leftClick){
System.out.println("activated!");
s3.activated = true;
s3.throwThis(s2X,s2Y);
}
}
//inside the sprite class (thing i want to click)
public void throwThis(double x, double y){
while(activated){
if(!ZenGame.leftClick){
double mX = ZenGame.mX;
double mY = ZenGame.mY;
if(x < mX){
speedX = 1;
setSpeed(speedX,speedY);
activated = false;
}
if(x > mX){
speedX = -1;
setSpeed(speedX,speedY);
activated = false;
}
if(y < mY){
speedY = 1;
setSpeed(speedX,speedY);
activated = false;
}
if(y > mY){
speedY = -1;
setSpeed(speedX,speedY);
activated = false;
}
}
}
}
everything seems to work untill i get to the if(!ZenGame.leftClick), inwhich does not run. i think the problem is that when the user moves the mouse away he is no longer colliding with the sprite so the if statement never gets teh chance to execute. what actually happens when i run teh game is once i click the sprite my mouse sprite freezes over the sprite and nothing happens.
maybe i should be going about this in a tottally diffrent way? any ideas?
thanks.
