public class Zielen
{
double x_float = 400;
double y_float = 400;
double vx;
double vy;
double angle = 80;
double power = 120;
final double gravity = 0.3;
double pi = 2 * Math.PI;
int radius = 3;
private lmage dblmage;
private Graphics g;
int i = 400 + (int)(20.0 * Math.cos(((double)angle * pi) / 360.0));
int j = 400 - (int)(20.0 * Math.sin(((double)angle * pi) / 360.0));
boolean addjusting = false;
double wind = rnd.nextFloat() * 4.0 - 2.0;
public void init()
{
setBackground (Color.blue);
}
public void start ()
{
Thread th = new Thread (this);
th.start ();
}
public void stop()
{
}
public void destroy()
{
}
public void update (Graphics g)
{
if (addjusting)
{
if (dbImage == null)
{
dbImage = createImage (this.getSize().width, this.getSize().height);
dbg = dbImage.getGraphics ();
}
dbg.setColor (getBackground ());
dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
dbg.setColor (getForeground());
paint (dbg);
g.drawImage (dbImage, 0, 0, this);
}
else
{
paint(g);
}
}
public boolean keyDown (Event e, int key)
{
if (key == Event.LEFT)
{
angle++;
i = 400 + (int)(20.0 * Math.cos(((double)angle * pi) / 360.0));
j = 400 - (int)(20.0 * Math.sin(((double)angle * pi) / 360.0));
addjusting = true;
}
else if (key == Event.DOWN)
{
power--;
addjusting = true;
}
else if (key == Event.UP)
{
power++;
addjusting = true;
}
else if (key == Event.RIGHT)
{
angle--;
i = 400 + (int)(20.0 * Math.cos(((double)angle * pi) / 360.0));
j = 400 - (int)(20.0 * Math.sin(((double)angle * pi) / 360.0));
addjusting = true;
}
else if (key == 32)
{
x_float = i;
y_float = j;
vx = (power / 10.0) * (float)Math.cos((pi * (double)angle) / 360.0);
vy = -((power / 10.0) * (float)Math.sin((pi * (double)angle) / 360.0));
addjusting = false;
}
return true;
}
public void run ()
{
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
while (true)
{
x_float += vx;
y_float += vy;
vy += 0.3;
double w = 1.9 * wind - vx;
if (wind >=0)
{
vx+= (w * w) / 512.0;
}
else
{
vx -= (w * w) / 512.0;
}
repaint();
try
{
Thread.sleep (20);
}
catch (InterruptedException ex)
{
}
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
}
}
public void Angriff ()
{
while (x_float =vx)
{
if (x_float =y_float )
{
power =power+10;
}
else
{
power = power;
}
}
}
public void paint (Graphics g)
{
g.setColor (Color.white);
g.drawString ("power " + power, 100, 20);
g.drawString ("angle " + angle, 100, 40);
g.drawString ("wind " + wind, 100, 60);
g.fillOval ((int)x_float - radius, (int)y_float - radius, 2 * radius, 2 * radius);
g.drawLine(399, 400, i - 1, j);
g.drawLine(401, 400, i + 1, j);
g.drawLine(400, 399, i, j - 1);
g.drawLine(400, 401, i, j + 1);
g.fillOval (390, 390, 20, 20);
}
}