Hey guys. I'm trying to make a simple game for Android in which the player drags a space ship with one thumb and fires at enemy ships by tapping empty space with the other thumb. Thing is, to animate the bullets traveling across space, I need the list of points between the user's spaceship, and the end of the screen, the line passing through the place the user tapped.
I know I have to parametrize the line, and have read some about the subject, but I can't quite grasp it, especially on how to convert it to code. The way I see it, I need to convert the line segment between the user's ship (P1) and the place the user taps (P2) the smallest possible piece, the rate of change between x and y, the slope, I guess. Once I have that I can just multiply the rate of change by the distance from P1 to get the desired point.
But it ain't quite working. Any help would be appreciated. Thanks.
EDIT: This is what I was doing. This is all to calculate the rate of change, which I use on the Beam's update method to update it's position by multiplying it by speed...
Beam(Renderer r, float OX, float OY, float TX, float TY)
{
super(r);
p.x = (int) OX;
p.y = (int) OY;
paint = new Paint();
paint.setColor(Color.BLUE);
float X = TX - OX;
float Y = TY - OY;
boolean xPositive = X >= 0;
boolean yPositive = Y >= 0;
if(X < Y)
{
RateOfChangeX = Math.abs(X) / Math.abs(Y);
RateOfChangeY = 1;
}
else
{
RateOfChangeX = 1;
RateOfChangeY = Math.abs(Y) / Math.abs(X);
}
if(RateOfChangeX < 0 & xPositive)
{
RateOfChangeX = RateOfChangeX * -1;
}
if(RateOfChangeY < 0 & yPositive)
{
RateOfChangeY = RateOfChangeY * -1;
}
}