Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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  Game Development / Newbie & Debugging Questions / Re: aiming? could call it homing missiled I guess on: 2009-03-05 23:53:08
h3ckboy, I don't know how old you are, but it would be a good idea to start looking into the basics of trigonometry and kinematics. Vectors and motion are vital to game development, so understanding these things will prove immensely useful; besides, it cant hurt to get ahead  Grin
2  Games Center / 4K Game Competition - 2009 / Re: Invaders on: 2009-02-23 19:05:23


Look ma, an infinite queue!  By leaving the window with fire pressed, I don't even have to hold the button.

But, seriously, its a quite a good game; I used to love Gauntlet.
3  Game Development / Newbie & Debugging Questions / Re: Key types while in a loop on: 2009-02-19 01:54:33
I'm not entirely sure, but I think your problem is caused by not using

try{Thread.sleep(sleepTime);}catch(InterruptedException e){}

at the end of each cycle, which means the CPU is choked by the loop and doesn't have time to process KeyEvents .  I believe I've had the same thing happen when omitting that part of game loops.
4  Game Development / Newbie & Debugging Questions / Re: Game graphics on: 2009-02-17 16:34:40
If you just draw things in the component you can do whatever you want, even pixel-by-pixel drawing. Then you can also put various buttons and things around the drawn component too, if you want.

That's perfectly reasonable, but I've always had problems with Java's layout managers trying to be intuitive and failing miserably with random locations and more especially sizes  (again, this is before I found out that I could disable that completely).  Being able to throw together a multi-panel layout myself was quicker than arguing.  Really though, I would assume that your way is the preferred/standardized way of going about drawing.

Side question: would my implementation have any relevant inherent effects on image-rendering speed?  Everyone says Java2D sucks, but a single frame-size background would make my fps plummet from 90 to about 40, which has always struck me as ridiculous. 
5  Game Development / Newbie & Debugging Questions / Re: Game graphics on: 2009-02-17 06:05:44
I think I had similar problems when I started using java for games, here's what I generally did (in some form or another)
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  
class Game extends Canvas implements KeyListener
{
    public Game()
    {
       JFrame frame = new JFrame("The Tomb of Argmet");
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       JPanel panel = (JPanel)frame.getContentPane();
       panel.setLayout(null);
       panel.setPreferredSize(new Dimension(505,505));
       panel.setBackground(Color.black);
       addKeyListener(this);
       setBounds(25,25,480,480);
       panel.add(this);
       setIgnoreRepaint(true);
       frame.pack();
       frame.setResizable(false);
       frame.setVisible(true);
       requestFocus();
       createBufferStrategy(2);
       strategy = getBufferStrategy();
   }
   public void loop()
   {
      while(true)
      {
         Graphics2D g = (Graphics2D)strategy.getDrawGraphics();
          long delta = (System.nanoTime()-lastLoopTime)/1000000;
          lastLoopTime = System.nanoTime();

         //update logic
        //draw screen

         g.dispose();
         strategy.show();

         try{Thread.sleep(100);}catch(InterruptedException e){}
      }
   }
}


Basically you just take the Canvas as your starting point, leave the Graphics code as a black-box situation, and lay things out exactly how you want.  I believe I picked this up from http://www.cokeandcode.com/spaceinvaderstutorial which is a really great tutorial for starting with java gaming.

I almost always used entity/widget/holder classes that over-ride a draw(Graphics g) and/or update(long delta) so I could just pass the Graphics down (events too).  Oh and if you haven't heard, plain Java and images don't seem to be on friendly terms.

Oh, there's something else you can throw into Thread.sleep() to get steady fps, but its simple and I don't want to reboot to look it up at the moment...

Graphics is pretty easy to deal with (assuming you're talking about java.awt.Graphics).

Basically, every time step or so you call repaint() within any JComponent. The component should also override its paintComponent(Graphics g) or paint(Graphics g) method, and in there you should draw everything out. Whatever you draw last appears on top. There's not much more to it.

I don't like doing that after a few to many fights to get java to let me place things like I want, but that was before I knew setLayout(null) would get me absolute positioning.  Having to recreate text-boxes/progress-bars/buttons on your own is also good experience.
6  Games Center / 4K Game Competition - 2009 / Re: Ultimate Tic-Tac-Toe on: 2009-02-09 05:32:15


Got it on the first try  Grin

However, I lost the next 4 times I played. Since the only time I went first was the only time I won, I wonder if the first player has the ability to force a win.  I'll have to think about that...
7  Game Development / Newbie & Debugging Questions / Re: global variable on: 2009-02-03 14:24:47
That is initializing the array

int[] arr;

is declaring it.

Also, this works

Object[] arr = {new String("HI"),new Integer("HI")};

Renoria was at least right on that part (though he did declare a new array)

Edit: I take that second part back, I forgot about that annoying caveat that you can only do that when declaring and initializing on the same line.
8  Game Development / Newbie & Debugging Questions / Re: global variable on: 2009-02-03 14:15:28
Nope. Wink The enemies Array is already defined as a member variable to make it available to other methods of the same class. If you redeclare it locally, the class member called enemies would remain unset. Also in java you can't use a short form for array initialization, it has to be <variable> = new <Type>[]{ new <Type>(), new <Type>(), ...}

err...int[] arr = new int[5] is shorter, unless your talking about a short-form to give the array locations starting values.

On a side note I may just seen the way to pass an array that is created in the method call.  I always had a syntax problem.
9  Game Development / Newbie & Debugging Questions / Re: wait for dialogue box on: 2009-02-01 19:42:59
1  
2  
      int i = JOptionPane.showConfirmDialog(null,"Text","Title",JOptionPane.DEFAULT_OPTION);
      System.out.println("Dialog closed ");


There's a bunch of different methods like this in JOptionPane so you should look at the documentation to find which kind you want, but they all look basically like this.
10  Game Development / Newbie & Debugging Questions / Re: self closing JFrame on: 2009-02-01 18:00:23
I think dispose() does what you want,but it may do more than you want it to if you read the javadoc (in which case, setVisible() should be enough)
11  Game Development / Game Play & Game Design / Pong Physics on: 2009-02-01 08:56:23
Hi, I'm looking for verification on the math I'm using for simple Pong-like physics for arbitrary convex polygons (i.e. collisions always involve a static structure).  So here's my solution:

1. Two bodies collide one of which has a velocity vector and create an intersection
2. The normal to the surface is found by finding the angle from the intersection center to the center of the moving object
3. The velocity vector is reversed by rotating 180 degrees
4. The new velocity vector is flipped over normal angle by adding the angle between the velocity vector and the normal to the normal.

Like this:



Here's my code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
      Rectangle me  = shape.getBounds();
      Rectangle him = ob.getShape().getBounds();
      Rectangle col = me.intersection(him);
      Point meCent = new Point((int)(me.getX()+me.getWidth()/2),(int)(me.getY()+me.getHeight()/2));
      Point colCent = new Point((int)(col.getX()+col.getWidth()/2),(int)(col.getY()+col.getHeight()/2));
      double normAngle = Math.atan2(meCent.getY()-colCent.getY(),meCent.getX()-colCent.getX());
      double velAngle = Math.atan2(dy,dx);
      double newAngle = normAngle+(normAngle-(velAngle-Math.PI));
     
      //I know this is not the best way to push out of the collision
     move(-5*Math.cos(velAngle), -5*Math.sin(velAngle));

      dx = 50*Math.cos(newAngle);
      dy = 50*Math.sin(newAngle);


I am fairly sure this is conceptually correct, but it never hurts to be sure, besides I got a few questions about it:
-Is this the most efficient way of doing things? (Specifically getting intersection and angles)
-Am I guaranteed that the normal angle will be correct (Assuming I never sink into a collision past the mid-point)
-Am I right in thinking that adding in force, friction, and collisions between 2 moving bodies would not be far off from this?
-Is there a way to easily/effeciently get perfect intersections rather than rectangular approximations

Thanks for the time
12  Game Development / Game Play & Game Design / Re: Hexagon board on: 2009-01-28 21:46:03
Oh, here's an idea that might make stepping through the links faster than iterating through a master list.

You start from the center and instead of spreading out in all directions you just step in the direction to get closer to the mouse event point (assuming you have the coordinates of the hexes). You'd have to be careful of cases where the mouse didn't click anything (may or may not be possible in your game) and how you determined the next step direction (otherwise you might end up circling).  Also, you would want to store the neighbors in a way that lets you know the direction the neighbors are in (as in an array with index correlating to specific directions, or whatever you could come up with).

That's about the 'cleverest' thing I could think of, but I wouldn't be surprised if someone came along and blew my mind out the back of my skull with awesomeness, lol.
13  Game Development / Game Play & Game Design / Re: Hexagon board on: 2009-01-28 21:22:04
If you establish the hex grid solely through linking from a central spot, can you still do pixel - hex coordinate conversion for mouse events and such?  What about finding the viewable hexes for efficient drawing?

For my purposes, keeping a master list of hexagons and iterating through them to find any 'hits' for the mouse event was perfectly acceptable, though that might be too slow in very large lists.  Changing how that was stored (say a 2d array or what Riven posted rather than an ArrayList) could conceivably speed that up to O(1) (assuming theres a correlation between location and index) and allow for clipping unseen hexes for drawing, though populating the list would be more complicated.  Basically you would be supporting both methods of map storage (b/c laying out the master list like this would support finding neighbors etc. from it) and using the links for faster interaction operations (like moving a piece) and the master list for global events (drawing, updating, and mouse events). 

However, the whole reason I went with the links was to avoid populating that list (so that I could throw together arbitrary boards of various shapes and sizes by removing neighbors w/o worrying about null pieces). 

If, as you said, you only stored the links, you could find mouse hits by recursively* stepping through the list from the center the same way you would 'grow' the array, but I feel that would end up having more overhead than even an ArrayList.

*A question occurred to me while working on this project and I never found the answer. Is it still recursion if you call the same Class.method() but using different objects, as in calling neighbor.grow(n-1) within Hex.grow(int n)?
14  Game Development / Newbie & Debugging Questions / Re: Generating Image on: 2009-01-28 17:52:33

@ Markus_Persson
Oh, that's a great idea!  I was trying to go at it backwards (trying to clip the sheet, move what i clipped to [0,0], and then draw) so I completely didn't see that I could draw the entire sheet to the new image in such a way that the new image would clip it to what I wanted.  I gotta start learning to see a problem from different angles at once; I've had that kind of problem before.  However...

@ cylab
 Shocked Shocked Shocked  Where did that come from?!?!? lol, I swear I scrolled through the BufferedImage documentation specifically looking for methods that return BufferedImage and didn't see one.  I guess I missed it  Undecided.  Argh, that was a complete waste people's time then.

Thanks guys, although I feel retarded that I didn't come up with either of those on my own....
15  Game Development / Newbie & Debugging Questions / Generating Image on: 2009-01-28 06:19:54
Hi all,

I'm looking for an easy way to generate an image by getting a clip from a different one, as with say a sprite sheet or a bitmap font.  Using separate files has been alright (albeit annoying and wasteful) for sprites, but I'm not having 24 pics for every font & size combination I want to use.

Anyways my ingenious plan was:
1. Load BufferedImage
2. getGraphics() and clip
3. ...
4. Profit!!!

Unfortunately, I can't seem to find anything obvious to throw into 3.  After hunting through Rasters and such for hours with no apparent success (I don't doubt I missed something though), I thought it would probably be better to bug someone for a few minutes of their time rather than pull my hair out/toss the laptop out the window/etc.

Thanks

P.S. Please don't say drawString(); I'm not that retarded. I'm using LWJGL and for unknown reasons the NeHe tutorial code and the Slick utility class don't like me  =( , lol (by which of course I mean I'm screwing stuff up and am too unfamiliar to deal with it).

P.P.S. Ok, last question. Even though I'm not using Java2D anymore, I've alway been curious if clipping the graphics context created a speed boost (say if I were drawing 500 images outside of the clip).
16  Discussions / Community & Volunteer Projects / Re: Community Project Mark 562 on: 2009-01-11 19:14:33
I personally would not like to open source the project. I dont really see the point,I know this statement can open up an arguement but id rather not argue on such a small matter, I just wanna say my bit.
I dont see the need as people that are joining the project should already know how to program and dont really need to learn off other peoples code (thats what this forum is for).
Other programers should only know how to use the classes supplied and not be tempted to spend alot of time criticising other people code.
I would rather have a utility style setup (rather than an engine) so that programers can interact with other peoples code without having to learn much about its implementation.

I see your point, but here is my case.  I know how to program and I've done quite a few games on my own, but I'm still rather a beginner just getting into the upper level CS classes at college.  I'd love to help if there was something I could contribute (like with a mini-game scheme), but very likely won't be able to do much, and additionally I've yet to actually get OpenGL (or other libraries) working.  Despite this, being able to see a intricate program beyond my own abilities as it is developed is a great opportunity.

I couldn't be sure, but I believe the community is mature enough to avoid petty criticisms and work together.

Just my thoughts
17  Game Development / Game Play & Game Design / A question out of curiousity on: 2008-12-08 07:37:51
I just ran into something that might be strange.

Since switching over to ubuntu, I've haven't done anything directly within a KeyListeners methods, so this is the first chance I've had to notice something that is possibly different from java under Windows.  The thing is; I can't check it myself.

When I run the program and hold down a key, the system begins firing both keyPressed() and keyReleased() continuously.  However, the way I remember it from the last time I needed to know this (under Windows), the system would only keep performing keyPressed() while the button was held, and its seems like some old code is meant to work like that (and it did do what I needed it too).  So I'm wondering if this really is a difference, or am I just insane?
18  Java Game APIs & Engines / OpenGL Development / Re: I shouldn't be getting a black box...or should I? on: 2008-11-16 19:12:24
Hmm, I may have found a problem.  Going from the tutorial in the jogl section I ran:

System.loadLibrary("lwjgl");

And I get:

Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/delirious/Documents/Java/jre/lib/i386/client/liblwjgl.so: libmawt.so: cannot open shared object file: No such file or directory
   at java.lang.ClassLoader$NativeLibrary.load(Native Method)
   at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1778)
   at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1703)
   at java.lang.Runtime.loadLibrary0(Runtime.java:823)
   at java.lang.System.loadLibrary(System.java:1030)
   at LwjglTest.<init>(LwjglTest.java:17)
   at LwjglTest.main(LwjglTest.java:118)

Is this libmawt.so causing the problem?

Btw, I'm using Ubuntu and Java 1.6
19  Java Game APIs & Engines / OpenGL Development / I shouldn't be getting a black box...or should I? on: 2008-11-16 07:26:00
I was just playing around with getting LWJGL working today and ran into something strange, or at least I think it should be strange.

Running a demo class, all I get is a black rectangle on the screen that is very buggy in interacting with objects behind it.  The code I use (below) isn't much, but it seems to imply that there would be a window with a title present, which is not what I'm getting.  Keep in mind that this could be a blatant error in my code or something having to do with how I set up LWJGL.

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  
import org.lwjgl.LWJGLException;

import org.lwjgl.Sys;

import org.lwjgl.opengl.Display;

import org.lwjgl.opengl.DisplayMode;

import org.lwjgl.opengl.GL11;



/**

 * @author eyuzwa

 * A big "thanks" also goes out to Kevin Glass over at

 * http://www.cokeandcode.com. He also has a lot of

 * excellent LWJGL resources!

 *

 */


public class LwjglTest {

   public LwjglTest(){  
      try {
         // find out what the current bits per pixel of the desktop is
        int currentBpp = Display.getDisplayMode().getBitsPerPixel();

         // find a display mode at 800x600
        DisplayMode mode = findDisplayMode(800, 600, currentBpp);


         // if can't find a mode, notify the user the give up
        if (mode == null) {

            Sys.alert("Error", "800x600x"+currentBpp+" display mode unavailable");
            return;

         }



         // configure and create the LWJGL display
        Display.setTitle("Empty Project");
         Display.setDisplayMode(mode);

         //keep things windowed for now
        Display.setFullscreen(false);

         //create the main display
        Display.create();
      } catch (LWJGLException e) {
         e.printStackTrace();
         Sys.alert("Error", "Failed: "+e.getMessage());
      }      
   }

   

   /**
   * Start the game
   */

   public void startGame() {
      // enter the game loop
     gameLoop();

   }

   /**
   * Get the current time in milliseconds based on the LWJGL
   * high res system clock.
   *
   * @return The time in milliseconds based on the LWJGL high res clock
   */

   private long getTime() {
      return (Sys.getTime() * 1000) / Sys.getTimerResolution();
   }

   /**
   * Determine an available display that matches the specified
   * parameters.
   *
   * @param width The desired width of the screen
   * @param height The desired height of the screen
   * @param bpp The desired color depth (bits per pixel) of the screen
   * @return The display mode matching the requirements or null
   * if none could be found
   * @throws LWJGLException
   * library.
   */

   private DisplayMode findDisplayMode(int width, int height, int bpp) throws LWJGLException {
      DisplayMode[] modes = Display.getAvailableDisplayModes();
      DisplayMode mode = null;

      for (int i=0;i<modes.length;i++) {
         if ((modes[i].getBitsPerPixel() == bpp) || (mode == null)) {
            if ((modes[i].getWidth() == width) && (modes[i].getHeight() == height)) {
               mode = modes[i];

       }

         }

      }
      return mode;
   }

   

   /**
   * The main game loop which is cycled to update / render
   */

   public void gameLoop() {
      boolean gameRunning = true;

      while (gameRunning) {

         GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

         Display.update();

         // if the user has requested that the window be closed, either
        // pressing ALT-F4 on windows, or clicking the close button
        // on the window - then we want to stop the game
        if (Display.isCloseRequested()) {
            gameRunning = false;
            System.exit(0);
         }
     }
   }  



   /**

   * @param args
   */


   public static void main(String[] args) {

      // TODO Auto-generated method stub

      LwjglTest g = new LwjglTest();

      g.startGame();
   }

}
20  Game Development / Shared Code / Re: Distributing a library on: 2008-11-13 13:31:58
O.K.

So I looked up some stuff about using hardware acceleration for images and am using the following code:

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  
   public Sprite getSprite(String ref) 

        {

           if (sprites.get(ref) != null)

              return (Sprite) sprites.get(ref);


           BufferedImage sourceImage = null;  

           try {

             sourceImage = ImageIO.read(new File(ref));

           } catch (IOException e) {fail("f**k, my picture:"+ref);}

     

           GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
           ImageCapabilities ic = new ImageCapabilities(true);
           VolatileImage image = gc.createCompatibleVolatileImage(sourceImage.getWidth(),sourceImage.getHeight(),Transparency.OPAQUE);
           try{
              image = gc.createCompatibleVolatileImage(sourceImage.getWidth(),sourceImage.getHeight(),ic,Transparency.OPAQUE);
           }catch (java.awt.AWTException e){System.out.println("Unable to create Volatile Image");}

       
           image.validate(gc);
           Graphics2D g = (Graphics2D)image.getGraphics();

           g.drawImage(sourceImage,0,0,null);

     

           Sprite sprite = new Sprite(image);

           sprites.put(ref,sprite);

     

           return sprite;

        }


Which successfully accelerates the images.  However, according to Sun images that use BITMASK transparency will not be accelerated.  Is there any way to get around this caveat?

I'm also planning on putting all my source out to be ripped apart in about a week.  I've sort of been in a programming slump lately, but got better upon spending a night of coding and customizing Ubuntu

P.S. Let's see you try to do this with windows



I got a console that hides and reveals with the stroke of a key and, even better, wobbly windows!
21  Game Development / Game Play & Game Design / Re: Custom Cursor Issue on: 2008-11-10 23:32:58
Sun's, I believe.
22  Game Development / Shared Code / Re: Distributing a library on: 2008-11-06 23:06:11
Ouch,
Because those entities currently don't have an animation loop, they look and move fine with that many, but I just found that the fps goes from 90-25 with 50 entities. A different program I made using Java2D (but not this library) didn't have problems w/ animation, but I don't think I ever exceeded 30 or so.  In lieu of this revelation, I'm going to see about changing my library over to openGL, although it might already have everything I'm doing.

Another question, I'm currently handling mouse events by catching them with the canvas and the 'cascading' it down through the various components by passing it to their mouse event methods.  Would it be better to go through the components and just generate a list of what is under the mouse (of only components to which it applies) and then handle it centrally by calling those components handleEvent() (or w/e I call it)?
23  Game Development / Game Play & Game Design / Re: Custom Cursor Issue on: 2008-11-06 02:41:40
I'm using Java 1.6 on Ubuntu
24  Game Development / Shared Code / Re: Distributing a library on: 2008-11-05 21:48:59
It is a bit limited in how much you can put into it at once.  The RTS up there starts to have fps issues with about 250-300 entities in it.  I'm sure there are ways to improve that, but I also know it will only go so far.  However, I can still think of tons of games that would never come close this maximum (and there could probably be a greater number of simpler entities), so I believe it still would be useful, esp. to a novice programmer.

Oh, while I'm at it, one definite way I can think of to increase speed is to stop rendering off-screen entities and components.  I'd rather not have to check bounding on each entity/component because it would probably make the benefit useless, so would using the Graphics built in clipping be a good idea (I would have to be able to change the clip, say for World, draw, and change it back for further drawing)?
25  Game Development / Shared Code / Re: Distributing a library on: 2008-11-05 17:04:50
That's exactly how I'm thinking about the situation. I would been able to use this set-up as a black-box long before I knew how to work with Canvas to do custom drawing, which was a HUGE breakthrough for what I could do and thus what I could learn.  I have a roommate who just started in programming classes, for example, and I'm probably going to show him this as soon as he asks me about graphics drawing; he'd have to learn Java first though (he's learning in C right now, and thinking about going to C++ next).

Now that I know what a widget is, you can pretty much see all the ones I have so far.  Every widget (from primitive data wrappers to holders to entities) is derived from the DrawableObject class and, as I said, making new ones can usually be done by changing draw(), update(), and possibly event handlers.

There's quite a bit more to add and change, since I'm developing this library simultaneously with other programs, but its improving all the time.
26  Game Development / Shared Code / Re: Distributing a library on: 2008-11-05 00:43:22
Oh, I have no aspirations of changing the Java community, lol.  Mostly, its just a chance of trying to make something for the public instead of by myself, and to get some feedback on what I'm doing. However, I do genuinely feel that this would be a good library for some one to start writing games with.

So, the central class of my library is Game, it handles the JFrame and canvas (which I suppose means this is based on Java2D), and is where the main loop is run.   Each loop, Game updates and draws the current screen (a Holder defined by the programmer) which starts a chain reaction down components.



The above is the MainMenu screen of my project*, Game sends the update() and draw() commands to MainMenu which in turns sends them to the inner Holder (w/ buttons) which in turns sends them to the Buttons.  This way, people can plug in new screens (thus games) without having to alter Game, and most things are accomplished just by overriding update().  Game uses a similar method to cascade MouseEvents to the components to which the events apply, which is how the Buttons alter their state.

Each Holder can hold any number of other GUI elements, including other holders, as in the following.  Three holders (status, and console, and world) are added to the screen, which contain other components. The first two are just typical holders, but World is a special holder to work with Entities (which are still derived from the same parent as other components), for those games that use entities. A zIndex of objects used by the Holders allows drawing order to be changed, so for example a unit can go under and over a bridge, its also useful in simple GUI like placing the console over the world.



Another benefit is the easy alteration of game time, for opening menus, dialog, etc.  To pause the game, I just have to shift a quickly defined activeObject from the screen itself to the menu (etc.).



That's pretty much the basis of it. I mean, I can throw together new screens in a few minutes, and theres already plenty of objects to build interfaces for various game designs.  Would this be a useful library?

----
Update:

Got Tetris back up, same design. A main Holder contains several Holders and uses update(), this also uses the Grid class, which will be good for board games (probably as a subclass)



Now that I think about it I could probably make it so that I can move between games within a single session by just defining a new Screen.

P.S. I know this sounds horrible, but what are widgets?
27  Game Development / Shared Code / Distributing a library on: 2008-11-04 22:06:24
While working on my recent game projects, I've realized that I have been developing a GUI/game library that is fairly simple but works very well for 2D projects (I think much better than Java's built-in GUI). I have developed or am developing Tetris, a hexagonal board game, and a simple RTS all based off of it and could easily see a zelda-type game or many other things.  So I was thinking that after I get complete more of it, it might be a good idea to review it with some people here and then release it.

What do you all think?
28  Game Development / Game Play & Game Design / Re: Custom Cursor Issue on: 2008-11-04 21:48:42
Yeah, .gifs are a pain color-wise, but I'm sure its not the image because
         g.drawImage(cursorImages[0],0,0,null);
works fine.

The old test file I had for custom cursor also appears to have problems displaying color correctly :S, are cursors limited to certain colors?

Oh, while I'm at it. I want to make my gui holders display a dynamic bg image and border. By dynamic I mean that it takes two base images and tiles them appropriately and, hopefully, stores that as a simple image.  Is this possible, and if so, where do I start?

Thanks!
29  Game Development / Game Play & Game Design / Custom Cursor Issue on: 2008-11-04 19:18:06
I am creating a custom cursor using the following code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
   public void fillCursor()
   {
      cursorImages = new Image[1];
      cursorImages[0] = Toolkit.getDefaultToolkit().getImage("bin/gui/cursor.gif");
   }
   public static void setCursor(int state)
   {
      canvas.setCursor(canvas.getToolkit().createCustomCursor(cursorImages[state], new Point(0,0), "Cursor"));        
   }


It does indeed change my cursor, but I'm having a very strange problem, the color of my image is messed up.  I have made sure that the canvas itself draws the image correctly, so I'm not really sure what's wrong.  Any ideas?
30  Game Development / Game Play & Game Design / Re: Spot well written games on: 2008-10-10 22:29:27
Any1 know of other sites like Sourceforge, where u can see and take on projects?
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.

xsi3rr4x (64 views)
2014-04-15 18:08:23

BurntPizza (62 views)
2014-04-15 03:46:01

UprightPath (75 views)
2014-04-14 17:39:50

UprightPath (58 views)
2014-04-14 17:35:47

Porlus (76 views)
2014-04-14 15:48:38

tom_mai78101 (101 views)
2014-04-10 04:04:31

BurntPizza (161 views)
2014-04-08 23:06:04

tom_mai78101 (256 views)
2014-04-05 13:34:39

trollwarrior1 (209 views)
2014-04-04 12:06:45

CJLetsGame (216 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!