Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
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 / Game Mechanics / Re: Creating a command line similar to MS-DOS. on: 2013-06-26 01:48:37
Hello all, I'm in the middle of working on a game, 'Pixel-Space: The Next Adventure' as you know it, and I'm attempting to implement computers into the game. Does anyone have any good advice or shared code that might be helpful?

I attempted it a while back and was stunned at how many different things you would need to think about. All help is appreciated.
Basically, I'm referring to the blank command line that you can perform commands on. Think of it like trying to create a console from scratch, mainly using java.awt.graphics.

Thanks in advance.  Smiley

If it's just a simple command line, write down a list of commands you need.
Then when the user enters anything into the command prompt check the entered string against a array for stored commands, if the command is valid proceed to doing what ever it is the command is supposed to do.

Is there anything in particular that you need help with?
2  Game Development / Game Play & Game Design / Re: How'd you implement an action not being repeated when the button is held down? on: 2013-06-26 01:41:12
I stored the pressed key's in a array.
Then I created a method to release the key from the array.

So there is a simple boolean check to see if a key is down (in the array).

So check if your key is down, if it is do the action, after the action, release the key.
3  Game Development / Newbie & Debugging Questions / Re: Saving Inventory Items on: 2013-05-10 06:42:44
I'm using just pure java Cheesy, I managed to assign an individual id to each item now I am just trying to figure out how to function like I need it to :/

So now you could have your items store a image location or you could make your images have the same ID as your items.

If you item stores a image location you would look up your item by it's ID and get the image location.
If you save the image with the same ID then you just load the image using the ID as the file name.

Here is a example of loading a image with the ID as the file name.

ImageLoad.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  
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.InputStreamReader;

import javax.imageio.ImageIO;


public class ImageLoad {
   
   /**
    * Read the item file and load the item image.
    */

   public ImageLoad(){
      //File name (Location is assuming the file is in the same folder)
     String itemFile = "./myitem.txt";
      String imageFileName = "";
     
      //Get the file
     BufferedReader input = new BufferedReader(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(itemFile)));
      String line;
     
      //Read the file line by line.
     try{
         while((line = input.readLine()) != null){
            imageFileName = line.split(":")[1].trim();
         }
      }catch(Exception e){
         e.printStackTrace();
      }
     
      //Echo the image filename
     System.out.println(imageFileName);
     
      //Load the image
     BufferedImage myItemImage = loadImage("./" + imageFileName + ".png");
     
      //Echo the image
     System.out.println(myItemImage);
   }
   
   /**
    * Method to load a image.
    *
    * @param ref
    * @return BufferedImage
    */

   public BufferedImage loadImage(String ref){
      BufferedImage bimg = null;
     
      try{
         bimg = ImageIO.read(this.getClass().getClassLoader().getResource(ref));
      }catch(Exception e){
         e.printStackTrace();
      }
     
      return bimg;
   }
   
   /**
    * Start.
    *
    * @param args
    */

   public static void main(String args[]){
      new ImageLoad();
   }

}


myItem.txt
1  
Image: 1


1.png
This is just a image made in paint 5x5 pixels with a black background.

Output:
1  
2  
1
BufferedImage@7b19f779: type = 6 ColorModel: #pixelBits = 32 numComponents = 4 color space = java.awt.color.ICC_ColorSpace@65c66812 transparency = 3 has alpha = true isAlphaPre = false ByteInterleavedRaster: width = 5 height = 5 #numDataElements 4 dataOff[0] = 3
4  Game Development / Newbie & Debugging Questions / Re: Saving Inventory Items on: 2013-05-10 03:39:22
Why are you trying to save the image to a file?

Just save a value which tells you what image to load.

If you must save the image to a file then first convert it to Base64 and get the string. Save this to a file. When loading, convert the Base64 back to bytes then you can use a input stream from you byte array to load a image.

5  Game Development / Newbie & Debugging Questions / Re: Finding nearest objects on: 2013-05-09 14:20:29
100,000,000 times. And that 60 times per second

Ah that makes sense.

Thank you.
6  Game Development / Newbie & Debugging Questions / Re: Finding nearest objects on: 2013-05-09 08:45:20
Distance uses
Math.sqrt()
which is slow.

Hmm... It really doesn't seem slow at all...

Here is a little test I wrote up: http://pastebin.com/Yf5e3vst

And here are the results:
1  
2  
3  
Average time TOTAL (10 loops of 100 loops): 0.016ms to find the closest point out of 100 points.
Average time TOTAL (10 loops of 100 loops): 0.124ms to find the closest point out of 10000 points.
Average time TOTAL (10 loops of 100 loops): 12.838999999999999ms to find the closest point out of 1000000 points.


Either I am testing this all wrong... or it really isn't a problem using a simple method?
7  Game Development / Newbie & Debugging Questions / Re: Finding nearest objects on: 2013-05-09 07:52:30
Would the performance of this be much better then something simple like this...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
   
public static Point getClosest(Point start, ArrayList<Point> points) {
      closest = null;
      nearest = 9999;

      for(Point p : points){
         if(p != null && p.distance(start) < nearest){
            nearest = (int) p.distance(start);
            closest = p;
         }
      }
     
      return closest;
   }
8  Game Development / Newbie & Debugging Questions / Re: Problems with vertical tearing using Bufferstrategy FSEM on: 2013-05-09 07:42:49
Hi there.

I also encounted this error when I first started playing around with the Bufferstrategy.

For me the problem was not with the buffer or rendering methods at all but with how I handled my input.

For example I had a KeyListener on my canvas which I would use to update map movement etc...
To fix it, in the KeyListener I just set a boolean value of up,down,left,right equals true then in my update method I would check if up,down,left,right equals true and if it did I would process my movement.

By doing this you update all your map,units etc before rendering so there is no tearing.
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.

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

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

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

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

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

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

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

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

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

CJLetsGame (187 views)
2014-04-01 02:16:10
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

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