Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (767)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (854)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Gage game menu  (Read 4656 times)
0 Members and 1 Guest are viewing this topic.
Offline minderaser

Junior Newbie




Java games rock!


« Posted 2003-07-10 21:01:58 »

Hi,
I was wondering if any one has made a game menu to go with gage?
I've been trying for some time but i don't think i have the code correct.
Also wondering if anyone has came upon a timer problem with gage.
I used the map example to start a demo but the timer it uses makes my game slow down after compiling a couple times.
It sometimes causes problems with DirectX 7, then again i'm using integrated video so that might be my problem.
Offline SpuTTer

Senior Devvie


Medals: 1
Exp: 14 years


Lazy Middle Class Intellectual


« Reply #1 - Posted 2003-07-10 22:01:58 »

What timer problem are you experiencing? Give us some specifics so we can help! I have no problems with the gage timer. Do you have the timer.dll in your startup directory or jar?

As far as a game menu with GAGE, I dont think GAGE has anything specific to use, but you should be able to build a menu that launches the game or whatever without using GAGEs code.

Sacramento Volleyball
"Whitty phrase goes here."
Offline Abuse

JGO Ninja


Medals: 70


falling into the abyss of reality


« Reply #2 - Posted 2003-07-10 23:19:08 »

GageMenu,

great idea!

There u go jbanes; your next project  Grin
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #3 - Posted 2003-07-11 00:54:07 »

Quote
GageMenu,

great idea!

There u go jbanes; your next project  Grin


Wonderful. Now people are *assigning* me work.  Roll Eyes

I was working on an API called "GAGEGui", but I haven't yet been able to work out a design I like. Until I figure it out, do like the Romans do. Write your own.  Grin

Java Game Console Project
Last Journal Entry: 12/17/04
Offline krypto

Junior Devvie




while(true) { self.caffeinate (); }


« Reply #4 - Posted 2003-07-11 08:26:19 »

Long Post Here We Go:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
/*
 * DefaultMenu.java
 *
 * Created on April 3, 2003, 8:10 AM
 */


package com.krypto.k2.graphics.menu;

import java.awt.*;
import java.awt.event.KeyEvent;
import com.krypto.k2.graphics.*;

/**
 *
 * @author  Krypto
 */

public class DefaultMenu implements GFXMenu, GFXConstants
{

    public String name = "";
    public boolean visible = false;
    public Color color = new Color(0.5f,1.0f,0.5f,0.5f);
    public String[] menuItems = null;
    public int selected = 0;
   
    /** Creates a new instance of DefaultMenu */  
    public DefaultMenu (final String _name, final String[] _menuItems)
    {
        name = _name;
        menuItems = _menuItems;
    }
   
   
   
    /** Returns Color of menu
     * @return
     *
     */

    public java.awt.Color getColor ()
    {
        return color;
    }
   
    /** returns selected menu item
     * @return index of selected item
     *
     */

    public int getSelectedMenuItem ()
    {
        return selected;
    }
   
    /** Used to recive key input
     * @param kE
     *
     */

    public void triggerKeyEvent (KeyEvent kE)
    {
        switch (kE.getKeyCode ())
        {
           
            case KeyEvent.VK_UP:
               
                if(selected != 0)
                {
                    selected--;
                }
                break;
               
            case KeyEvent.VK_DOWN:
               
                if(selected < menuItems.length - 1)
                {
                    selected++;
                }
                break;                
        }
    } // implement specialties in subclasses
   
    public void draw (Graphics g)
    {
        if(visible)
        {
        Font myFont=new Font ("Arial",Font.BOLD,24);
        g.setFont (myFont);
        FontMetrics myMetrics = g.getFontMetrics ();
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
       
        int longest=0;
        int numItems = menuItems.length;
           
        String longestString = menuItems[0];
        {
            for(int i =0;i<numItems;i++)
            {
                int temp = menuItems[i].toCharArray ().length;
             
                if (temp>longest)
                {
                    longest = temp;
                    longestString = menuItems[i];
                }
            }            
        }
                 
        int mX,mY,mW,mH,center;
        mW = myMetrics.stringWidth (longestString) + 40;
        mH = numItems*myMetrics.getAscent () + 40 ;
        mX = (int)((GFXEngine.screenWidth - mW)/2);
        mY = (int)((GFXEngine.screenHeight - mH)/2);
        center =(int)(myMetrics.stringWidth (longestString)/2);
               
        g.setColor (color);
        //g.clearRect(mX,mY,mW,mH);
        g.fillRoundRect (mX,mY,mW,mH,20,20);            
       
       
        int offset;
        for(int i =0;i<menuItems.length;i++)
        {
            offset=center-(int)(myMetrics.stringWidth (menuItems[i])/2);
         
            if(i == selected)
            {
               g.setColor (Color.WHITE);
            }
            else
            {
               g.setColor (Color.BLACK);
            }
           
            g.drawString (menuItems[i],
                          mX+20+offset,
                          mY+myMetrics.getAscent() + i*myMetrics.getHeight() + 10);
        }
       
       }
    }
}


of Course I didn't include the interface code, or listener code. But this should give you a good place to start. As for JBanes, you guys leave him alone, so he'll have free time to help me some more, as he always has Wink

JRPG Users -  General Users Site
JRPG Developers -  The JRPG Project's Home
Offline minderaser

Junior Newbie




Java games rock!


« Reply #5 - Posted 2003-07-11 17:31:09 »

Thanks for the menu code haven't tried it but i see i have a lot of work to do.
This is the timer error i get after trying to run my demo
I just shorted the directories com.gage... instead of com.dsalinas... if thats where i went wrong please tell me.
Also my timer.dll is in my bin folder along with the jar
and my project file.
Note also that i am using the old gage files i haven't downloaded the newest release.
___________________________________________
Windows 98
java.lang.UnsatisfiedLinkError: getResolution
     at com.gage.timer.windows.WindowsTimer.getResolution(Native Method)
     at com.gage.timer.AdvancedTimer.getTicksPerSecond(AdvancedTimer.java:192)
     at Shooter.run(Shooter.java:144)
     at Shooter.main(Shooter.java:98)
Offline kevglass

« JGO Spiffy Duke »


Medals: 319
Projects: 25
Exp: 22 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #6 - Posted 2003-07-11 17:39:18 »

Quote

I just shorted the directories com.gage... instead of com.dsalinas... if thats where i went wrong please tell me.


Thats wrong. Smiley That'll be the problem I'd have thought.

Kev

Offline minderaser

Junior Newbie




Java games rock!


« Reply #7 - Posted 2003-07-11 17:50:05 »

ok what i did was make all the gage folders to shorter folders instead of the com.dsalinas...folders
i just made com.gage folders.
otherwise it wouldn't compile and i'd get lots more errors.
i also changed the code in my import and package calls to match the folders i have them in.
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #8 - Posted 2003-07-12 00:43:33 »

If you change the package of the WindowsTimer, you'll need to recreate the RMI stubs and recompile the C code. You probably don't want to do that.

Java Game Console Project
Last Journal Entry: 12/17/04
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #9 - Posted 2003-07-12 16:05:55 »

Jbanes meant to say JNI stubs. RMI if for calling methods from a different machine over a network.

The name of the C functions for native methods contain the entire fully qualified name of the class and method.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #10 - Posted 2003-07-13 03:12:06 »

Thanks for the correction SW.  Smiley Guess I had my mind on something else.  Embarrassed  Smiley

Java Game Console Project
Last Journal Entry: 12/17/04
Offline minderaser

Junior Newbie




Java games rock!


« Reply #11 - Posted 2003-07-14 17:04:57 »

Ok so i solved my timer problem by getting the latest gage release and leaving the folders alone.
I then made a copy of the shooter example and started from there. I included the gage jar files in my classpath for my project and i have everything up and running.
I have two problems though:
1. I try to compile it to a MS-DOS batch file->shooter.bat
but i get an error when i try running it without using my IDE/Compiler.
Error:"Exception in thread "main" java.lang.NoClassDefFoundError"

2.I try creating the jar file Shooter.jar but it dosn't work
when i try running it.
Error:"could not find main class program will exit"

Remeber i'm using the shooter folders i have my project file in the bin folder but my shooter.java and class in the source folder.
I've tried adding the shooter.class and shooter.java files to the bin then creating the jar and batch file but still recieve the same errors.

Just one last thing, I created a very simple menu for my project nothing fancy just an image with simple options
like press enter to start, press escape to quit.If anyone is interested i will display the basic code for it. I don't really know if it's the correct way but it works for me.
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #12 - Posted 2003-07-14 17:41:19 »

Time to head back to school for classpaths. Smiley You see, the JVM has to have a way of finding the classes it uses. The way it does this is via a mechanism called the "Classpath". The classpath is simply a list of directories or JAR files that the JVM searches to find what it wants. Let's take this example:

java Shooter

This will most likely fail with the error "Could not find class Sprite" or something along those lines. The solution is to pass the following classpath:

java -cp ..\libs\gage2d.jar;. Shooter

Above, we passed ..\libs\gage2d.jar and the currect directory as classpaths.  When the JVM runs it will first look in gage2d.jar for Shooter.class. If it doesn't find it, it will move on to the current directory and find it there. After that, it will start loading GAGE classes and again look first in gage2d.jar. This time it will find the classes in the jar file. If a class exists that it can't find in gage2d.jar or the current directory, it will throw an error. BTW, you'll note that we used a semicolon for a separator. This changes depending on the OS. Unix type OSes use semicolons instead.

So how come the JAR worked, you ask? Because the JAR contained a special file called a Manifest. The manifest has all the commands in it that you'd normally have to pass to the command line. For example, shooter comes with a file called "shooter.mf" in the source directory. It looks something like this:

Main-Class: Shooter
Class-Path: ../lib/sound.jar ../lib/gage2d.jar ../lib/timer.jar ../lib/Resources.jar

The "Main-Class" attribute tells the JVM the class to run. The "Class-Path" attribute does what it sounds like and passes a list of paths/JARs to look for files in. You'll note that in this case the path separator is a space. To use this manifest, we simply add the "m" command to the JAR program. i.e.:

jar -cvmf shooter.mf ..\bin\shooter.jar *.class

More info can be found here:

http://java.sun.com/docs/books/tutorial/jar/basics/run.html

Good luck!

Java Game Console Project
Last Journal Entry: 12/17/04
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1303 views)
2018-06-10 19:43:48

EgonOlsen (1161 views)
2018-06-10 19:43:44

EgonOlsen (900 views)
2018-06-10 19:43:20

DesertCoockie (1301 views)
2018-05-13 18:23:11

nelsongames (1106 views)
2018-04-24 18:15:36

nelsongames (1337 views)
2018-04-24 18:14:32

ivj94 (2079 views)
2018-03-24 14:47:39

ivj94 (1231 views)
2018-03-24 14:46:31

ivj94 (2212 views)
2018-03-24 14:43:53

Solater (798 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!