DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 16 to 20 of 20
  1. #16
    Join Date
    Jun 2005
    Location
    Toronto, Ontario in Canada.
    Posts
    11
    Ya I was going to modify your class and add a part 2 of the game...

    Basically i wanted to use your click-thingy program as part of the game. So that when people click and hit the targets a variable records that. Then im going to make it give points and update to the screen in real time. Afterwards (this is what im working on tonite) when the user has enough points he faces an "end guy" where he battles the end guy to the death. (thats what the health, chakra and all thats for). In the battle he/she clicks buttons that will show a gif in that box area with an animation.

    The box area loads a .gif thats animated and unfortunately it was flickering and the while true loop that your saying that doesnt compile was my noob attempt to make it stop flickering. Oddly enough it made it stop flickering at school, but here at home it just doesn't get compiled.

    Sorry i wasn't clear about where my vision was for the game. Our teacher let us use 1 other persons programs and we give them credit (thats your click game) and the end guy thing i have to do myself. The point system and all i will make as long as a variable records a click (shouldnt be hard.)

    I have included one of the animations. (this is a standard moving eyes that loads when the game starts in the box area.) So you can see how it flickers.

    Ya for your input i just wanted the target image to appear randomly on the tree area of the background so when people click it, it disappears and a variable records a hit. (i will do point system myself)

    Sorry to take up your time so much, thanks a lot.
    Attached Images
    Once upon a time there was a lost java programmer...

  2. #17
    Join Date
    Jun 2005
    Location
    Toronto, Ontario in Canada.
    Posts
    11
    that main method we dont need in the Master_Shinobi_Challenge hehe,



    I got 3 options:
    1) Somehow make your GamePanel as a class that is used to run the targetting part of the game.
    2) Or make 3 classes, one an intro class that welcomes the user, then you start GamePanel for target shooting, then after you get a certain amount of points start the end guy battle class.
    3) Tweak and change Gamepanel so there is a welcome screen then you target shoot and finally at a certain score the end guy battle starts.

    Not totally sure what is the best option of the 3 or if some of them are possible.
    Once upon a time there was a lost java programmer...

  3. #18
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    Well, here you can click away.

    I have made the GamePanel a component in the applet (that I have used
    a slightly abbrevated name for). There was a bug in my untested code that
    I have fixed. As it is now it spawns new clickObjects in the same manner as
    the initial click game. I have tested it as a local app, like you have, but the
    code for doing remote uploads and running as an aplet is there.

    I am a bit puzzled about the no-flicker issue; flickering is something that
    occurs when the program performs a repeated screen update with graphics
    that change rapidly, the code I saw just displayed an image, and that was
    it. The FRAMEBITS variable is, to my knowledge there to signal when an
    image is ready to be displayed/used and how that can substitute for double
    buffering in an animation scenario,... well that beats me, but then again,
    I have taken a lot of "beating" in my career..

    Notice that the applet in this version is just a container for the GamePanel.
    The GamePanel does all the work for loading and animating and the
    DisplayList is where all the objects that are visible have their pointers stored.

    If you introduce new classes for display you should do that by extending the
    VisibleObject class.
    Attached Files
    eschew obfuscation

  4. #19
    Join Date
    Jun 2005
    Location
    Toronto, Ontario in Canada.
    Posts
    11
    // the target(s) (?)
    private static String [] IMAGE_NAME={
    "C:\\Documents and Settings\\family\\Desktop\\naruto_game\\images\\target.gif" // etc..... ?
    };

    private static String BG_IMAGE_NAME="C:\\Documents and Settings\\family\\Desktop\\naruto_game\\images\\trees_background.jpg";
    // there is no space in trees_background.jpg in the code, not sure why it does that here

    Hey Sjalle. Thanks a lot! It runs fine as an application but when i run it as an applet it says theres a URL error in those lines i pasted above. Is there anyway to load an image thats relative to the file? ie ("images/target.gif") and if i wanted to use a url I would use ie ("http://url.com/target.gif") correct?

    Now what i have to change is the bounds so that the targets only spawn in the tree area of the GUI and spawn so theres only one at a time that disappears after x seconds.

    Neato! ^_^
    Once upon a time there was a lost java programmer...

  5. #20
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    That is not correct remote URL's

    Here goes:

    The html for a simple one image applet that is uploaded to a server folder
    named "stubs6" with images in the folder "stubs6/images"

    Code:
    <html>
    <head>
    <title>
    HTML Test Page
    </title>
    </head>
    <body>
    Basic Applet Image Display<br>
    <applet
      codebase = "."
      code     = "stubs6.ImageApplet.class"
      name     = "TestApplet"
      width    = "200"
      height   = "150"
      hspace   = "0"
      vspace   = "0"
      align    = "middle"
    >
    <param name = "image_path" value = "stubs6/images/deicide_50.jpg">
    </applet>
    </body>
    </html>
    and here is the applet:

    Code:
    package stubs6;
    
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.Image;
    import java.applet.*;
    import java.net.*;
    
    /**
     *
     * @author sjalle
     * @version 1.0
     */
    
    public class ImageApplet extends Applet {
    
      Image img=null;
      String message="No image loaded yet...";
      boolean isLoaded=false;
    
      /**
       * Initialize the applet
       */
      public void init() {
        String imagePath = this.getParameter("image_path");
        loadImage(imagePath);
      }
    
      /**
      * paint background in one color
      */
     private void paintBack(Graphics g, Color c) {
    
       g.setColor(c);
       g.fillRect(0,0,getWidth(), getHeight());
    
     }
     /**
      * Draw image if available
      * @param g
      */
     public void update (Graphics g) {
       Color oldColor = g.getColor(); // current graphics context color
       paintBack(g, Color.white);
       if (isLoaded) {
         g.drawImage(img, 0, 0, this);
       } else {
         g.setColor(Color.black);
         g.drawString(message, 20, 20);
       }
       g.setColor(oldColor); // reset current graphics context color
     }
     public void paint (Graphics g) {
       update(g);
     }
    
      /**
       * Upload an image (the old safe way)
       * @param imagePath
       */
      public void loadImage(String imagePath) {
        System.out.println("Loading:"+imagePath);
        URL url=null;
    
        try { // make URL
          url = new URL(this.getCodeBase(),imagePath);
        }
        catch (MalformedURLException ex) {
          ex.printStackTrace();
        }
    
        img=this.getImage(url); // get image object
        /**
         * ImageIO not used as this is a non-swing applet.
         */
        MediaTracker mt=new MediaTracker(this);
        mt.addImage(img,0); // start monitoring image upload progress
        /**
         * halts execution here until image is loaded, the Java VM may invoke
         * the  repaint() method and cause the display to update before
         * this is completed, the "No image loaded yet..." message will then
         * be displayed.
         */
        try {
          mt.waitForID(0);
        }
        catch (InterruptedException ex1) {
          ex1.printStackTrace();
          message="Image load failed: "+ex1.getMessage();
          repaint(); // ensure immediate message display
          return;
        }
        // ensure immediate image display
        isLoaded=true;
        repaint();
        System.out.println("OK Loaded:"+imagePath);
      }
    }
    Last edited by sjalle; 06-20-2005 at 07:40 AM.
    eschew obfuscation

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links