Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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  Games Center / 4K Game Competition - 2008 / Re: Hey, my first playable 4K game, based on Rocket Jockey on: 2007-12-24 00:45:46
Thats an awesome game! There seemed to be some text in the top left corner but it was mostly off the screen, I suppose thats my score but I couldn't read it.
2  Game Development / Newbie & Debugging Questions / Re: runtime error accessing ArrayList on: 2007-12-14 00:41:59
First of all, thanks for your replies so far!!

I added the (now working) hotfix but I still get the same runtime error. Which sort of surprised me. I looked at getFrame(), but all the methods depend on eachother so the fault could be anywhere, I think.
3  Game Development / Newbie & Debugging Questions / Re: runtime error accessing ArrayList on: 2007-12-12 21:01:04
I thought that was never supposed to happen because of the
1  
2  
 
   animTime = animTime % totalDuration;


I left the Animation class untouched so that would mean the code in the book is wrong. Or I made a mistake copying. I think the fault is somewhere in my test class.

oh by the way your hotfix gave a compile error. I added something similar, It got rid of the error message, but paint is still only called once, before the images are loaded.
4  Game Development / Newbie & Debugging Questions / runtime error accessing ArrayList on: 2007-12-12 05:29:59
These 2 classes are basically the classes from the book developing games in java, without the fullscreen stuff. They are supposed to create an animation. They both compile fine but when I run I get an error message, an no animation, paint() is only called once. Here's the error message:

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
at java.util.ArrayList.RangeCheck(ArrayList.java:546)
at java.util.ArrayList.get(ArrayList.java:321)
at Animation.getFrame(Animation.java:60)
at Animation.update(Animation.java:43)
at AnimationTest1.animationLoop(AnimationTest1.java:58)
at AnimationTest1.run(AnimationTest1.java:44)
at AnimationTest1.main(AnimationTest1.java:10)

I think this means the program is trying to access frame 4 when there is none. Right? I just can't get my brain around this. Any help would be great!
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  
import java.awt.Image;
import java.util.ArrayList;
 
/*   this class manages a serie of images (frames) and the amount of time to
   display each frame */

   
public class Animation {
   
   private ArrayList frames;
   private int currFrameIndex;
   private long animTime;
   private long totalDuration;
   
   //creates a new, empty animation, calls start().
  public Animation() {
      frames = new ArrayList();
      totalDuration = 0;
      start();
   }
   
   //adds an image to the animation, + how long to display the image.
  public synchronized void addFrame(Image image, long duration) {
      totalDuration += duration;
      frames.add(new AnimFrame(image, totalDuration));
   }
   
   //starts this animation over from the beginning .
  public synchronized void start() {
      animTime = 0;
      currFrameIndex = 0;
   }
   
   //updates this animations current frame if necessary
  public synchronized void update(long elapsedTime) {
      if (frames.size() >1) {
         animTime += elapsedTime;
         
         if (animTime >= totalDuration) {
            animTime = animTime % totalDuration;
            currFrameIndex = 0;
         }
         
         while (animTime > getFrame(currFrameIndex).endTime) {
            currFrameIndex ++;
         }
      }
   }
   
   //gets the animations current frame. null if none availible.
  public synchronized Image getImage() {
      if (frames.size() == 0) {
         return null;
      }
      else {
         return getFrame(currFrameIndex).image;
      }
   }
   
   private AnimFrame getFrame(int i) {
      return (AnimFrame)frames.get(i);
   }
   
   private class AnimFrame {
     
      Image image;
      long endTime;
     
      public AnimFrame(Image image, long endtime) {
         this.image = image;
         this.endTime = endTime;
      }
   }
}


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  
import java.awt.*;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
 
public class AnimationTest1 {
 
   public static void main (String args[]) {      
     
      AnimationTest1 test = new AnimationTest1();
      test.run();
   }
   
   private static final long DEMO_TIME = 5000;
   
   private JFrame frame;
   private Animation anim;
   
   public void loadImages() {
      //load images
     Image player1 = loadImage("gif1.png");
      Image player2 = loadImage("gif2.png");
      Image player3 = loadImage("gif3.png");
      //create animation
     anim = new Animation();
      anim.addFrame(player1, 200);
      anim.addFrame(player2, 200);
      anim.addFrame(player3, 200);
      anim.addFrame(player2, 200);
   }
   
   //loads image with ImageIcon
  private Image loadImage(String filename) {
      return new ImageIcon(filename).getImage();
   }
   
   public void run() {
      try {
         frame = new JFrame();
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.setSize(300, 300);
         frame.setVisible(true);
         
         loadImages();
         animationLoop();
      }
      finally {
      }
   }
   
   public void animationLoop() {
      long startTime = System.currentTimeMillis();
      long currTime = startTime;
     
      while (currTime - startTime < DEMO_TIME) {
         long elapsedTime = System.currentTimeMillis() - currTime;
         currTime += elapsedTime;
         
         anim.update(elapsedTime);
         //getContentpane.getgraphics??!!
        Graphics g = frame.getGraphics();
         draw(g);
         g.dispose();
         
         try {
            Thread.sleep(20);
         }
         catch (InterruptedException ex) {}
      }
   }
   
   //draw the animation
  public void draw(Graphics g) {
      g.setColor(Color.white);
      g.fillRect(0, 0, 300, 300);      
      g.drawImage(anim.getImage(), 0, 0, null);
   }
}
5  Java Game APIs & Engines / Java 2D / Re: ::Pixel art resources thread:: on: 2007-12-05 02:16:05
I found this :

http://mirror.motherhamster.org/tsugumo/default.html
6  Game Development / Newbie & Debugging Questions / Java gaming tutorials on: 2007-12-02 23:06:05
I've put all my bookmarks for java gaming tutorials on my website, so if you're looking for some good ones, look here. Note: I didn't write these, please don't ask me any questions about them. If you know of any other ones please post and I will add them.

Here's the link: http://tdem.t35.com/javatutorials.html
7  Game Development / Game Play & Game Design / Re: What do you want in a web game? on: 2007-12-02 21:00:16
I like the type of games where you have your little person, walk around, build structures, mine resources. Sadly I've never seen a minigame version. So you could make it!
8  Discussions / Miscellaneous Topics / Re: Are there any good physics engines written in Java? on: 2007-04-16 05:09:27
Have a look at this site http://www.flyingguns.com/
9  Discussions / Miscellaneous Topics / Re: Does anyone have a list of cool java things? on: 2007-04-16 05:04:35
Oh yes I do!!

first of all : Art of illusion, a 3d modeling program. Free, lots of features, small download, very, very, very easy to use, good documentation and runs even on my computer (64 meg ram).
url http://artofillusion.org/

second: runescape. you all know it. The most boring game ever to be made. But I wish I could make something that good!
url www.runescape.com

also drjava, a java ide written in java. All the features you need, and not a thing more. Just how I like it!
url http://drjava.org/
10  Game Development / Newbie & Debugging Questions / Re: Cannot get this to work properly. on: 2007-04-14 00:18:17
My java book shows how to do this but it uses deprecated methods. Fletchergames, when you say take out the thread alltogether, how would you control the speed of the animation? Or use doublebuffering?
When I followed SimonH,s advice the ball wouldn't move at all. Is there a way of slowing down a loop, timers or something?
11  Game Development / Newbie & Debugging Questions / Re: Cannot get this to work properly. on: 2007-04-13 02:34:20
Thanks for the replies!

I think this is the reason for not moving along x

1. That should be if clickX < posX
the first if clickX > posX moves the ball to the right, and the second if clickX >posX moves it right back!! Silly me! Embarrassed
I changed the code and added in sleep() so the ball moves slowly.
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  
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class App extends Applet implements MouseListener, Runnable
{
 Image offscreen;
 Graphics buffer;
 int posX, posY, clickX, clickY;
 Thread th;
 
 
 

 public void init()
 {
  offscreen = this.createImage(100,100);
  buffer = offscreen.getGraphics();

  addMouseListener(this);
 
 }


 public void paint(Graphics g)
 {
  buffer.setColor(Color.white);
  buffer.fillRect(0,0,100,100);
  buffer.setColor(Color.red);
  buffer.fillOval(posX - 5,posY - 5,10,10);
  g.drawImage(offscreen,1,1,this);
 }

 public void start()
 {
  if(th == null)
  {
   th = new Thread(this);
  }  
 }

 public void stop()
 {
 
 }
 

 public void mouseClicked (MouseEvent me)
 {
   clickX = me.getX();
   clickY = me.getY();
   
   th.start();
   
 }

 public void run()
 {
  while(isActive())
  {
   try
   {
     if(clickX > posX)
     {
       posX ++;
     }
     else if(clickX < posX)
     {
       posX --;
     }
     
     if(clickY > posY)
     {
       posY ++;
     }
     else if(clickY < posY)
     {
       posY --;
     }
     
     if(posX != clickX || posY !=clickY)
     {
       repaint();
       th.sleep(100);
     }
   }
   catch(Exception e)
   {
   }
  }
 }
  public void mouseEntered (MouseEvent me) {}
  public void mousePressed (MouseEvent me) {}
  public void mouseReleased (MouseEvent me) {}  
  public void mouseExited (MouseEvent me) {}



}


It all works but the second time (and following times) MouseClicked is called I get like 8 error messages in command. I think its because I call start when the thread is already running but I cant see any other way of doing it. Looks like I need some help once again!
12  Game Development / Newbie & Debugging Questions / Re: Can anyone start me off? on: 2007-04-12 06:41:30
advice from other noob:

I found this tutorial very easy to follow as it builds up from a small beginning instead of doing a whole big game at once
http://www.javacooperation.gmxhome.de/TutorialStartEng.html
(yes i call spaceinvaders a big game!!).

13  Game Development / Newbie & Debugging Questions / Cannot get this to work properly. on: 2007-04-12 06:28:25
This is the code for my first game. So far Its supposed to be a circle that moves to wherever you click the mouse. The code compiles fine but when I run the applet the circle only moves along the y-axis, and not across. Could someone please tell me what's wrong with it?

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  
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class App extends Applet implements MouseListener, Runnable
{
 Image offscreen;
 Graphics buffer;
 int posX, posY, clickX, clickY;
 Thread th;
 
 
 

 public void init()
 {
  offscreen = this.createImage(100,100);
  buffer = offscreen.getGraphics();

  addMouseListener(this);
 
 }


 public void paint(Graphics g)
 {
  buffer.setColor(Color.white);
  buffer.fillRect(0,0,100,100);
  buffer.setColor(Color.red);
  buffer.fillOval(posX - 5,posY - 5,10,10);
  g.drawImage(offscreen,1,1,this);
 }

 public void start()
 {
  if(th == null)
  {
   th = new Thread(this);
  }  
 }

 public void stop()
 {
 
 }
 

 public void mouseClicked (MouseEvent me)
 {
  clickX = me.getX();
  clickY = me.getY();
 
  th.start();
 }

 public void run()
 {
  while(isActive())
  {
   try
   {
    //CLICK IS TO THE RIGHT...
   if(clickX > posX)
    {
      //...and lower than ball
     if(clickY > posY)
      {
        posX ++;
        posY ++;
        repaint();
      }
      //...and higher than ball
     if(clickY < posY)
      {
        posX ++;
        posY --;
        repaint();
      }
      //...and equal height to the ball
     if(clickY == posY)
      {
        posX++;
        repaint();
      }
    }
   
    //CLICK IS TO THE LEFT...
   if(clickX > posX)
    {
      //...and lower than ball
     if(clickY > posY)
      {
        posX --;
        posY ++;
        repaint();
      }
      //...and higher than ball
     if(clickY < posY)
      {
        posX --;
        posY --;
        repaint();
      }
      //...and equal height to the ball
     if(clickY == posY)
      {
        posX--;
        repaint();
      }
    }
   
    //CLICK IS SAME X-CO AS BALL...
   if(clickX == posX)
    {
      //...and lower than ball
     if(clickY > posY)
      {
       
        posY ++;
        repaint();
      }
      //...and higher than ball
     if(clickY < posY)
      {
       
        posY --;
        repaint();
      }
      //...and equal height to the ball
     if(clickY == posY)
      {
        repaint();
        th.interrupt();
      }
    }
     
   }
   catch(Exception e)
   {
   }
  }
 }
  public void mouseEntered (MouseEvent me) {}
  public void mousePressed (MouseEvent me) {}
  public void mouseReleased (MouseEvent me) {}  
  public void mouseExited (MouseEvent me) {}



}
14  Game Development / Game Play & Game Design / Re: Whata classes to use? on: 2007-04-12 06:20:45
I have made a textbased game and a gui game and this was supposed to be my first applet game. I think I'll try to make a graphical application first as I have some experience in that and then make it into an applet later.
Thanks for the replies, Riven.
15  Game Development / Game Play & Game Design / Re: Whata classes to use? on: 2007-04-11 23:58:43
(after doing some internet searches on visitor pattern)

I think I understand what you mean but I don't see how I would get that to work in an applet. What if I got update() to call my visitor pattern which then calls paint? Would that work?
16  Game Development / Game Play & Game Design / Whata classes to use? on: 2007-04-11 04:09:44
I'm trying to make a fairly basic rpg but I keep getting stuck with what classes to make. I'm trying to have it all rendered (vector graphics?) but I'm stuck with what classes used for drawing. For example: Would you put the code for drawing and animating your player in a seperate class to the main player class. And would you have another class for what the player looks like when going in different directions? I think my main issue is that its not using images so you have to have different painting routines for different directions of movement.
Any help to sort of unjumble my mind would be very welcome!
17  Game Development / Newbie & Debugging Questions / Re: Is this a good tutorial? on: 2007-04-10 09:55:30
Netscape 4? WTF? Isn't that thing also like 10 years old?

Try Firefox or Opera (a current version... don't get em from some browser archive again o_O).
I meant the screenshots lol.
I use opera 9!
Thanks for the replies.I think I will use the cokeandcode tutorial first!
18  Game Development / Newbie & Debugging Questions / Re: Is this a good tutorial? on: 2007-04-10 01:47:04
It did look sort of arcane (netscape 4)
thanks for the reply!
19  Game Development / Newbie & Debugging Questions / Is this a good tutorial? on: 2007-04-10 00:51:58
I found a tutorial on game programming in java and was wondering if it is any good. It looks promising but it is very long and I don't want to cram my brain with useless information. If someone could please tell me what they think about it I would be very thankfull.
The url is:
http://www.softlookup.com/tutorial/games/index.asp

thanks already for any replies.
20  Game Development / Newbie & Debugging Questions / Re: just starting on: 2006-06-22 01:21:59
Oh, I found the tutorial

the url is http://www.cokeandcode.com/spaceinvaderstutorial
21  Game Development / Newbie & Debugging Questions / Re: just starting on: 2006-06-22 01:16:48
thanks guys
22  Game Development / Newbie & Debugging Questions / just starting on: 2006-06-21 03:41:14
I know some basic java and was wandering if anyone could tell me what would
be the best thing to do next.

Eventually I want to make a 3d game but that'll take
some time.

Especially tutorials would be good.
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.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (35 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36

Riven (45 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

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

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

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
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!