Unome again. I'm still pursuing this goal. I was able to get the rotations to all sync correctly but now I'm pursing a new goal. An Archer applet.
GOAL: Archer moves bow up and down according to arrow key strokes.
Archer launches an arrow at every press of the space bar.
So far I've got the archer, and I've been able to manipulate the arm up and down, so I'm confident once I apply the key listener I can get that to work.
My problem is launching a new arrow. I got the trajectory calculated... thats not the problem. The problem is displaying the animation over and over at any given time. This requires an independent animation which I've decided to test with something simple.
Here is a bullet animation.
|
PHP Code:
|
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JApplet;
import java.awt.*;
public class bulletanimator extends JApplet implements Runnable
{
double posx = 10;
final double POSY = 10;
Thread shooter = null;
double count;
public void paint(Graphics g)
{
count++;
Graphics2D g2 = (Graphics2D)g;
bullet eraser = new bullet(posx-12,POSY,2);
bullet projectile = new bullet(posx,POSY,1);
eraser.shoot(g2);
projectile.shoot(g2);
}
public void start()
{
shooter = new Thread(this);
shooter.start();
}
public void run() {
while (count<10) {
if(count < 10)
{
posx = posx + 12;
}
repaint();
try {
Thread.sleep(20);
} catch ( InterruptedException e ) {
// do nothing
}
}
}
}
|
When I run this Applet. A bullet object will rapidly fire across the screen ONCE.
I decided to take this and try to run it within my Working Archer applet.
|
PHP Code:
|
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JApplet;
import java.awt.*;
public class Animatetester extends JApplet implements Runnable
{
final static int WIDTH = 400;
final static int HEIGHT = 200;
double stickx = 50;
double sticky = 50;
double angle = -Math.PI/3;
double shoot = 0;
Thread runner = null;
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
setSize(WIDTH,HEIGHT);
Rectangle clear = new Rectangle(0,0,WIDTH,HEIGHT);
Archer stickbob = new Archer(stickx,sticky,angle);
Arrow arrow1 = new Arrow(stickx+4,sticky+16);
g2.setColor(Color.white);
g2.fill(clear);
g2.setColor(Color.black);
stickbob.draw(g2);
g2.rotate(-angle,stickx+4,sticky+16);
arrow1.draw(g2);
g2.rotate(angle,stickx+4,sticky+16);
if(angle == Math.PI/3) //here is where I'm attempting to display the bullet animation.
{
bulletanimator bullet = new bulletanimator();
bullet.start();
bullet.run();
}
}
public void start()
{
runner = new Thread(this);
runner.start();
}
public void run() {
while ( runner != null) {
if(angle < Math.PI/3)
{
angle = angle + Math.PI/80;
}
repaint();
try {
Thread.sleep(20);
} catch ( InterruptedException e ) {
// do nothing
}
}
}
}
|
When I run this The archer lifts his bow like always, but the bullet never fires when the required bow angle occurs. What is my issue?
I really hope I can get some help. I've had very little response to my questions (with an exception of Norm. Thankyou very much for responding)
Please help me.
Unome