im developing a game (j2me)....
in this i want to impliment a throwing effect....
ie .the player1 want to throw an obstacle (image) to player2....
The player1 've the option to choose force and direction.
according to this force and direction i want to make the throw. The throw should move like a parabola ....
i ve a sample midlet(given bellow) which is for 90 degree(ie the throw is possible only to right side)...
i want to make it 360 degree..
plz help me to make it in 360 degree........
- Code: Select all
import java.util.Random;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
public class RandomStoneCanvas extends Canvas implements Runnable
{
int xPosition = 0;
int yPosition = 0;
int xSpeed = 0;
int ySpeed = 0;
int gravity = 1;
Random rand = null;
int stageWidth = 0;
int stageHeight = 0;
customfont midlet;
public RandomStoneCanvas(customfont m_Midlet)
{
midlet = m_Midlet;
rand = new Random();
stageWidth = getWidth();
stageHeight = getHeight();
newStone();
new Thread(this).start();
}
public void newStone()
{
xSpeed =2 + rand.nextInt(20); //suppose 2+ force
ySpeed = - (10 + rand.nextInt(10));
xPosition = 20;
yPosition = 200;
}
public void paint(Graphics g)
{
g.setColor(0xffffff);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0x000000);
g.fillRect(xPosition - 2,yPosition - 2, 4, 4);
}
void moveStone()
{
/* this equation is for one direction , i want to make it 4 all direction */
ySpeed += gravity;
xPosition += xSpeed;
yPosition += ySpeed;
if(xPosition > stageWidth || yPosition > stageHeight)
{
newStone();// next throw starting
}
}
public void run()
{
while(true)
{
try
{
repaint();
moveStone();
synchronized(this)
{
wait(100L);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
in this sample Midlet assume force and direction are taking as random numbers.........
is there any other logic to impliment this ?
thanks in advance
