First Applet Game

I was trying to write snake. After discovering the Timer class, i was able to get the snake to move properly. However, i cant get it to turn. I think I did something wrong with the key listener.
import javax.swing.Timer;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Snake extends Applet implements KeyListener
    private int length,dir; //for dir, 2=down, 4=left, 8=up, 6=right
    private int[] snakeX=new int[99];
    private int[] snakeY=new int[99];
    public void init()
        addKeyListener(this);
        length=5;
        dir=6;
        for (int c=0;c<length;c++)
            snakeX[c]=150-20*c;
            snakeY[c]=150;
     * Called by the browser or applet viewer to inform this Applet that it
     * should start its execution. It is called after the init method and
     * each time the Applet is revisited in a Web page.
    public void start()
        int delay = 1000; //milliseconds
        ActionListener taskPerformer = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                 move();
         new Timer(delay, taskPerformer).start();
    public void update(Graphics g) {
        // Redefine update so it doesn't erase the applet before calling
        // paint().
      paint(g);
     * This may be the most important method in your applet: Here, the
     * drawing of the applet gets done. "paint" gets called everytime the
     * applet should be drawn on the screen. So put the code here that
     * shows the applet.
     * @param  g   the Graphics object for this applet
    public void paint(Graphics g)
        //field
        g.setColor(Color.white);
        g.fillRect(0, 0, 500, 500);
        //snake
        g.setColor(Color.blue);
        for (int c=0;c<length;c++)
            g.fillRect(snakeX[c] ,snakeY[c], 20, 20);
     public void changeDir(int direction)
         dir=direction;
     public void keyTyped(KeyEvent evt) {
         int key = evt.getKeyCode();  // keyboard code for the key that was pressed
         if (key == KeyEvent.VK_LEFT)
            changeDir(4);
         else if (key == KeyEvent.VK_RIGHT)
            changeDir(6);
         else if (key == KeyEvent.VK_UP)
            changeDir(8);
         else if (key == KeyEvent.VK_DOWN)
            changeDir(2);
     public void keyReleased(KeyEvent e) {
     public void keyPressed(KeyEvent e) {                       
    public void move()
        int x=snakeX[0];
        int y=snakeY[0];
        int xChange=0;
        int yChange=0;
        for (int c=length-1;c>0;c--)
            snakeX[c]=snakeX[c-1];
            snakeY[c]=snakeY[c-1];
        switch (dir)
            case 8: yChange=-20; break;
            case 4: xChange=-20; break;
            case 6: xChange=20; break;
            case 2: yChange=20; break;
        snakeX[0]=x+xChange;
        snakeY[0]=y+yChange;
        repaint();
    public boolean isAlive()
        if (snakeX[0]<0 || snakeX[0]>280 || snakeY[0]<0 || snakeY[0]>280)
            return false;
        for (int c=1;c<length;c++)
            if (snakeX[0]==snakeX[c] && snakeY[0]==snakeY[c])
                return false;
        return true;
     * Called by the browser or applet viewer to inform this Applet that
     * it should stop its execution. It is called when the Web page that
     * contains this Applet has been replaced by another page, and also
     * just before the Applet is to be destroyed. If you do not have any
     * resources that you need to release (such as threads that you may
     * want to stop) you can remove this method.
    public void stop()
        // provide any code that needs to be run when page
        // is replaced by another page or before Applet is destroyed
     * Called by the browser or applet viewer to inform this Applet that it
     * is being reclaimed and that it should destroy any resources that it
     * has allocated. The stop method will always be called before destroy.
     * If you do not have any resources that you need to release you can
     * remove this method.
    public void destroy()
        // provide code to be run when Applet is about to be destroyed.
}The Timer creates new thread. I think i need to get the Key Listener into that thread, but Im not sure how to. Please help me do this. (Btw, i know the delay is too long)

this is the code, same with your code but keyTyped is moved to keyPressed, and it is an applet-application game
if playing as applet, be sure to click in the applet area to have it focus
and one thing, there's nothing wrong with the thread
import javax.swing.Timer;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Snake extends Applet implements KeyListener{
     private int length,dir; //for dir, 2=down, 4=left, 8=up, 6=right
     private int[] snakeX=new int[99];
     private int[] snakeY=new int[99];
     public void init() {
          addKeyListener(this);
          length=5;
          dir=6;
          for (int c=0;c<length;c++) {
               snakeX[c]=150-20*c;
               snakeY[c]=150;
     public void start() {
          int delay = 1000; //milliseconds
          ActionListener taskPerformer = new ActionListener() {
               public void actionPerformed(ActionEvent evt) {
                    move();
          new Timer(delay, taskPerformer).start();
     public void update(Graphics g) {
          // Redefine update so it doesn't erase the applet before calling
          // paint().
          paint(g);
     public void paint(Graphics g)    {
          //field
          g.setColor(Color.white);
          g.fillRect(0, 0, 500, 500);
          //snake
          g.setColor(Color.blue);
          for (int c=0;c<length;c++) {
               g.fillRect(snakeX[c] ,snakeY[c], 20, 20);
     public void changeDir(int direction)     {
          dir=direction;
     public void keyTyped(KeyEvent evt) {
          // moved to keyPressed(KeyEvent) method
     public void keyReleased(KeyEvent e) { }
     public void keyPressed(KeyEvent e) {
          int key = e.getKeyCode();   // keyboard code for the key that was pressed
          if (key == KeyEvent.VK_LEFT) {
              changeDir(4);
          } else if (key == KeyEvent.VK_RIGHT) {
               changeDir(6);
          } else if (key == KeyEvent.VK_UP) {
               changeDir(8);
          } else if (key == KeyEvent.VK_DOWN) {
               changeDir(2);
     public void move()    {
          int x=snakeX[0];
          int y=snakeY[0];
          int xChange=0;
          int yChange=0;
          for (int c=length-1;c>0;c--)        {
               snakeX[c]=snakeX[c-1];
               snakeY[c]=snakeY[c-1];
          switch (dir)        {
               case 8: yChange=-20; break;
               case 4: xChange=-20; break;
               case 6: xChange=20; break;
               case 2: yChange=20; break;
          snakeX[0]=x+xChange;
          snakeY[0]=y+yChange;
          repaint();
     public boolean isAlive()    {
          if (snakeX[0]<0 || snakeX[0]>280 || snakeY[0]<0 || snakeY[0]>280) {
                return false;
          for (int c=1;c<length;c++) {
               if (snakeX[0]==snakeX[c] && snakeY[0]==snakeY[c]) {
                    return false;
          return true;
     public static void main(String[] args) {
          Snake game = new Snake();
          game.init();
          Frame f = new Frame();
          f.setSize(500, 530);
          f.add(game);
          f.setVisible(true);
          game.start();
          game.requestFocus();
}and you might want to see this: http://goldenstudios.uni.cc/contents/products/games/bin/snake.jnlp

Similar Messages

  • Connecting more than java file in an applet game

    I'm creating an applet game that consists of more than one java file, how can I connect those java files in one main program?....And also, how can I hide the first window of my applet and show the next window of my applet from the different java file?
    Can anyone give me a simple code that consists of 2 java files connected in one program and that can hide the first window when I click a button there and opens the next window....please help me with this....thanks....

    Components and windows in java have setVisible(boolean) methods. You can hide them by calling setVisible(false). Later you can make them visible again by calling setVisible(true).

  • Use mouse for first person game

    I have programed one first person game using Java 3D and am working on a new idea and I hope to be able to run it through a web browser.
    The problem I am having is using the mouse in the game were it does not leave the applet window when moved and I can keep track of how much movement it makes so I can make it function like a normal FPS (the mouse is moved in a certain direction and the character turns that direction the amount the mouse was moved). If someone could point me toward a class or of anyway this can be done that would be great. Thanks.

    Java does not have built-in support for direct polling of the mouse.
    One hack that I've used to get around that is in the Robot class.
    If the mouse exits the applet window from the left side, I can use Robot.moveMouse(int x, int y) to move the cursor back to the right side. This let's me force the mouse to be within the applet window at all times.
    Its pretty hacky, and I believe you're going to have to get the user to sign some special permissions to use this in an applet, but there's not much alternative.
    good luck
    -Cuppo

  • Help needed in doing a first applet !

    Dear People,
    My goals are humble. Only to do a first applet
    my MyFirstApplet.html and MyFirstApplet.java are below
    If I try to open the html document in the web browser
    I see a grey rectangle which indicates I think that
    the applet capability has not been enabled for the browser.
    Yet I did download the plugin .
    thank you in advance
    Stan
    import javax.swing.JApplet;
    import java.awt.Graphics;
    public classMyFirstApplet extends JApplet
    public void paint(Graphics g)
    g.drawString("To climb a ladder, start at the bottom rung",20,90);
    <html>
    <head>
    <title> MyFirstApplet
    </title>
    <body>
    <applet code = "MyFirstApplet.class" width = 300 height = 200 >
    </applet>
    </body>
    </html>

    I would try to color the background to see if it is even getting addd to the applet.
    import javax.swing.JApplet;
    import java.awt.Graphics;
    public classMyFirstApplet extends JApplet
    punlic void init(){
    this.setSize(300,300);//setst the size
    this.setbackground(Color.red);//sets the color of the background
    public void paint(Graphics g)
    g.setForeground(Color.black);//sets the color of the text
    g.drawString("To climb a ladder, start at the bottom rung",20,90);
    thy that and let me know if it worked,.
    steve

  • How to call an applet from a first applet

    Hi,
    I need to call an applet from a first applet, but I want that the called applet doesn't execute in the same AppletContext than the first one, is it possible?
    If it is, what is the solution?
    Thanks

    Yes, it is possible. One way would be to use static variables.
    class A1 extends Applet
       public static A2 TheOther;
       public A1()
          A2.TheOther = this;
       public void callA2()
          TheOther.doSomething();
    class A2 extends Applet
       public static A1 TheOther;
       public A2()
          A1.TheOther = this;
       public void doSomething()

  • How to pass first applet value to second applet

    please help ,
    can anyone knows how to send first applet parameter to second applet,
    here is the code
    //<applet code="firstapplet.class" height="200" width="300"></applet>
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class firstapplet extends JApplet
    JPanel pn;JTextField txt;JButton btn;
    public void init()
    pn = new JPanel();
    getContentPane().add(pn);
    txt = new JTextField(20);
    pn.add(txt);
    btn = new JButton("submit");
    pn.add(btn);
    on the click of button i want to pass the textfield value to second applet

    I don't know what exactly you mean by "sending first
    parameter", but using Applet.getContext() you can
    gain access to the other applets on that page, if
    that's what you need. Refer to the API docs for more
    info.thanks for the reply,
    but i want to get the first applet textfield value and show on second applet
    can you help me on this

  • Applet Game Programming - player movement

    HI Java Experts,
    I have a very simple question applet game programming - jdk 1.02.
    Let's say you have a player on the applet window. He can move right and left.
    Naturally you have an image representing the player. When the player moves left you present an image loop with him running left. And vice versa for running right.
    Of course when he stops moving you just want to show a still image.
    What do you guys feel is the best technique for that situation ?
    Stephen

    Hi Thanks for the advice.
    I'm under the impression that if I used jdk1.4
    everybody who wanted to play the game would have to go
    through the trouble of downloading something . If
    that is so, then i would like to stick with 1.02 to
    have the widest possible audience.Use Java Web Start to deploy it as an application instead of an Applet. If your program is really cool, people will download the JDK 1.4 to use it. Then we will have more java users in the world :)
    By the way i have a URL perhaps someone could look > at the source code and give additional suggestions
    you can make sonic the hedge hog run and jump
    http://www.swebdev.com/Adventure.html
    That code has some good points. I like the nice object oriented flow of it. However, the way he sets up the Thread is all wrong. He uses yield and sleep, you would want to set up this using wait() and notifyAll() calls if you want to make it more interesting.
    Right now i'm trying to address the issue of how to
    reverse the image for when the player is running the
    opposite way -- ? perhaps a separate thread in 1.02
    might be an answer? I would be glad to hear all kinds
    of suggestions on the sample code seen thereYou shouldn't need a separate thread just to reverse the image. If your little guy is already in his own thread, just switch the image that is displayed when the player hits the opposite direction key.
    Think of threads like puppets, and you are the puppet master. Your little guys is a puppet, so he should be in his own thread. You can make him do whatever you want from your thread (the master) by pulling strings (changing globals, and message passing)
    Wow... Thats a really good analogy... I just thought that up :)

  • What do you think of my applet game

    Over the last couple days, I made a java applet game. It is all complete except for the highscores. I am planning on doing some sort of global highscores and since I have little experience with internet programming, it is going to take a little while.
    Let me know what you think!
    http://www.geocities.com/scottrick49/targeteer/targeteer.html

    First of all I wanted to say that I like the game but I still think there is room to improve.
    To begin with yes, I think you've got way to many circles going in the start.
    If you had maybe 7 circles with higher speed I would think it more of a challenge or do as turingpest says and ramp up the number of circles.
    When I click the mouse button everything stops for a maybe 250 msec and then jumps to a new location, while it makes it more difficult I though it mainly annoying.
    One thing I would like to see in the game is if you remove the white corners of the circles and makes them explode in the color that they are.
    Adding sound would greatly benefit the game.
    Another thing that TuringPest points out, try making a credits part or something where you show any info about yourself.
    Another idea would be to give the circles different scores and when you've got enough score and accuracy you reach a new level.
    Something in the manner of adding time to the bar when you hit a circle and remove when you miss might be fun and as the difficulty increases you lose time faster.
    That's about what I can think of right now, but as I said, I actually enjoyed playing it :P

  • My First Flash Game

    ok this is my first flash game I have ever built. I developed
    the whole game myself. I am actually amazed how well it came
    together. There was more I would have loved to add but with
    budget/timeline they got left out. Id love to hear feed back on it.
    it's called Bobby Labonte's Pit Stop Challenge. I originally
    developed it with a engine repair guy but the client said no engine
    repair in the pit stops. So since I already programed him in I left
    it as a easter egg (you gotta hit 4 then 3 on the start screen to
    activate him). heres the URL
    http://labonteslaw.com
    Thanks for looking.

    pit failed
    but great, nice game...

  • Looking beginner applet game programmer

    Hi people. Iam quite new to java and currently learning stuff about how to program java games in an applet. So iam looking for a partner to start a little game/project together and hopefully we can learn stuff of each other and get a half decent game at the end aswell. I only really have 1 requirement.
    Please know atleast the fundementals of applet game programming
    Other information
    Age : 16
    Location : UnitedKingdom
    Chat : MSN Messenger
    Please get in contact with me through e-mail or MSN Chat. e-mail is : [email protected]
    Thanks alot.

    >>
    The age/location aren't requirements--the OP is describing himself.Yes, I think it's a bit too early in the day for my attempt at humor:);)
    kindly apologizing
    walkenNo need to apologize. Your humor is always welcome. If this is too early, I'd hate to see what's too late. ;)

  • Applet game question , plz take a look

    Hi!
    Which is the most common method when u have an applet game and you want to paint/print things on the screen, do i use the normal paint method?
    like this:
    public void paint(Graphics g) {
    g.drawImage(stone,0,0);
    g.drawImage(grass,0,44);
    //etc etc...
    } I don't know any other way so please tell me which is the most common way. And which alternatives there are.
    Thanks in advance. http://www.pbhome.se/alltomallt/html/Little%20Quester.html
    By the way, here is one game i made using the way i showed aboveEdited by: javaguy387 on Nov 20, 2007 8:19 AM
    Edited by: javaguy387 on Nov 20, 2007 8:27 AM
    Edited by: javaguy387 on Nov 20, 2007 8:28 AM

    Active rendering is when you actively decide when to render (draw) things.
    No, I don't have any current samples, and if I gave them to you it'd be because I used the wonderful "Search Forums" box on the left sidebar, or google. I suggest you learn to do the same or you won't get very far. Good luck with your work.

  • First project, an applet game board.

    Dear coders,
    I cannot get my carefully constructed color arrays to color the tiles in my game board.
    If some kind person would kindly peruse my scratchings and show me how to get my colors on to the tiles, I would be most grateful.
    Here is the code as far as I have been able to take it.
    import java.awt.*;
    import java.applet.*;
    import java.util.*;
    public class JbGreed1 extends Applet
         int x;
         int y;
         int c;
         int rn;
         byte[] rd = new byte[16];
         byte[] gr = new byte[16];
         byte[] bl = new byte[16];
         int [][] displayBoard = new int[60][40];
         Random rnd = new Random ( ) ;
         public void colours ( )
         rd[ 0]= ( byte ) 255;     gr[ 0]= ( byte ) 255;     bl[ 0]= ( byte ) 255;
         rd[ 1]= ( byte ) 255;     gr[ 1]= ( byte ) 0;     bl[ 1]= ( byte ) 0;
         rd[ 2]= ( byte ) 0;     gr[ 2]= ( byte ) 0;     bl[ 2]= ( byte ) 255;
         rd[ 3]= ( byte ) 0;     gr[ 3]= ( byte ) 255;     bl[ 3]= ( byte ) 0;
         rd[ 4]= ( byte ) 255;     gr[ 4]= ( byte ) 255;     bl[ 4]= ( byte ) 0;
         rd[ 5]= ( byte ) 0;     gr[ 5]= ( byte ) 127;     bl[ 5]= ( byte ) 0;
         rd[ 6]= ( byte ) 0;     gr[ 6]= ( byte ) 160;     bl[ 6]= ( byte ) 255;
         rd[ 7]= ( byte ) 0;     gr[ 7]= ( byte ) 240;     bl[ 7]= ( byte ) 255;
         rd[ 8]= ( byte ) 200;     gr[ 8]= ( byte ) 190;     bl[ 8]= ( byte ) 0;
         rd[ 9]= ( byte ) 160;     gr[ 9]= ( byte ) 0;     bl[ 9]= ( byte ) 0;
         rd[10]= ( byte ) 0;     gr[10]= ( byte ) 155;     bl[10]= ( byte ) 155;
         rd[11]= ( byte ) 127;     gr[11]= ( byte ) 0;     bl[11]= ( byte ) 127;
         rd[12]= ( byte ) 79;     gr[12]= ( byte ) 79;     bl[12]= ( byte ) 79;
         rd[13]= ( byte ) 255;     gr[13]= ( byte ) 0;     bl[13]= ( byte ) 255;
         rd[14]= ( byte ) 127;     gr[14]= ( byte ) 127;     bl[14]= ( byte ) 127;
         rd[15]= ( byte ) 200;     gr[15]= ( byte ) 200;     bl[15]= ( byte ) 200;
         public void init ( )
              for ( y=0; y<40; y++ )
                   for ( x=0; x<60; x++ )
                        int rn = rnd.nextInt ( ) *100;
                        if ( ( rn%14 ) == 2 ) displayBoard [x] [y] = 1;
                        else displayBoard [x] [y] = 0;
         public void paint ( Graphics g )
              setBackground ( Color.black ) ;
              int rn = ( rnd.nextInt ( ) *100 ) %14;
              g.setColorRGB ( rd[rn], gr[rn], bl[rn] ) ;
              for ( int x=0; x<60; x++ )
                   for ( int y=0; y<40; y++ )
                        if ( displayBoard [x] [y] >0 )
                             g.fillRect ( 15+x*16, 15+y*16,16,16 ) ;
                        else
                             g.fillRect ( 16+x*16, 16+y*16,14,14 ) ;
    }Thank you for your kind attention (-_-)
    Edited by: julianbury on Jun 24, 2009 8:20 PM
    Edited by: julianbury on Jun 24, 2009 8:22 PM

    Hiya AndrewThompson,
    I still have this color problem with the gameboard applet ...
    It compiles ok but doesn't work the way it should.
    This line sets random tile-color-numbers (0 to 13) thus:
    board [x] [y] = ( ( rnd.nextInt ( ) *100 ) %14 );and the lines below are supposed to read color number for the tile and draw it accordingly:
    g.setColor ( tileColour [ board [x] [y] ] ) ;
    g.fillRect ( 16+x*16, 16+y*16,14,14 ) ;This is not working. It draws one tile in black and stops without throwing an error.
    So, I commented it out
    g.setColor ( tileColour [ board [x] [y] ] ) ;and substituted
    g.setColor ( Color.cyan ) ;Just to check that it covers the board.
    I cannot understand why it is not working.
    Here are the HTM file contents:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>julianbury.com</title>
    </head><body>
    <center><applet code="GameBoard.class" width="992" height="672"></applet></center>
    </body></html>
    And here is the entire Java source for you to play with:
    //     GameBoard.java
    import java.applet.*;
    import java.awt.*;
    import java.util.*;
    public class GameBoard extends Applet
         int x;
         int y;
         int c;
         int rr;
         int [][] board = new int[60][40];
         Random rnd = new Random ( ) ;
         Color [] tileColour = new Color[16];
         public void tileColours ( )
              tileColour[ 0] = new Color( 255, 255, 255);
              tileColour[ 1] = new Color( 255, 0, 0);
              tileColour[ 2] = new Color( 0, 0, 255);
              tileColour[ 3] = new Color( 0, 255, 0);
              tileColour[ 4] = new Color( 255, 255, 0);
              tileColour[ 5] = new Color( 0, 127, 0);
              tileColour[ 6] = new Color( 0, 160, 255);
              tileColour[ 7] = new Color( 0, 240, 255);
              tileColour[ 8] = new Color( 200, 190, 0);
              tileColour[ 9] = new Color( 160, 0, 0);
              tileColour[10] = new Color( 0, 155, 155);
              tileColour[11] = new Color( 127, 0, 127);
              tileColour[12] = new Color( 79, 79, 79);
              tileColour[13] = new Color( 255, 0, 255);
              tileColour[14] = new Color( 127, 127, 127);
              tileColour[15] = new Color( 200, 200, 200);
         public void init ( )
         {     // assign a random color to each tile -- colors 0 to 13
              for ( y=0; y<40; y++ )
                   for ( x=0; x<60; x++ )
                        board [x] [y] = ( ( rnd.nextInt ( ) *100 ) %14 );
         public void paint ( Graphics g )
              setBackground ( Color.gray ) ;
              for ( int x=0; x<60; x++ )
                   for ( int y=0; y<40; y++ )
    //                    g.setColor ( tileColour [ board [x] [y] ] ) ;
                        g.setColor ( Color.cyan ) ;
                        g.fillRect ( 16+x*16, 16+y*16,14,14 ) ;
    }Thank you in anticipation and hope (-_-)
    ==========================================================
    Edited by: julianbury on Jun 26, 2009 6:12 AM

  • Time delay in a applet game

    J have a game in an applet but I am not so fast in my fingers so I want to slow the game dowm. I therefor thought of taking the class file home and decompile it. Is there an other wayThe game is an sokoban with 400 steps and a time limit. The problem is that it easy to forget the move if you dont have the needed time.
    Hopefully someone helps me with this for me big problem
    Regards Bengt

    Hi When I turn off my computer and turn oi on again it still works. I have seen i the HTML what the name is and and if I cange the name I cant get it workning so it must be right.
    Still the question remain, no class file. Have you tested to get an applet on your computer and get it working and seach for the class.file. It must be the same for you.
    I think about the secutity. Perhaps one is not allow to dowmnload class file, because then author can prove the author have made it? But how can the thing work without the executable file class-file.
    DIV align=center><APPLET code=Triplets.class vspace=10 align=middle
    width=530 height=380
    alt="This program requires a Java-enabled web browser."><PARAM NAME="bgColor" VALUE="000000"><PARAM NAME="title" VALUE="TRIPLETS"><PARAM NAME="newGame" VALUE="NEW GAME"><PARAM NAME="level" VALUE="LEVEL"><PARAM NAME="beginner" VALUE="Beginner"><PARAM NAME="intermediate" VALUE="Intermediate"><PARAM NAME="expert" VALUE="Expert"><PARAM NAME="board" VALUE="BOARD"><PARAM NAME="bdWidth" VALUE="Width"><PARAM NAME="bdHeight" VALUE="Height"><PARAM NAME="board3" VALUE="3"><PARAM NAME="board4" VALUE="4"><PARAM NAME="board5" VALUE="5"><PARAM NAME="board6" VALUE="6"><PARAM NAME="board7" VALUE="7"><PARAM NAME="board8" VALUE="8"><PARAM NAME="board9" VALUE="9"><PARAM NAME="board10" VALUE="10"><PARAM NAME="board11" VALUE="11"><PARAM NAME="board12" VALUE="12"><PARAM NAME="playerFirst" VALUE="Player First"><PARAM NAME="yourMove" VALUE="Your move.."><PARAM NAME="thinking" VALUE="Thinking.."><PARAM NAME="playerWin" VALUE="You win !"><PARAM NAME="tripletWin" VALUE="Game Over !"><PARAM NAME="code" VALUE="Triplets.class"><PARAM NAME="vspace" VALUE="10"><PARAM NAME="align" VALUE="middle"><PARAM NAME="width" VALUE="530"><PARAM NAME="height" VALUE="380"><PARAM NAME="alt" VALUE="This program requires a Java-enabled web browser."><PARAM NAME="codeBase" VALUE="http://www.mazeworks.com/triplets/"></APPLET></DIV></TD></TR>
    <TR>
    Regards Bengt

  • Help with first flash game?

    Hi. My name's Rory.
    I am an artist.
    http://www.youtube.com/profile?user=PimpOfPixels
    http://roaring23.cgsociety.org/gallery/
    I am learning action script and Flash so that I can make
    games.
    I am not a complete novice in programming. I am proficient in
    Java and in MaxScript (3DSMAX embedded language).
    I have been making some progress in action script and I have
    a functional (although incomplete) game in the works. You can view
    it here:
    http://secure2.streamhoster.com/~rlu...orniverous.swf
    The idea is it's a color game
    red beats green, green beats, blue beats red. Think paper
    scissor rock.
    The idea is to change the entire circle into one color.
    The graphics are place holders BTW.
    I am using FlexBuilder 2.0 and Flash CS3, and I have come
    across a problem not covered in either of my books.
    I'd really appreciate any help that you guys can offer.
    I have gotten this far on my own.
    My #1 question (and I have many more) is:
    How do you through Flash specify animation segments for a
    MovieClip Symbol?
    Notice how the red creatures occasionally open their mouths.
    I want to have a walk, an attack, an absorb, and a bounce animation
    on the same timeline and trigger the appropriate one depending on
    which color the creature collides with. I do not know how to go
    about this problem. I’ve just been trying to get the walk
    animation to loop without playing the attack animation so far.
    I've tried frame-labeling in flash, with scripts on the key
    frames of a second layer that specify when to stop or repeat the
    animation... No dice.
    I have a symbol named RedShot in the library of a flash
    project named "graphics"
    In my timeline I have 2 animation segments, and I have a
    second layer denoting two corresponding frames named "walk" and
    "attack" from the properties menu.
    On the final frames of the animations I have scripts.
    Code:
    gotoAndPlay("walk");
    and
    Code:
    gotoAndPlay("attack");
    respectively.
    Im my library I have linkage options specified as such:
    Class:RedShot
    BaseClass:flash.display.MovieClip
    export of actionscript#CHECKED
    export on 1st frame#CHECKED
    on the main stage of my flash project I have actionscript for
    2 functions:
    Code:
    function walk(){
    red_shot.gotoAndPlay("walk");
    function attack(){
    red_shot.gotoAndPlay("attack");
    I export the project and the opened window has the "walk"
    animation looping properly.
    In my FlexBuilder project I embed the symbol
    Code:
    //Inside class global variables:
    [Embed(source="../graphics.swf", symbol="RedShot")]
    public var RedShot:Class;
    private var _shot:MovieClip;
    Code:
    //and in my buildShot function:
    _shot = new RedShot();
    addChild(_shot);
    When I build the project the characters appear, and they
    animate. The only trouble is that there are no breaks in the
    animation. The animation loops right through the frames where I
    have specified that the animation should "gotoAndPlay" from a
    different part.
    What's weirder is that I can call
    Code:
    "gotoAndPlay("attack");"
    without an error and it will go to and play from that point.
    The only trouble is that it will begin to loop the entire animation
    again without stopping at the gotoAndPlay events stored in the
    frames of the timeline.
    It seems like all embedded actions are ignored, add I can't
    think of another way to controll the animation.
    Any thoughts?

    After hours of searching the internet I finally got this
    blasted question figured out.
    How to you export a symbol from Flash for use in a Flex
    Builder project without destroying actionscript stored within the
    frames of the Symbol's timeline?
    That's a long winded way of saying: "In FlexBuilder, how do
    you control MovieClips from Flash". I'm trying to make games, and
    this was a particularly important question for me :).
    Here's how:
    1) You need a hotfix from Adobe.
    [HTML]http://kb.adobe.com/selfservice/viewContent.do?externalId=kb401493&sliceId=2[/HTML]
    This allows Flash CS3 to export a SWC file.
    2)You have to set the linkage properties for your various
    symbols in the flash library panel.
    a)right click on symbol in library panel
    b)choose "linkage"
    c)"Class:" = (pick a name)
    d)"Base class:" = flash.display.MovieClip;
    e)"Export for ActionScript" = CHECKED
    f)"Export in first frame"=CEHCKED
    3)If you want to have multiple segmented animations as I
    certainly did you'll want to create frames and actionscripts within
    the symbols timeline to define where these animations are.
    a) in the symbol's timeline make a second layer. We'll name
    that layer "labels" for the sake of not having this get too
    confusing.
    b) on that layer create a new frame for each of the animation
    segments that you'd like to define and stretch them to the length
    of the corresponding animations.(I'm assuming that you have a
    keyframe animation on the 1st layer... otherwise what's the point
    of all this :P?)
    c)in the properties panel name the frames in the "labels"
    layer accordingly ie. "walk" "run" shoot" etc.
    d)Define whether the various animations play once or loop by
    adding a script to the last frame of the animation. If you want the
    animation to loop add
    [CODE]gotoAndPlay("name-of-the-animation");[/CODE]
    if you want the animation to play once and stop add
    [CODE]stop();[/CODE]
    if you want the animation to play once and then return to a
    different animation add
    [CODE]gotoAndPlay("name-of-a-different-animation");[/CODE]
    4) now you can export the symbols to an SWC file. Note: you
    do not get this option unless you have installed the hotfix.
    [HTML]http://kb.adobe.com/selfservice/viewContent.do?externalId=kb401493&sliceId=2[/HTML] .
    a)rightclick on a symbol in the library panel
    b)choose "exportSWCfile..."
    c)export the file to a logical place such as the root of your
    FlexBuilder project.
    5) Now you have to tell flexbuilder about the new SWC file.
    Note: Once this file is added to the FlexBuilder library you can
    instantiate classes from it as though they were included using the
    "include" function.
    a)Right clicking on the root of the project in the Navigator
    view.
    b)going to properties.
    c)Going to library path. (2nd tab)
    d)and pressing the "Add SWC" button
    Now you're done and you can instantiate any of the symbols
    from your library while preserving any actions from your symbols
    timeline just as though you had imported it as a class from a
    typical library.
    Sweet huh?
    Thanks to the countless people and internet resources I found
    on the subject. Hopefully it will be easier for anyone who finds
    this post.
    Here's an adobe video which covers the basic process.
    https://admin.adobe.acrobat.com/_a300965365/p75214263/

  • Best place to load Images in applet game

    Sorry for the double post but I just realised I originally posted this in completely the wrong forum!
    Hello,
    I have made a fairly basic game of 21/BlackJack and was wondering where the best place to load the card Images is/was...
    Currently I am loading the images into an Image[ ] in the applet class, but was thinking maybe the loading should be done in the deck or card class?
    In the applet class I use an ordered version of the deck to assign the cards in the image[ ], then to call an image I generate an index number based on the current cards value and suit....
    However this method means I have to create an instance of the deck in the main program, whereas before I had it as a private member of the dealer class, so only the dealer could access it (which seems "safer", no?)
    So would a better idea be to have a loadImage() method in the deck class, which populates an Image[ ] with the cards and pass this to the main program?
    Thanks

    Ken,
    Loading images is slow so you only want to do it once... maybe when you generate the deck ... and "image" is definately an attribute of the card, yes... I'd actually implement the loadImage() as a method in the card class so set a private image variable... and then get the the dealer to call the loadImage method for each card as "he" builds the deck.
    But that's just how I would do it... and I'm no guru so don't take it as gospel... I'd be surprised if there wasn't atleast one "purer" way of doing it.

Maybe you are looking for

  • Total variances through IR

    Hi experts, Could some one explain me when  the 'Total variances through IR' are generated? We have a case of a PO in Foreign currency for quantity of 1. This PO was invoiced before being received. When received, the GR  value does not match the invo

  • Substitution because not working of Z10 in warranty - Italy

    The shop where i have bought my Blackberry Z10 is closed for bankruptcy and I don't know how to proceed with Blackberry Support in Italy because they don't have any phone number for assistance. My smartphone was broken from october 2013, while I was

  • Privledge level not working

    Guys and Gals, I need to allow a level 9 user in my switches the ability to manage interfaces f0/1 to f0/44 but NOT interfaces f0/45 thru interface f0/48 (these are trunks). Any Idea why this does not work... privilege interface level 8 switchport po

  • Non-Destructive & Deleting

    OK... I know that if you 'roll up' part of a clip you can recover it with Non-Dest feature by reverting back to original state etc... But, if you Crop or Delete a portion of your clip from the timeline, reverting back to original state is not availab

  • Can't reset my security passworrds...

    When I tried to do what the page asked me, I got sent to a place where it... asked me for my security questions. It also apparently was doing that so I could change my password, which is not something I want. I want to change my security questions so