Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Compatibility issue  (Read 733 times)
0 Members and 1 Guest are viewing this topic.
Offline lefnire

Senior Newbie




Java games rock!


« Posted 2005-04-02 00:23:09 »

I made a rudimentary "game" that seems to be only working on some computers.  Newer computers run it, older computers give me the "class not found" error when I try to load the applet.  Here's my 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  
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  
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.io.*;
import java.awt.image.*;


public class VideoGame extends Applet implements Runnable, KeyListener {

  Thread animation;
  Graphics offscreen;
  static final int REFRESH_RATE = 35; // in ms
 int width, height;
  AudioClip music;
 
  MediaTracker t;
 
  Image image,images[][];
  boolean[][] grid;
 
  Layer2 layer2;
  Hero hero;
  int amtSprites=8;
  Sprite[] sprite=new Sprite[amtSprites];  
 
  public String debugString;
  int spriteNumber;
 

//INHERITED METHODS
 public void init() {
              this.addKeyListener(this);
          showStatus("Loading Images");
          width=bounds().width; height=bounds().height;
          setBackground(Color.black);        // applet background
         image = createImage(width,height); // make offscreen buffer
         offscreen = image.getGraphics();
          Font timesNew = new Font("TimesRoman",Font.PLAIN,18);
          offscreen.setFont(timesNew);
          grid=new boolean[width][height];
          music = getAudioClip(getDocumentBase(),"Music/Tsz_02.mid");
         
          loadImages();
          music.play();
         
          for (int j=0; j<width-1; j++) //set the borders as obstructions
               {grid[j][0]=true; grid[j][height-1]=true;}
          for (int j=0; j<height-1; j++)
                {grid[0][j]=true; grid[width-1][j]=true;}
               
          for (int i=0; i<amtSprites; i++){
                sprite[i].updateMap(grid, amtSprites);
                sprite[i].updatePosition();}
          hero.updateMap(grid, amtSprites);
         
          layer2.setObstruction(grid);
             }

  public void start() {
          showStatus("Starting Game!");
          animation = new Thread(this);
           if (animation != null) {
                   animation.start();
                 }
              }
             
  public void update(Graphics g) {// override update so it doesn't erase screen
         paint(g);
              }

  public void paint(Graphics g) {
          offscreen.setColor(Color.black);
          offscreen.fillRect(0,0,width,height);  // clear buffer
         updateImages();
          layer2.paint();
          hero.paint(offscreen);
          for (int i=0; i<amtSprites; i++){
                  sprite[i].paint();
                  if (sprite[i].messageNumber!=-4)
                        spriteNumber=i;
                  }
            sprite[spriteNumber].say(" The completed argument to the end method tells whether or not the I/O operation actually completed, that is, whether it had any effect that would be visible to the invoker. In the case of an operation that reads bytes, for example, this argument should be true if, and only if, some bytes were actually transferred into the invoker's target buffer.A concrete channel class must also implement the implCloseChannel method in such a way that if it is invoked while another thread is blocked in a native I/O operation upon the channel then that operation will immediately return, either by throwing an exception or by returning normally. If a thread is interrupted or the channel upon which it is blocked is asynchronously closed then the channel's end method will throw the appropriate exception. ");
          g.drawImage(image,0,0,this);
              }

  public void run() {
          while (true) {
                  repaint();
                  try {
                   Thread.sleep (REFRESH_RATE);
                  } catch (Exception exc) { };
                }
              }
             
  public void stop() {
          showStatus("Game Stopped");
          if (animation != null) {
                  animation.stop();
                  animation = null;
                }
              }


//HANDLE IMAGES
 public void updateImages(){

              for (int i=0; i<amtSprites; i++)
              {
                    if(sprite[i].messageNumber==-4)
                          sprite[i].update(sprite, i);
                    sprite[i].updatePosition();
              }
              hero.update(sprite);
   }

  public void extractImages(Image strip,Image images[][],int num_images,int croppedWidth,int croppedHeight, int spriteSet)
  {
        ImageProducer producer;
    ImageProducer source = strip.getSource();
    int startingY=0;
    if (spriteSet>4){
          spriteSet=spriteSet%4; startingY=4*croppedHeight;}
    int startingX=(spriteSet*(3*croppedWidth))-(3*croppedWidth);
    for (int i = 0; i<num_images/4; i++) {
          for (int j=0;j<num_images/3; j++){
                  ImageFilter extractFilter = new CropImageFilter(startingX+(i*croppedWidth),startingY+(j*croppedHeight),croppedWidth,croppedHeight);
                  producer = new FilteredImageSource(source,extractFilter);
                  // extract the subimage
                 images[i][j] = createImage(producer);
                  t.addImage(images[i][j], 0);
          }
    }
   
  }
 
 
  public void loadImages() {
    t = new MediaTracker(this);
         Image strip;
    int num_images=12;
   
    //Load Layer1
         strip=getImage(getCodeBase(), "sprites/layer.png");
          t.addImage(strip, 0);
          layer2=new Layer2(this, strip, offscreen);
         
         
   
   
    //Load Hero
         strip = getImage(getCodeBase(),"sprites/Chara1.png");
          t.addImage(strip, 0);
          // define array of constituent images
         images = new Image[num_images/4][num_images/3];
          extractImages(strip,images,num_images,24,32, 1);
          hero = new Hero(600,400,images,this);
         
    //Load Enemies
                 
    //Load NPCs
    for (int i=0; i<amtSprites; i++){
            strip = getImage(getCodeBase(),"sprites/Chara1.png");
          t.addImage(strip, 0);
          images = new Image[num_images/4][num_images/3];
          extractImages(strip,images,num_images,24,32, (int)(Math.random()*7+1));
          sprite[i] = new Sprite(10,300,images,this, offscreen, hero);
         
         
         
         
         
         
         
          Image face=getImage(getCodeBase(), "Faces/hero1.png");
           
            ImageProducer producer;
          ImageProducer source = face.getSource();
         
                  ImageFilter extractFilter = new CropImageFilter(0,0,47,47);
                  producer = new FilteredImageSource(source,extractFilter);
                  // extract the subimage
                 face = createImage(producer);
                  t.addImage(face, 0);
          sprite[i].face=face;
           
           
           
           
           
           
           
           
           
           
           
           
           
           
            }
                 
      //Wait for all images to finish loading
         try {
                  t.waitForAll();
                }  catch (InterruptedException e) {}
            if (t.isErrorAny()) {
                  showStatus("Error Loading Images!");
                }
          else if (t.checkAll()) {
                  showStatus("Images successfully loaded");
                    }
        }
             
        public int[] spritex=new int[amtSprites];
        public int[] spritey=new int[amtSprites];
         
//HANDLE INPUT  
   public void keyTyped(KeyEvent e)  {}
    public void keyReleased(KeyEvent e)
          {
                hero.key[e.getKeyCode()]=false;
                hero.enableActionKey=true;
          }
      public void keyPressed(KeyEvent e)
            {hero.key[e.getKeyCode()]=true;}
           
}


for the main game loop.  If you need me to list my sprite and hero class code, please say so.. I figured this class is my problem since the error is "error finding class VideoGame".
Any ideas as to what I should change to make this more compatible with other machines?  I've tried downloading the latest JRE in all instances, and again, it works sometimes and not other times.  I hear that bufferedimage causes some compatilibity issue and that you need to get a screen context, do you need to do something similar with images?
Also, I've implemented obstructions based on boolean values that are set in layer2 if the region is not transparent.  This works perfectly on my computer, but when I save it to a jump drive it doesn't work on any other computer on which the game DOES work (including my own, actually).  Do I need to set bufferedImage up in some way to ensure compatibility?  here is my layer2 code for setting up the 2d boolean array for true/false regions (on the true regions, the characters can't walk):

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  
import java.awt.*;
import java.applet.Applet;
import java.awt.image.BufferedImage;

public class Layer2
{
      Applet applet;
      BufferedImage bimage;
      int width, height;
      int alpha;
      Graphics g;
      Image image;
      String debugString;
     
      public Layer2(Applet a, Image i, Graphics g)
      {      this.g=g;
            this.applet=a;
            width=a.getWidth(); height=a.getHeight();
            bimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
            image=i;
            g = bimage.createGraphics();
            g.drawImage(image, 0, 0, applet);
           
           
      }
     
      public void setObstruction(boolean[][] grid)
            {for (int i=0; i<width; i++)
            {for (int j=0; j<height; j++)
            {alpha = (bimage.getRGB(i,j) >>> 24);
            if (alpha==255)
                  grid[i][j]=true;
      }}}
           
      public void paint()
      {
            g.drawImage(image, 0,0, applet);
    }
}


Long post, cootos to whoever has the patience to bear through this one.
Offline JuddMan

Senior Member


Medals: 1


Your Ad Here


« Reply #1 - Posted 2005-04-11 13:21:01 »

could you post the whole error message?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (20 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (28 views)
2014-09-21 23:33:17

BurntPizza (64 views)
2014-09-21 02:42:18

BurntPizza (34 views)
2014-09-21 01:30:30

moogie (42 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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!