DurzoBlint15
Senior Newbie 
|
 |
«
Posted
2012-02-22 19:30:22 » |
|
Could anyone guid me into making some interfaces and stuff so I can implement it into games I will make? Also, how could I make a game that prints tiles out by reading a picture and decoding it like Notch used on one of his games. Thanks, I know the basics of game making but I'm not very imaginative when it comes to code. I'm more imaginative with visual stuff.
|
|
|
|
|
DurzoBlint15
Senior Newbie 
|
 |
«
Reply #2 - Posted
2012-02-23 03:01:53 » |
|
Excuse me? I already know a lot of Java. I am asking for help on making my own game library.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
ra4king
|
 |
«
Reply #3 - Posted
2012-02-23 03:29:43 » |
|
Have you ever made a game before? A game library does not just come about, it is mostly produced from abstracting code you wrote in earlier games. My "game library" was born out of several games I made when I noticed that I was rewriting the same code over and over so I just put them in their own little project and soon it kept growing and growing as I demanded more from it 
|
|
|
|
lhkbob
|
 |
«
Reply #4 - Posted
2012-02-23 06:30:08 » |
|
The phrase "not very imaginative with code" made it sound like you were not comfortable programming, or did not enjoy it, or were inexperienced.
|
|
|
|
Damocles
|
 |
«
Reply #5 - Posted
2012-02-23 07:21:03 » |
|
Before you make a library (a library is a collection of knowledge to reference at one place) you should first collect the knowledge.
How about starting first with a textfile where you collect and comment a lot of codesnipplets.
When I "quicklearned" Javascript for gamemaking, I first made a textfile, and then specifically searched for snipplets to fill it and use it as a reference.
Before actually knowing how JS works (apart from the random stuff I know from looking at it) I wrote me a similar step-by-step list to work through: (and look up specific solutions online)
#1 basic programmingstructure -architecture of js in an html -datatypes -conditions -loops -functions / classes / parameters
#2 basic rendering -displaying shapes -loading and displaying images -moving images -structured way to handle resources
#3 input -capturing key presses -capturing mouse/click positions
#4 gameloop -where and how to structure a gameloop -timing the gameloop
etc.. etc..
Just working though a list like this lets you have quite fast progress without hanging too much at a specific topic for too long.
----------------
A library would later structure solutions into a toolkit ts you dont have to rewrite it. But also forces a specific architecture onto how you structure the game. "Entitiesystem"
Btw: what I see from Notch's code is that he does not use a library, but programs the stuff on the fly... Simply by having done this a hundred times before. A library can also slow you down, especially when you dont understand all parts and have to spend time searching how to use it propperly. - compared to just copy/pasting and adpating a snipplet. It really depends on the topic what you want to generalize behind a library:
-sound/music definately -toolbox (logging, Mathematical conversions, property file loadting, etc) good -resourceloading - good -input/controls - depends -displaying sprites / animations - depends -gameloop / arcitecture / collision - rather not,
|
|
|
|
DurzoBlint15
Senior Newbie 
|
 |
«
Reply #6 - Posted
2012-02-23 16:30:32 » |
|
Um... Do you know that I'm talking about Java and not JavaScript? If you know that I'm talking about Java, are you wanting me to use the same ideas but in Java?
Oh, and to the other person, I said I wasn't very imaginative in code because I'm more of a visual person(if that makes sense).
I'm working on a game right now. It will kind of be like Mario but much simpler.
|
|
|
|
DurzoBlint15
Senior Newbie 
|
 |
«
Reply #7 - Posted
2012-02-23 16:40:01 » |
|
Also, I'm not having trouble loading images from a folder outside the JAR, but is there a way to load images from or copy images from a JAR? This is what I use to load images from a JAR: 1 2 3 4 5 6 7 8 9 10 11 12 13
| public static Image getImage(String imageName) {
Image imageToReturn;
try {
imageToReturn = new ImageIcon(System.getProperty("user.dir") + File.seperator + "images" + File.seperator + imageName).getImage();
} catch (Exception e) {System.err.println("Error loading image!"); return;}
return imageToReturn;
} |
|
|
|
|
Damocles
|
 |
«
Reply #8 - Posted
2012-02-23 19:19:55 » |
|
Well, I thought you catch the idea what I mean by the Javascript example 
|
|
|
|
ra4king
|
 |
«
Reply #9 - Posted
2012-02-23 19:20:37 » |
|
First of all, its best to use javax.imageio.ImageIO to load images. To find resources in JAR files, you have to use the getClass().getClassLoader().getResource(...) method: 1
| BufferedImage image = ImageIO.read(getClass().getClassLoader().getResource("res/myImage.png"); |
That method searches for the path relative to the root of the classpath, aka the "bin" folder in Eclipse or the root of the jar.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
aonxe
Junior Newbie
|
 |
«
Reply #10 - Posted
2012-02-24 19:50:28 » |
|
After you load the image you need to go through each pixel and then get the RGB value of each pixel. You can think of a pixel as a tile in your game world so if you want a 32x32 game world, make a 32x32 image. Then you make a decision on the RGB value returned by that pixel you looked at and build the tile required.
(Hint: look up Java bitwise and bit shift operators, specifically the >> signed right shift operator.)
|
|
|
|
ra4king
|
 |
«
Reply #11 - Posted
2012-02-24 22:32:25 » |
|
No bitwise or bit shift operations needed to compare RGB values: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| switch(pixel) { case 0xffffffff: break; case 0xff0000ff: break; case 0x00ff00ff: break; case 0x0000ff88: break; case 0x000000ff: break; case 0x00000000: break; }
|
|
|
|
|
sproingie
|
 |
«
Reply #12 - Posted
2012-02-24 23:33:04 » |
|
A case statement for every possible color? Seriously?
|
|
|
|
ra4king
|
 |
«
Reply #13 - Posted
2012-02-24 23:42:06 » |
|
A case statement for every possible color? Seriously?
Well it is certainly cleaner than an if-else chain 
|
|
|
|
sproingie
|
 |
«
Reply #14 - Posted
2012-02-24 23:56:10 » |
|
If one really must encode a map in single pixels (something you're going to find awfully hard to eyeball once you get beyond basic terrain), then you want a Map<Integer,Tile> where Tile is whatever your game representation is and not a giant bunch of conditionals. Maybe even <Long,Tile> just to not have to deal with the signedness foofra.
|
|
|
|
aonxe
Junior Newbie
|
 |
«
Reply #15 - Posted
2012-02-25 15:40:08 » |
|
I like this way better 1 2 3 4 5 6 7 8 9 10
| private int[] getPixelData(BufferedImage img, int x, int y) { int argb = img.getRGB(x, y);
int rgb[] = new int[] { (argb >> 16) & 0xff, (argb >> 8) & 0xff, (argb ) & 0xff }; return rgb; } |
But it's just because I'd rather define colors as 0-255 RGB values than write the hex out by hand.
|
|
|
|
BoBear2681
|
 |
«
Reply #16 - Posted
2012-02-25 18:04:26 » |
|
I like this way better 1 2 3 4 5 6 7 8 9 10
| private int[] getPixelData(BufferedImage img, int x, int y) { int argb = img.getRGB(x, y);
int rgb[] = new int[] { (argb >> 16) & 0xff, (argb >> 8) & 0xff, (argb ) & 0xff }; return rgb; } |
But it's just because I'd rather define colors as 0-255 RGB values than write the hex out by hand. While I think we're straying from the OP's question, if you want to take the approach above and get individual red, green, and blue from a pixel in a BufferedImage, why not just use Color? 1
| Color color = img.getRGB(x, y); |
color.getRed()/getGreen()/getBlue()/getAlpha() would be much clearer than array of ints. If the code is performance-critical though, you really should just use the DataBufferInt backing of the BufferedImage to access individual pixels.
|
|
|
|
ra4king
|
 |
«
Reply #17 - Posted
2012-02-25 21:03:55 » |
|
1
| Color color = new Color(img.getRGB(x,y)); |
FTFY
|
|
|
|
BoBear2681
|
 |
«
Reply #18 - Posted
2012-02-26 02:04:24 » |
|
D'oh! Thanks.
|
|
|
|
|