Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2
1  Discussions / General Discussions / Re: subtle blips while playing java games? on: 2007-11-01 03:57:24
Could be lots of issues. My guess would be gratuitous garbage collection.
2  Game Development / Game Play & Game Design / Library/JAR Question on: 2007-08-06 19:04:03
I've been thinking about something and hopefully some of the more experienced of you could lend me your knowledge.

Take for instance that you have a working FPS using some open-source libraries in JARs. I'm wondering if a malicious user could compile their own (jME for instance) with some extra modifications to give them an unfair advantage (wallhacks?). Is this possible? Is there a mechanism in Java to prevent this? Am I worrying too much?

Thanks Smiley
3  Game Development / Newbie & Debugging Questions / Re: Two Image Questions on: 2006-04-06 23:17:09
If I remember my Final Fantasy, I'm pretty sure it was always a general 'hurt' animation and an 'attack' animation....
4  Java Game APIs & Engines / OpenGL Development / Re: LWJGL and Microsoft's GDI Generic Renderer? on: 2006-04-06 22:01:06
Thanks for the reply. I'll try this from the command line, however I already call setProperty on this lwjgl property inside my initalization code. Can I not do this?

1  
2  
3  
4  
5  
6  
7  
8  
if( QConfiguration.getBoolean("allowsoftware", false) )
{
   System.setProperty("org.lwjgl.opengl.Window.allowSoftwareOpenGL", "True");
}
else
{
   System.setProperty("org.lwjgl.opengl.Window.allowSoftwareOpenGL", "False");
}
5  Java Game APIs & Engines / OpenGL Development / LWJGL and Microsoft's GDI Generic Renderer? on: 2006-04-06 12:59:08
Get guys, got a question for you, one that is confusing the hell out of me. Hopefully someone can help me.

I have a Dell PC over here that doesn't have a decent graphics chipset (Some obscure ATi integrated thing) and ends up using the GDI Generic as the renderer for anything OpenGL. So here's my question: Why can I not run anything LWJGL using this renderer? Here are some specs from GLView:

Quote
System Info
Windows XP Professional

Vendor
Microsoft Corporation
1.1.0

Renderer
GDI Generic

Extensions
GL_EXT_bgra
GL_EXT_paletted_texture
GL_WIN_swap_hint


Core features

v1.1 (100 % - 7/7)
v1.2 (12 % - 1/8)
v1.3 (0 % - 0/9)
v1.4 (0 % - 0/15)
v1.5 (0 % - 0/3)
v2.0 (0 % - 0/9)
OpenGL driver version check (Current: 6.13.3036, Latest known: 6.13.3036):
Latest version of display drivers found

According the database, you are running the latest display drivers for your video card.
No hardware support

Your current video configuration DOES NOT support hardware accelerated OpenGL.
No compiled vertex array support

This may cause performance loss in some applications.
No paletted texture support

This may cause performance loss in some older applications.
No multitexturing support

This may cause performance loss in some applications.
No secondary color support

Some applications may not render polygon highlights correctly.
No S3TC compression support

This may cause performance loss in some applications.
No texture edge clamp support

This feature adds clamping control to edge texel filtering. Some programs may not render textures correctly (black line on borders.)
No vertex program support

This feature enables vertex programming (equivalent to DX8 Vertex Shader.) Some current or future OpenGL programs may require this feature.
No fragment program support

This feature enables per pixel programming (equivalent to DX9 Pixel Shader.) Some current or future OpenGL programs may require this feature.
No OpenGL Shading Language support

This may break compatibility for applications using per pixel shading.
No Frame buffer object support

This may break compatibility for applications using render to texture functions.
Few texture units found

This may slow down some applications using fragment programs or extensive texture mapping.
Extension verification:
GL_EXT_color_subtable was not found, but has the entry point glColorSubTableEXT

GLView can also show render demos, but LWJGL just utterly refuses to cooperate. Any help or insight into this problem would be excellent. Wink
6  Game Development / Newbie & Debugging Questions / Re: New to Java, communicating through a Com port on: 2006-03-29 02:00:59
I had this issue when trying to figure out a way to sync a christmas light display using 16 SSRs with a computer. I ended up using the parallel port, but I found the Java communications API to rather unsuitable. Even though it for the parallel port, it does show you how to use some simple JNI if you didn't know before:

http://www.hytherion.com/beattidp/comput/pport.htm

I'm sure you could adapt that design, find some C code that'll ouput to a serial port on a Windows machine, and voila: You're in business.
7  Java Game APIs & Engines / OpenGL Development / Re: time based movement ,unstable delta calculation from sys.gettime on: 2006-03-20 14:51:20
I'm not sure what the underlying code is behind SystemTimer, but you might try System.nanoTime() from Java 5.0, if only for comparision purposes.
8  Game Development / Game Play & Game Design / Re: Engine Codebase Design on: 2006-03-20 14:46:16
Thanks, I'll take a look at that. I remember running across it, but haven't looked at it since.
9  Game Development / Game Play & Game Design / Engine Codebase Design on: 2006-03-20 04:47:36
Does anyone have any resources on this? Perhaps it's just something that must be learned through experience but I'm one to learn from other's mistakes. I'd really like to see how a real game engine is layed out and used in the context of a real game. Diagrams, flow-charts, all that good stuff would be great.

The reason I ask is that I can't find much in the way of game creation patterns. You can find anything else, pretty much, but design of the code itself seems to be left out altogether. And, as I understand it, from experience and looking around, a good codebase can help you through a lot of problems that otherwise could force to rewrite something.
10  Discussions / General Discussions / Re: LudumDare's 48hgame programming competition this weekend on: 2005-12-15 04:15:59
Whoo! Made a game Smiley Wish me luck.

http://ludumdare.com/wiki/index.cgi/JacobGohlkeFinal
11  Java Game APIs & Engines / Java 2D / Re: Trouble getting Active Rendering to perform quickly on: 2005-11-29 13:58:18
If the background image has no transparent parts to it, than you might consider using just a VolatileImage rather than a BufferedImage...
12  Java Game APIs & Engines / Java 2D / Re: Fullscreen Oddites on: 2005-11-27 18:30:09
Ahh, I'm sure someone else will be happy for that.

Right now though, I've completely transferred over to LWJGL. The only reason I might go back and revisit Java2D is if I want to make a Java2D wrapper that is also compatible with my OpenGL wrapper.
13  Game Development / Shared Code / Re: Some code.. on: 2005-11-25 06:08:53
some particle engine stuff

Excellent! :drools: Wink
I love to see how others implement things. This is just in time, too. I just finished my own particle system Cheesy
14  Java Game APIs & Engines / Tools Discussion / Re: Java IDE on: 2005-11-22 23:29:37
Well, that does it. I'm going to go get Eclipse and ditch JCreator...
15  Java Game APIs & Engines / OpenGL Development / Re: 32-bit Graphics, getting dithered down to 16-bit? on: 2005-11-22 18:04:25
Interesting, although I wouldn't want to disable anything on their hardware, so I'll leave it how it is now. Thanks though Wink
16  Discussions / Miscellaneous Topics / Re: Unwelcome reminder on: 2005-11-21 21:10:39
Well then... I'm just 16! My first gaming experience was on the NES, playing duck hunt. Damn that dog...

My first computer had Windows 95 on it, and I was acctually programming small C-Apps with it. (Think 'Hello World' and 'Console-Fireworks') I didn't get to have the joy of a command-line experience until I tryed out Linux. (Debian happens to be my favorite flavor, btw).

I feel young in this crowd...
17  Java Game APIs & Engines / OpenGL Development / Re: 32-bit Graphics, getting dithered down to 16-bit? on: 2005-11-21 10:23:20
EDIT:

Wow, I blame nVidia totally =D

I changed some driver settings, namely 'Image Quality' Smiley, and it magically works. Thanks for that recommendation!
18  Java Game APIs & Engines / OpenGL Development / Re: 32-bit Graphics, getting dithered down to 16-bit? on: 2005-11-20 16:53:00
Hmm, no such luck. I tried both suggestions, reinstalled nVidia drivers as well.
Well, it's not a big deal; But if you guys have any other guesses, please throw 'em at me Smiley Thanks anyway!

If I ever find the issue I'll post it here for reference.
19  Java Game APIs & Engines / OpenGL Development / 32-bit Graphics, getting dithered down to 16-bit? on: 2005-11-20 15:56:21
Hey guys, I just recently made the switch to LWJGL from Java2D and I have to say I love it Smiley

Anyway, I'm having a slight problem: My 32-bit graphics are getting dithered down to 16-bit, and then being displayed on my 32-bit screen. Argh! Any ideas?

Example:


I'll try to post any relevent code blocks as well:

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  
   public static QTexture fromFile( String name, boolean flip )
   {
      QTexture texture = null;
      ByteBuffer imageData = null;
      int ilImageHandle;
      int oglImageHandle;
      IntBuffer scratch = BufferUtils.createIntBuffer(1);
     
      try{
         IL.create();
         ILU.create();
         ILUT.create();
      } catch (LWJGLException ex) {
         
      }
      // create image in DevIL and bind it
     IL.ilGenImages(scratch);
      IL.ilBindImage(scratch.get(0));
      ilImageHandle = scratch.get(0);
     
      // load the image
     if( !IL.ilLoadImage( name ) )
         return null;
     
      // convert image to RGBA
     IL.ilConvertImage(IL.IL_RGBA, IL.IL_BYTE);
     
      // flip
     if( flip )
         ILU.iluFlipImage();
     
      // get image attributes
     int width = IL.ilGetInteger(IL.IL_IMAGE_WIDTH);
      int height = IL.ilGetInteger(IL.IL_IMAGE_HEIGHT);
      int textureWidth = QUtil.getNextPowerOfTwo(width);
      int textureHeight = QUtil.getNextPowerOfTwo(height);
     
      // resize image according to poweroftwo
     if (textureWidth != width || textureHeight != height)
      {
         imageData = BufferUtils.createByteBuffer(textureWidth * textureHeight * 4);
         IL.ilCopyPixels(0, 0, 0, textureWidth, textureHeight, 1, IL.IL_RGBA, IL.IL_BYTE, imageData);
      }
      else
         imageData = IL.ilGetData();
     
      // create OpenGL counterpart
     GL11.glGenTextures(scratch);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, scratch.get(0));
      oglImageHandle = scratch.get(0);
     
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
      GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, textureWidth, textureHeight, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, imageData);
     
      // Create image (either resized by copying, else directly from IL)
     if (textureWidth != width || textureHeight != height)
         texture = new QTexture(oglImageHandle, width, height, (width / (float) textureWidth), (height / (float) textureHeight), textureWidth, textureHeight);
      else
         texture = new QTexture(oglImageHandle, width, height);
     
      // delete Image in DevIL
     scratch.put(0, ilImageHandle);
      IL.ilDeleteImages(scratch);
      IL.destroy();
      ILU.destroy();
      ILUT.destroy();
     
      // revert the gl state back to the default so that accidental texture binding doesn't occur
     GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
     
      // return OpenGL texture handle
     return texture;
   }


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  
   public static void drawImage( QTexture tex, int x, int y )
   {
      if( color[3] == 0 )
         return;
      // store the current model matrix
     GL11.glPushMatrix();
     
      // translate to the right location and prepare to draw
     GL11.glTranslatef(x, y, 0);
      GL11.glColor4f( color[0], color[1], color[2], color[3] );

      if( ra != 0 && ra != 360 )
      {
         float rx1 = rx - x;
         float ry1 = ry - y;
         GL11.glTranslatef(rx1, ry1, 0);
         GL11.glRotatef( ra, 0, 0, 1 );
         GL11.glTranslatef(-rx1, -ry1, 0);
      }
      GL11.glEnable(GL11.GL_TEXTURE_2D);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureId() );
      GL11.glBegin(GL11.GL_QUADS);
      {
         GL11.glTexCoord2f( 0, 0 );
         GL11.glVertex2f( 0, 0 );
         
         GL11.glTexCoord2f( tex.getWidthRatio(), 0 );
         GL11.glVertex2f( tex.getWidth(), 0 );
         
         GL11.glTexCoord2f( tex.getWidthRatio(), tex.getHeightRatio() );
         GL11.glVertex2f( tex.getWidth(), tex.getHeight() );
         
         GL11.glTexCoord2f( 0, tex.getHeightRatio() );
         GL11.glVertex2f( 0, tex.getHeight() );
      }
      GL11.glEnd();
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0 );
      GL11.glDisable(GL11.GL_TEXTURE_2D);
      // restore the model view matrix to prevent contamination
     GL11.glPopMatrix();
   }
20  Java Game APIs & Engines / Java Sound & OpenAL / Re: Inward-pointing Normal Vector? on: 2005-11-20 00:23:14
I think you posted in the wrong forum  Grin

This is OpenAL, not OpenGL...
21  Java Game APIs & Engines / Java 2D / Re: Fullscreen Oddites on: 2005-11-19 02:14:06
I'm running in Windowed mode at 32-bit, according to Windows.

EDIT:
I'm going to repost the issue I'm having with OpenGL at the LWJGL forum.
22  Java Game APIs & Engines / Java 2D / Re: Fullscreen Oddites on: 2005-11-19 01:09:41
I've made lots of progress with LWJGL, but I have just one question. And a rather puzzling one at that (to an OpenGL-beginner anyway). When I draw images with OpenGL, it looks ... crappier, for lack of a better word, than it does in the picture. It almost looks like it was dithered to 256 colors and then brought back up to 32-bit. Any idea? Images:

Good:
Bad:

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  
   public static void drawImage( QTexture tex, int x, int y )
   {
      if( color[3] == 0 )
         return;
      // store the current model matrix
     GL11.glPushMatrix();
     
      // translate to the right location and prepare to draw
     GL11.glTranslatef(x, y, 0);  
      GL11.glColor4f( color[0], color[1], color[2], color[3] );
     
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureId() );
      GL11.glBegin(GL11.GL_QUADS);
      {
         GL11.glTexCoord2f( 0, 0 );
         GL11.glVertex2f( 0, 0 );
         
         GL11.glTexCoord2f( tex.getWidthRatio(), 0 );
         GL11.glVertex2f( tex.getWidth(), 0 );
         
         GL11.glTexCoord2f( tex.getWidthRatio(), tex.getHeightRatio() );
         GL11.glVertex2f( tex.getWidth(), tex.getHeight() );
         
         GL11.glTexCoord2f( 0, tex.getHeightRatio() );
         GL11.glVertex2f( 0, tex.getHeight() );
      }
      GL11.glEnd();
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0 );

      // restore the model view matrix to prevent contamination
     GL11.glPopMatrix();
   }


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  
import java.nio.*;
 
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.devil.*;
import org.lwjgl.*;

public class QTexture implements QDestroyable
{
   //...
 
   public static QTexture fromFile( String name, boolean flip )
   {
      QTexture texture = null;
      ByteBuffer imageData = null;
      int ilImageHandle;
      int oglImageHandle;
      IntBuffer scratch = BufferUtils.createIntBuffer(1);
     
      try{
         IL.create();
         ILU.create();
         ILUT.create();
      } catch (LWJGLException ex) {
         
      }
      // create image in DevIL and bind it
     IL.ilGenImages(scratch);
      IL.ilBindImage(scratch.get(0));
      ilImageHandle = scratch.get(0);
     
      // load the image
     //if(!IL.ilLoadFromURL(IL.class.getClassLoader().getResource(name)))
     //   return null;
     if( !IL.ilLoadImage( name ) )
         return null;
     
      // convert image to RGBA
     IL.ilConvertImage(IL.IL_RGBA, IL.IL_BYTE);
     
      // flip
     if( flip )
         ILU.iluFlipImage();
     
      // get image attributes
     int width = IL.ilGetInteger(IL.IL_IMAGE_WIDTH);
      int height = IL.ilGetInteger(IL.IL_IMAGE_HEIGHT);
      int textureWidth = QUtil.getNextPowerOfTwo(width);
      int textureHeight = QUtil.getNextPowerOfTwo(height);
     
      // resize image according to poweroftwo
     if (textureWidth != width || textureHeight != height)
      {
         imageData = BufferUtils.createByteBuffer(textureWidth * textureHeight * 4);
         IL.ilCopyPixels(0, 0, 0, textureWidth, textureHeight, 1, IL.IL_RGBA, IL.IL_BYTE, imageData);
      }
      else
         imageData = IL.ilGetData();
     
      // create OpenGL counterpart
     GL11.glGenTextures(scratch);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, scratch.get(0));
      oglImageHandle = scratch.get(0);
     
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
      GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, textureWidth, textureHeight, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, imageData);
     
      // Create image (either resized by copying, else directly from IL)
     if (textureWidth != width || textureHeight != height)
         texture = new QTexture(oglImageHandle, width, height, (width / (float) textureWidth), (height / (float) textureHeight), textureWidth, textureHeight);
      else
         texture = new QTexture(oglImageHandle, width, height);
     
      // delete Image in DevIL
     scratch.put(0, ilImageHandle);
      IL.ilDeleteImages(scratch);
      IL.destroy();
      ILU.destroy();
      ILUT.destroy();
     
      // revert the gl state back to the default so that accidental texture binding doesn't occur
     GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
     
      // return OpenGL texture handle
     return texture;
   }
}
23  Java Game APIs & Engines / Java 2D / Re: Fullscreen Oddites on: 2005-11-15 01:39:30
Great link! Again, Thanks.

Acctually, I prefer Targa to PNG, I acctually chose PNG as ImageIO doesn't have a Targa-reader (that I've found).

Only one thing that I don't like is pre-game/in-game image manipulation. Maybe it's just bad practice, but in this game I split a single image, namely a brick image, into several smaller parts that I use as a particle system to 'spray out' when a brick is hit. Cool effect, but I don't see how this could be possible with that loader. I also pre-rotate the paddle-image to -45 and 45 degrees of movement for some very smooth movement effects. (I saw something about a 'rotated-quad', somewhere, but I don't want to have to detect collisions for that, and leave it as a rectangle-pixel perfect) So, if you have any leads on how to get the best of both worlds, please let me know.
24  Java Game APIs & Engines / Java 2D / Re: Fullscreen Oddites on: 2005-11-14 14:35:22
Roger.  Wink Thanks for that.

Well, I've started converting the project over to LWJGL. OpenGL doesn't seem that hard, and I've already got a 'wire-frame' with alpha-blending and LWJGL's jinput wrapper working. The new OpenGL coordinate system annoys me though, as I'm so ingrained in the Java2D way of doing things... That and I have no idea how to load an OpenGL texture from a BufferedImage... Back to the red-book  Smiley !
25  Java Game APIs & Engines / Java 2D / Re: Fullscreen Oddites on: 2005-11-12 23:51:58
The problem seems to only occur when I have something with an alpha other than 0 or 255 being drawn. This includes BufferedImages and AlphaComposites. Otherwise, I get a 2x increase in framerate. Any idea? This slowdown doesn't occur so severely outside of fullscreen.

Also, there doesn't seem to be any leads about the KeyListener problem. I might have to switch over to jinput if I want to continue fullscreen support here, I suppose.
26  Java Game APIs & Engines / Java 2D / Re: Fullscreen Oddites on: 2005-11-10 02:41:49
I'll try and do that this weekend. Thanks for the responses.

This is Windows, XP to be exact.
27  Java Game APIs & Engines / Java 2D / Re: Fullscreen Oddites on: 2005-11-06 06:25:07

Input.java
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  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
/*
 *   Input Class
 *
 *   Allows for polling-input rather than event-driven input. This is an
 *   esspecially important concept of games that is missing in vanilla-Java.
 */


import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class Input implements MouseMotionListener, MouseListener, KeyListener, MouseWheelListener
{
   public static void init()
   {
      typedKeys = new ArrayList<Integer>();
      wheelUnits = 0;
      mouseBtns = new ArrayList<Integer>();
      mousePosition = new Point(0, 0);
   }
   
   private static ArrayList<Integer> typedKeys;
   
   protected static synchronized void  addKey( int key )
   {
      if( !isKeyDown(key) )
         typedKeys.add( new Integer(key) );
   }
   
   protected static synchronized void removeKey( int key )
   {
      for( int i = 0; i < typedKeys.size(); i++ )
      {
         if( typedKeys.get(i).intValue() == key )
         {
            typedKeys.remove(i);
            return;
         }
      }
   }
   
   public static boolean isKeyDown( int key )
   {
      for( int i = 0; i < typedKeys.size(); i++ )
      {
         if( typedKeys.get(i).intValue() == key )
            return true;
      }
      return false;
   }
   
   private static int wheelUnits;
   
   protected static synchronized final void setWheelMoved( int i )
   {
      wheelUnits = i;
   }
   
   public static final int getWheelMoved()
   {   // Read-Once method, for reacting to the mouse wheel properly
     int i = wheelUnits;
      wheelUnits = 0;
      return i;
   }
   
   private static ArrayList<Integer> mouseBtns;
   
   protected static synchronized void addMouseButton( int key )
   {
      if( !isMouseButtonDown(key) )
         mouseBtns.add( new Integer(key) );
   }
   
   protected static synchronized void removeMouseButton( int key )
   {
      for( int i = 0; i < mouseBtns.size(); i++ )
      {
         if( mouseBtns.get(i).intValue() == key )
         {
            mouseBtns.remove(i);
            return;
         }
      }
   }
   
   public static boolean isMouseButtonDown( int key )
   {
      for( int i = 0; i < mouseBtns.size(); i++ )
      {
         if( mouseBtns.get(i).intValue() == key )
            return true;
      }
      return false;
   }
   
   private static Point mousePosition;
   
   protected static synchronized void setMousePosition( Point p )
   {
      mousePosition = p;
   }
   
   public static final Point getMousePosition()
   {
      return new Point( (int)mousePosition.getX(), (int)mousePosition.getY() );
   }
   
   public static final Vector2D getMouseVector2D()
   {
      return new Vector2D( (int)mousePosition.getX(), (int)mousePosition.getY() );
   }
   
   public static final int getMouseX()
   {
      return (int)mousePosition.getX();
   }
   
   public static final int getMouseY()
   {
      return (int)mousePosition.getY();
   }

   /*
    *   KeyListener Methods
    */

   
   public void keyPressed( KeyEvent evt )
   {
      Input.addKey( evt.getKeyCode() );
   }
   
   public void keyReleased( KeyEvent evt )
   {
      Input.removeKey( evt.getKeyCode() );
   }
   
   public void keyTyped( KeyEvent evt ) {}
   
   /*
    *   MouseListener Methods
    */

   
   public void mouseClicked( MouseEvent evt ) {}
   
   public void mouseEntered( MouseEvent evt )
   {
      Input.setMousePosition( evt.getPoint() );
   }
   
   public void mouseExited( MouseEvent evt )
   {
      Input.setMousePosition( evt.getPoint() );
   }
   
   public void mousePressed( MouseEvent evt )
   {
      Input.addMouseButton( evt.getButton() );
   }
   
   public void mouseReleased( MouseEvent evt )
   {
      Input.removeMouseButton( evt.getButton() );
   }
   
   /*
    *   MouseMotionListener Methods
    */

   
   public void mouseDragged( MouseEvent evt )
   {
      Input.setMousePosition( evt.getPoint() );
   }
   
   public void mouseMoved( MouseEvent evt )
   {
      Input.setMousePosition( evt.getPoint() );
   }
   
   /*
    *   MouseWheelListener Methods
    */

   
   public void mouseWheelMoved( MouseWheelEvent evt )
   {
      Input.setWheelMoved( evt.getWheelRotation() );
   }
}


There is more, of course, but I don't think it's relevant.
28  Java Game APIs & Engines / Java 2D / Fullscreen Oddites on: 2005-11-06 06:24:45
Well, I'm working on a small Java2D-AWT-based breakout clone and I have a few problems, maybe you can help me with them.

I designed the game engine with fullscreen or windowed mode in mind, but developed mainly in windowed. When I try to switch to fullscreen now, keyboard-input does not work, and my performance goes from somewhere in the 40-60FPS range to 5-15FPS. It's very puzzling, as I thought fullscreen exclusive was supposedly faster than windowed, and there doesn't seem to be any cause of the keyboard-input problem.


ScreenCanvas.java
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  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263  
264  
265  
266  
267  
268  
269  
270  
271  
272  
273  
274  
275  
276  
277  
278  
279  
280  
281  
282  
283  
284  
285  
286  
287  
288  
289  
290  
291  
292  
293  
294  
295  
296  
297  
298  
299  
300  
301  
302  
303  
304  
305  
306  
307  
308  
309  
310  
311  
312  
313  
314  
315  
316  
317  
318  
319  
320  
321  
322  
323  
324  
325  
326  
327  
328  
329  
330  
331  
332  
333  
334  
335  
336  
337  
338  
339  
340  
341  
342  
343  
344  
345  
346  
347  
348  
/*
 *   ScreenCanvas Class
 *
 *   Used to encapsulate the process of setting up and showing frame renders,
 *   multi-buffering, and everything related to graphics.
 */

 
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.*;

public class ScreenCanvas extends Frame
{  
   protected static int width;
   protected static int height;
   protected static int fps;
   protected static boolean instance = false;
   
   public static int getScreenWidth()
   {
      return width;
   }
   
   public static int getScreenHeight()
   {
      return height;
   }
   
   public static int getFPS()
   {
      return fps;
   }

   public static ScreenCanvas getInstance()
   {
      if( !instance )
         return new ScreenCanvas();
      return null;
   }

   public static ScreenCanvas getInstance( String title )
   {
      if( !instance )
         return new ScreenCanvas( title );
      return null;
   }

   private GraphicsEnvironment env;
   private GraphicsDevice device;
   private GraphicsConfiguration gc;
   
   private BufferStrategy bufferStrategy;
   
   private DisplayMode fullscreenMode;
   private DisplayMode windowedMode;
   private DisplayMode displayMode;
   
   private int fps_max;
   
   //private double fps_avg = 0;
   
   private long startTime;
   private long endTime;
   private long wantedEndTime;
   
   private Canvas canvas;
   
   private Component raster;
   
   private boolean debug;
   
   protected ScreenCanvas()
   {
      this( "" );
   }
   
   protected ScreenCanvas( String title )
   {
      ScreenCanvas.instance = true;
      debug = Configuration.getBoolean("debug", false);
      ScreenCanvas.fps = 0;
      fps_max = Utility.clamp( Configuration.getInteger( "fps_max", 0 ), 0, 1000 );
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
            cleanup();
         }
      });
     
      setBackground( Color.black );
      setIgnoreRepaint( true );
      setResizable( false );
      setFocusable( false );
     
        env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        device = env.getDefaultScreenDevice();
        gc = device.getDefaultConfiguration();
       
        int bitDepth     = device.getDisplayMode().getBitDepth();
        int refreshRate  = device.getDisplayMode().getRefreshRate();
       
        fullscreenMode = new DisplayMode( Configuration.getInteger("fs_res_w", 1024), Configuration.getInteger("fs_res_h", 768), bitDepth, refreshRate );
      windowedMode = new DisplayMode( Configuration.getInteger("wnd_res_w", 1024), Configuration.getInteger("wnd_res_h", 768), bitDepth, refreshRate );
     
      if( Configuration.getBoolean("fakefullscreen", false) )
      {
         //Setup fake-fullscreen
        setupFakeFullscreen();
      }
      else if( Configuration.getBoolean("fullscreen", false) && device.isFullScreenSupported() )
      {
         //Setup fullscreen
        setupFullscreen();
      }
      else
      {
         //Setup windowed
        setupWindowed();
      }
     
      if( !isVisible() )
         setVisible( true );
     
      if( canvas == null )
      {
           createBufferStrategy( Configuration.getInteger("buffers", 2) );
           bufferStrategy = getBufferStrategy();
      }
      else
      {
           canvas.createBufferStrategy( Configuration.getInteger("buffers", 2) );
           bufferStrategy = canvas.getBufferStrategy();
      }
     
      ScreenCanvas.width = raster.getWidth();
      ScreenCanvas.height = raster.getHeight();
      raster.addKeyListener( new Input() );
      raster.addMouseListener( new Input() );
      raster.addMouseMotionListener( new Input() );
      raster.addMouseWheelListener( new Input() );
      requestFocus();
       
        try{
           Thread.sleep(375);
        } catch(Exception e) {}
       
       Console.echo( Console.VERBOSE, "ScreenCanvas Initialized" );
       setTitle( title );
   }
   
   public void cleanup()
   {
      if( device.getFullScreenWindow() != null )
         device.setFullScreenWindow(null);
         
      bufferStrategy = null;
      ScreenCanvas.instance = false;

      setVisible(false);  
      dispose();
   }
   
   private void setupWindowed()
   {
       Console.echo( Console.NORMAL, "Using Windowed Mode" );
       
       Insets windowInsets = Toolkit.getDefaultToolkit().getScreenInsets( gc ); //Use these insets to correct the 'odd' space left around borders...
     setSize( windowedMode.getWidth() + windowInsets.left + windowInsets.right, windowedMode.getHeight() + windowInsets.top + windowInsets.bottom );
           
       canvas = new Canvas();
        canvas.setBackground( Color.black );
        canvas.setIgnoreRepaint( true );
        canvas.setFocusable( true );
      canvas.setSize( windowedMode.getWidth(), windowedMode.getHeight() );
      canvas.setLocation( 0, 0 );
        add( canvas );
       
        raster = canvas;
        displayMode = windowedMode;
   }
   
   private void setupFullscreen()
   {
       Console.echo( Console.NORMAL, "Using Fullscreen Mode" );
       
      setUndecorated(true);
      if( device.isFullScreenSupported() )
         device.setFullScreenWindow(this);
     
      if( device.isDisplayChangeSupported() )
      {
         if( isDisplayModeSupported( fullscreenMode ) )
            device.setDisplayMode( fullscreenMode );
      }
     
      setSize( fullscreenMode.getWidth(), fullscreenMode.getHeight() );
       
        raster = this;
        canvas = null;
        displayMode = fullscreenMode;
   }
   
   private void setupFakeFullscreen()
   {
       Console.echo( Console.NORMAL, "Using Fake Fullscreen Mode" );
       
      setUndecorated( true );
     
      if( device.isDisplayChangeSupported() ) // Well, if we can change it without going into the
     {                              // Fullscreen exclusive mode, do it. (Probably not though)
        if( isDisplayModeSupported( fullscreenMode ) )
            device.setDisplayMode( fullscreenMode );
      }
     
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      setSize( (int)screenSize.getWidth(), (int)screenSize.getHeight() );
     
       canvas = new Canvas();
        canvas.setBackground( Color.black );
        canvas.setIgnoreRepaint( true );
        canvas.setFocusable( true );
      canvas.setSize( getSize() );
      canvas.setLocation( 0, 0 );
        add( canvas );
       
        raster = canvas;
        displayMode = new DisplayMode( (int)screenSize.getWidth(), (int)screenSize.getHeight(), fullscreenMode.getBitDepth(), fullscreenMode.getRefreshRate() );
   }
   
    private boolean isDisplayModeSupported( DisplayMode dm )
    {
        DisplayMode[] modes = device.getDisplayModes();
        for (int i = 0; i < modes.length; i++)
        {
            if (dm.getWidth() == modes[i].getWidth() && dm.getHeight() == modes[i].getHeight() && dm.getBitDepth() == modes[i].getBitDepth() && dm.getRefreshRate() == modes[i].getRefreshRate())
                return true;
        }
        return false;
    }
   
    public void setCursorVisible( boolean b )
    {
       if( b )
       {
          setCursor( Cursor.getDefaultCursor() );
       }
       else
       {
         int[] pixels = new int[16 * 16];
         Image image = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(16, 16, pixels, 0, 16));
         Cursor transparentCursor = Toolkit.getDefaultToolkit().createCustomCursor(image, new Point(0, 0), "");
          setCursor( transparentCursor );
       }
    }
   
    public void setCustomCursor( ARGBImage img )
    {
      int[] pixels = img.toIntArray();
      Image image = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(16, 16, pixels, 0, 16));
      Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(image, new Point(0, 0), "");
       setCursor( cur );
    }

    public Graphics2D getGraphics()
    {
      if( bufferStrategy != null )
      {
         Graphics2D g = (Graphics2D)bufferStrategy.getDrawGraphics();
         g.setClip( new Rectangle( 0, 0, raster.getWidth(), raster.getHeight() ) );
         return g;
      }
      return null;
    }

    public void StartFrame()
    {
      if( bufferStrategy == null )
         return;
         
      startTime = Utility.currentTimeMillis();
     
      Graphics2D g = getGraphics();
      if(g == null)
         return;
         
      g.setColor( getBackground() );
      g.fillRect( 0, 0, raster.getWidth(), raster.getHeight() );
    }

    public void EndFrame()
    {
      if( bufferStrategy == null || bufferStrategy.contentsLost() )
         return;
     
      Graphics2D g = getGraphics();
      if(g == null)
         return;
         
      if( debug )
      {
         Console.render( g );
         DynamicGrid.render( g );
      }
     
      if( bufferStrategy != null && !bufferStrategy.contentsLost() && isVisible() )
         bufferStrategy.show();
         
      endTime = Utility.currentTimeMillis();
      if( fps_max > 0 )
      {
         wantedEndTime = ( 1000 / fps_max ) + startTime;
         while( wantedEndTime > endTime )
         {
            endTime = Utility.currentTimeMillis();
         }
      }
     
      if( endTime != startTime )
         ScreenCanvas.fps = Utility.clamp( (int)( 1000 / (endTime - startTime) ), 1, Integer.MAX_VALUE );
      else
         ScreenCanvas.fps = 1000;
         
      TimerSystem.update();
     
      /*if( fps_avg != 0)
      {
         fps_avg += ScreenCanvas.fps;
         fps_avg /= 2;
      }
      else
      {
         fps_avg = ScreenCanvas.fps;
      }*/

   }
   
   public void setDebug( boolean b )
   {
      debug = b;
   }
   
   public boolean getDebug()
   {
      return debug;
   }
   
   public void update( Graphics g ) {}
   public void paint( Graphics g ) {}
}

29  Games Center / Archived Projects / Re: First Fullscreen Game on: 2005-04-30 16:52:00
Thanks for all that input. I'll see if I can't put in the line collision detection. I'm not sure about the last level loading time, it all depends on the computer I suppose.
30  Games Center / Archived Projects / First Fullscreen Game on: 2005-04-29 21:24:20
Hey, I've been working on a game for my computer science class and I'd like any input you guys have on it. It's sort of a Sonic The Hedgehog-esqe game, and I'd like to share it here. I named it 'Java Quest' after the language I programmed it in. First, some background:

- The teacher of my computer science class is named 'Steve Shannon' and I choose one of my friends in that class to be the main character, 'Nick Wood'. The author of the text-book, Exposure Java, is named 'Leon Schram'. Basically I was bored in Algebra 2 and I started writing a story line. It mostly consisted of Nick falling asleep while coding a lab assignment, but he still coded in his sleep. This code compiled to a portal into an alternate universe inside the computer. You later find out that he only activated a virius planted by Schram in his computer. Also, there is a slight inside joke in story line. 'Schram should Scram' is a little rhyme Nick yelled out during a test Wink Everything is original, down to the last sprite animation. (Except the music, which I got from http://www.flashkit.com/)

My entire class loved it, hope you enjoy it as well.

And with out further ado, my 3 weeks of hard work:




Download Link:
http://modx.ath.cx:1337/JavaQuest.zip

All source code is included if you're curious. I've built it with the JDK 1.4_07. To run the game, run the included 'run.bat' file.

(I know the sprite graphics aren't that good-looking, but I'm not in a Graphics Design class... I think the awesome particle system makes up for it though Smiley

Legal Garbage: Java is a registred trademark of Sun ... blah blah ...

Known Bugs: If you hit a tile just right you will go straight though it. I've not a clue how this happens, but it does.
Pages: [1] 2
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (22 views)
2014-09-19 03:14:18

Dwinin (37 views)
2014-09-12 09:08:26

Norakomi (65 views)
2014-09-10 13:57:51

TehJavaDev (91 views)
2014-09-10 06:39:09

Tekkerue (45 views)
2014-09-09 02:24:56

mitcheeb (66 views)
2014-09-08 06:06:29

BurntPizza (49 views)
2014-09-07 01:13:42

Longarmx (36 views)
2014-09-07 01:12:14

Longarmx (42 views)
2014-09-07 01:11:22

Longarmx (38 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!