Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 TRON help.
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
.hack




PostPosted: Wed Jun 07, 2006 9:55 am   Post subject: TRON help.

So, I'm coding my final project for grade 12 Java trash. And I have taken it to the applet route. Of course we use the garbage ready to Java, so I decided an applet would be the best way, as Ready To Java doesn't change how they run in its environment.

Anyways, I found a nifty tutorial about how to code a game, and I was particularily looking towards the the keyboard input. The first bit that I have done now is just for the menu. TO choose, new game, instructions, credits. Instead of using the older system of hitting 1 for new game, 2 for instructions, etc, I wanted to use a cursor that would move with the keyboard.

I am using the keydown method, and then having it set a position. Then the graphics method is to get the position number, and place the image accordingly. Here is the code so far:

code:
// The "Tronfinal" class.
import java.applet.*;
import java.awt.*;

public class Tronfinal extends Applet
{
    // Place instance variables here
    int menupos = 1;

    Image background;
    Image menu;
    Image br;
    Image bl;
    Image bu;
    Image bd;
    Image rr;
    Image rl;
    Image ru;
    Image rd;

    AudioClip Menubeep;



    public void init ()
    {
        // Place the body of the initialization method here
        menu = getImage (getCodeBase (), "\\Final\\TRON\\Images\\menu.gif");
        background = getImage (getCodeBase (), "\\Final\\TRON\\Images\\tronfield.gif");
        br = getImage (getCodeBase (), "\\Final\\TRON\\Images\\bcr.gif");
        bl = getImage (getCodeBase (), "\\Final\\TRON\\Images\\bcl.gif");
        bu = getImage (getCodeBase (), "\\Final\\TRON\\Images\\bcu.gif");
        bd = getImage (getCodeBase (), "\\Final\\TRON\\Images\\bcd.gif");
        rr = getImage (getCodeBase (), "\\Final\\TRON\\Images\\rcr.gif");
        rl = getImage (getCodeBase (), "\\Final\\TRON\\Images\\rcl.gif");
        ru = getImage (getCodeBase (), "\\Final\\TRON\\Images\\rcu.gif");
        rd = getImage (getCodeBase (), "\\Final\\TRON\\Images\\rcd.gif");
        Menubeep = getAudioClip (getCodeBase (), "\\Java\\Final\\TRON\\Sounds\\menubeep.au");
    }


    public boolean keyDown (Event e, int key)
    {
        if (key == Event.UP)
        {

            menupos--;
            Menubeep.play ();
            //makes sure the cursor cannot move past the lowest menu title
            //By minimizing the movement area to 1.
            if (menupos == 0)
            {
                menupos = 1;
            }

        }
        else if (key == Event.DOWN)
        {
            menupos++;
            Menubeep.play ();
            //makes sure the cursor cannot move past the lowest menu title
            //By maxing the movement area to 3.
            if (menupos == 4)
            {
                menupos = 3;
            }

        }
        // user presses space bar (value = 32!)
     //No spacebar response sent.
        else if (key == 32)
        {

        }
        else
        {

        }

        return true;
    }


    // init method

    public void paint (Graphics g)
    {
        // Place the body of the drawing method here
        // drawing the image: g.drawImage (name, x- value, y - value, frame)
        //g.drawImage (background, 0, 0, this);
        g.drawImage (menu, 330, 350, this);
        if (menupos == 1)
        {
            System.out.println ("POS 1 v 2 TEST");
            g.drawImage (br, 290, 355, this);

        }
        if (menupos == 2)
        {
            System.out.println ("POS 2 V 2 TEST");
            g.drawImage (br, 290, 340, this);
        }
        if (menupos == 3)
        {
            System.out.println ("POS 3 V 2 TEST");
            g.drawImage (br, 290, 335, this);
        }



    } // paint method



} // Tronfinal class


The first bit is of course declaring images, than initializing them. the Position # V # test lines are just to output text into a different window when th eposition changes, as we can see, the original menu position is preset to 1, and does not change with button presses, thus the spam things pews Position 1 V 2 test.

Thanks for any help. I don't know if the event method is proper, and I am still somewhat confused about the execution flow of applets =X. So far it doesn't recognize any keyboard input, I followed the tutorial as what I thoug ht was properly, this is the link to it:: http://javaboutique.internet.com/tutorials/Java_Game_Programming/TastaturereignisseEng.html
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: