Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-17-2008, 07:33 AM
Member
 
Join Date: Oct 2008
Posts: 44
Rep Power: 0
Unome is on a distinguished road
Default Archer Applet
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
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 10-17-2008, 02:20 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
Default
Why are the two code segements both JApplets?
Are there two <APPLET tags in the HTML, one for each?
BTW do you have HTML to run your code?

To help you debug your code add some println() statements to show execution flow and variable value changes.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-17-2008, 03:25 PM
Member
 
Join Date: Oct 2008
Posts: 44
Rep Power: 0
Unome is on a distinguished road
Default
I'm still running everything in eclipse... so I got no HTML integrated yet. I'm gonna only do that after I've debugged and gotten it to work. The println statements are a good idea... I read something about Multiple Independent Animations that required I turn Bulletanimator into a subclass within my main animator. My question is.. I know that will work. But can I run an if statement like this

if(//some sort or paramater)
{
BulletAnimator tester == new BulletAnimator(x,y);
projectile1.start();
Bullet projectile1 == new Bullet(tester.getX(),tester.getY());
projectile1.draw(g2);

}

Would that work? I'm not sure I want to be able to create multiple of these bullets at the same time... you know whenever I hit the space key? But if I did this would it call new bullet objects? Or would it create the same old one over and over and over
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 10-17-2008, 04:48 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
Default
Using new will create a new instance of the class.

You should try it occasionally in a browser to make sure the IDE is NOT doing something that a browser doesn't.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 10-17-2008, 08:12 PM
Member
 
Join Date: Oct 2008
Posts: 44
Rep Power: 0
Unome is on a distinguished road
Default
Mmk... I better try that then. How do you load it in a browser? Can you give me a basic rundown here or link me to somewhere where it does?
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 10-17-2008, 08:53 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
Default
To load an applet in a browser, you write an HTML page with the <APPLET tag. Use Search to find sample code here on this forum.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 10-18-2008, 09:51 AM
Member
 
Join Date: Oct 2008
Posts: 44
Rep Power: 0
Unome is on a distinguished road
Default
Thanks norm. Using those println's was real helpful, it helped me isolate what code wasn't running and I was able through trial and error to develop a method to work this thing. I'm sure I could perfect it, but for now. Its good enough.

I'm gonna start working on sending it to a browser, and then beging the trajectory and Actionlisteners.

Thanks
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 11-08-2008, 03:05 AM
Member
 
Join Date: Oct 2008
Posts: 40
Rep Power: 0
hunterbdb is on a distinguished road
Default
wow, this sounds cool!
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need with an applet maggie_2 Java Applets 6 09-21-2008 08:07 PM
Applet in a GUI serfster New To Java 1 06-12-2008 11:09 PM
applet amith AWT / Swing 1 05-16-2008 03:24 AM
Applet kapoorje Java Applets 0 07-24-2007 04:06 PM
Applet, To center text and To open I engage in a dialog in an Applet Marcus Java Applets 4 06-08-2007 06:15 AM


All times are GMT +2. The time now is 03:07 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org