Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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]
1  Game Development / Newbie & Debugging Questions / Re: Moving Enemies on: 2004-10-25 13:12:28
Also, have a look at the A* algorithm (A star) for a little ghost "AI". You get some pretty nifty results from it ( well... I thought it was nifty Smiley ).
2  Game Development / Newbie & Debugging Questions / Scrolling problems on: 2004-08-16 12:51:24
Hello again,

Posted my latest game attempt in the "Your games here" topic, but there seems to be a few wrinkles that need to ironed out so I thought I'd start a new thread here and fling some code at you.

The thread:
http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=Announcements;action=display;num=1091819583

The game:
http://home.chello.no/~ttollefs/game/scroller/scroller.html
or
http://student.iu.hio.no/~s113388/SpaceStationII.jnlp

Sooo ... where to start. As I understood it the game speed was all over the place and some of the tiles didn't have the good sense to stay in one place. I've changed the game loop since then from using Thread.sleep()

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public void run()
            {
                  while (true)
                  {
                        try
                        {   sleep(m_iFrameDelay);   }
                        catch(InterruptedException ie)
                        {   System.err.println("m_iFrameDelay was interrupted");   }

                        ref.gameCycle();
                  }
            }


to the following (posted in forums.java.sun.com)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
public void run()
      {
            final int MILLI_FRAME_LENGTH = 1000/30;
            long startTime = System.currentTimeMillis();
            int frameCount = 0;
            while(true)
            {
                  ref.gameCycle();
                  frameCount++;

                  while((System.currentTimeMillis()-startTime)/MILLI_FRAME_LENGTH <frameCount)
                  {            Thread.yield();         }

                  if (ref.getKeyState(KeyEvent.VK_ESCAPE))
                        break;
            }
            ref.destroy();
      }

The original version used java 1.5's System.nanoTime()
which I changed to currentTimeMillis(). the gameCycle() method updates what needs to be updated and calls repaint(). My update() method looks like this:
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  
public void update(Graphics g)
      {
            // Paint game graphics to off-screen image
           renderGameOffscreen();

            // Draw the off-screen image to on-screen
           do
            {
                  int returnCode = vImgOffscreen.validate(getGraphicsConfiguration());
                  if (returnCode == VolatileImage.IMAGE_RESTORED)
                  {
                      // Contents need to be restored
                     renderGameOffscreen();          // restore contents
                 }
                  else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE)
                  {
                      // old vImgOffscreen doesn't work with new GraphicsConfig; re-create it
                     vImgOffscreen = createVolatileImage(Constants.GAMEWIDTH, Constants.GAMEHEIGHT + Constants.BOTTOM_Y_OFFSET);
                      renderGameOffscreen();
                  }
                  g.drawImage(vImgOffscreen, 0, 0, this);
             }
             while (vImgOffscreen.contentsLost());
      }

// Method renders all game graphics to an off screen volatile image
     public void renderGameOffscreen()
      {
            do
            {
                  if (vImgOffscreen.validate(getGraphicsConfiguration()) == VolatileImage.IMAGE_INCOMPATIBLE)
                  {
                        // old vImgOffscreen doesn't work with new GraphicsConfig; re-create it
                       vImgOffscreen = createVolatileImage(Constants.GAMEWIDTH, Constants.GAMEHEIGHT + Constants.BOTTOM_Y_OFFSET);
                  }

                  Graphics2D g = vImgOffscreen.createGraphics();

                  switch (m_iGameState)
                  {
                        ... paints what needs to be painted based on the current game state ...
                  }

                  g.dispose();
            }
            while (vImgOffscreen.contentsLost());
      }



Been having a hard time trying to figure out what could be wrong because I don't have any real problems with speed or weirdo tile placements on this end ... so anything seem wrong with the game loop or my drawing routine?
3  Games Center / Archived Projects / Re: Yet another scroller on: 2004-08-09 19:36:40
Thanks again for all the feedback .. though this is starting to freak me out a little. The tiles seem to stay in place here! Maybe I should start a new thread in a more appropriate topic and post a little code   (unless none of you mind if this thread runs a little off topic).

About the game slowness ... I have removed all anti aliasing and transparency operations so maybe it'll run a little faster now (At least its not abusing the CPU as much as before ... according to Windows Task Manager  Tongue ) I've updated the link from my previous post.
4  Games Center / Archived Projects / Re: Yet another scroller on: 2004-08-09 14:12:58
Well, the webstart thing-a-ma-jig is up and running (I hope. It worked here but that never seems to hold true for others Tongue).

http://student.iu.hio.no/~s113388/SpaceStationII.jnlp

No fullscreen yet.
5  Games Center / Archived Projects / Re: Yet another scroller on: 2004-08-07 21:19:40
hehe ... the green block guy is only a temp. I can draw VERY basic tiles like ladders/air vents etc, but any sprite animation of the hero would end up as a poorly drawn stick figure Tongue

Thanks for the error message ... I'll see what I can do to prevent it.
6  Games Center / Archived Projects / Re: Yet another scroller on: 2004-08-07 12:54:46
Thanks for the feedback. Why the lack of love for the basic applet?  Grin I'll see what I can do to get a webstart application up and running. Never really done that before but I'm sure I can google my way to a  tutorial of some kind. What's the basic advantage? Runs faster?

As far as the level goes there's really no where else to go aside from the two rooms.

Not sure why things slow down when items are picked up. A dialog box pops up then so maybe that's where the problem lies ...

Now about the array out of bounds exception ... well as long as the game didn't crash lets pretend it never happened!   Wink
Suggestions on more user friendly keys are welcomed.

Well, I guess thats it for now. I'm of to Google a little Smiley

*little edit: Thanks for the control screen cheer Smiley I ripped the little key pictures and I'll be sure to mention their rightful owner when I get the credits up and running. (There ... now I'm in the clear of any lawsuits!)
7  Games Center / Archived Projects / Yet another scroller on: 2004-08-06 19:13:02
Hullo all,

Thought I'd get some feedback on my first scroller. It has reached the "story and better graphics to be added later" phase (which is were I tend to abandon a project Wink ), and the tile collision detection needs a little tweaking.

http://home.chello.no/~ttollefs/game/scroller/scroller.html

Anywho ... I'd be interested to know how it runs on other machines (choppy etc).  I had a buddy of
mine test it and apparently everything froze when he picked up either the weapon or the medkit, but I think
that has more to do with an antiquated JRE on his end. (I hope)
8  Game Development / Newbie & Debugging Questions / Re: Image clipping on: 2004-07-03 14:32:57
Guess I could cast the double values. In fact that's what I've been doing but it seemed to defeat the purpose of using double to store the position only to cast them back to int when drawing the sprite (though I guess any precision lost would be far from noticeable:) ).

I made a new image array because as it turned out the different images did not have an equal amount of frames.
9  Game Development / Newbie & Debugging Questions / Image clipping on: 2004-07-03 11:42:11
Hi all,

First time poster. Just wanted to ask a quick question about sprite animation and clipping.  Up until now I've been using
1  
drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)

to draw the correct part of the sprites image, but I've recently made the transition from int to double when storing my sprites position so it doesn't really work anymore.

Now I've started using CropImageFilter, so when I create a sprite that has more than one frame I split the image into an image array and use this bit of code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
public void draw(Graphics2D g)
      {
            // Draw the sprite if it isn't hidden
           if (m_image != null && !m_bHidden)
            {
                  // Draw the appropriate frame, if necessary
                 // m_at == AffineTransform
                 if (m_iNumFramesX == 1)
                        g.drawImage(m_image, m_at.getTranslateInstance(m_rcPosition.x, m_rcPosition.y), null);
                  else
                  {
                        g.drawImage(m_images[m_iCurRow][m_iCurColumn],
                              m_at.getTranslateInstance(m_rcPosition.x, m_rcPosition.y), null);
                  }
            }
      }


Now this works but in the game I'm working on right now I change a sprites image based on certain game events and when this happens I create a new image array and crop the appropriate image into it. This works just fine locally but when I play the applet over the web I get a half a second freeze when this happens.

I've been trying to use setClip(...) now to draw just the part of the current image that I want but I just can't seem to figure out just how exactly it works :p so any help would be appreciated (regarding setClip or any better way to get the part I want). Oh and if it is of any interest, the Graphics2D object the sprite's draw method receives is from the volatile image I use as a back buffer.
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

ctomni231 (33 views)
2014-07-18 06:55:21

Zero Volt (29 views)
2014-07-17 23:47:54

danieldean (24 views)
2014-07-17 23:41:23

MustardPeter (26 views)
2014-07-16 23:30:00

Cero (41 views)
2014-07-16 00:42:17

Riven (43 views)
2014-07-14 18:02:53

OpenGLShaders (31 views)
2014-07-14 16:23:47

Riven (30 views)
2014-07-14 11:51:35

quew8 (29 views)
2014-07-13 13:57:52

SHC (65 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!