Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
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  
  Making My Own "Gaming Library"  (Read 3452 times)
0 Members and 1 Guest are viewing this topic.
Offline 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.
Offline lhkbob

JGO Knight


Medals: 32



« Reply #1 - Posted 2012-02-22 21:36:12 »

Sounds like GameMaker: http://www.yoyogames.com/make or RPGMaker might be a good fit for you: http://www.rpgmakerweb.com/

Otherwise you're going to need to learn how to code (to some degree) first, before you can dive into game making.

Offline 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!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« 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 Smiley

Offline lhkbob

JGO Knight


Medals: 32



« 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.

Offline 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,

Offline 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.
Offline 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;

}
Offline Damocles
« Reply #8 - Posted 2012-02-23 19:19:55 »

Well, I thought you catch the idea  what I mean by the Javascript example Yawn

Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« 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!
Legends of Yore - The Casual Retro Roguelike
Offline 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.)
Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« 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  
//0xRRGGBBAA
switch(pixel) {
    case 0xffffffff:
        //white
        break;
    case 0xff0000ff:
        //red
        break;
    case 0x00ff00ff:
        //green
        break;
    case 0x0000ff88:
        //blue at 50% transparency
        break;
    case 0x000000ff:
        //black
        break;
    case 0x00000000:
        //completely transparent!
        break;
}

Offline sproingie

JGO Kernel


Medals: 202



« Reply #12 - Posted 2012-02-24 23:33:04 »

A case statement for every possible color?  Seriously?
Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« 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 Smiley

Offline sproingie

JGO Kernel


Medals: 202



« 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.
 
Offline 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, //red
         (argb >>  8) & 0xff, //green
         (argb      ) & 0xff  //blue
   };
   return rgb;
}


But it's just because I'd rather define colors as 0-255 RGB values than write the hex out by hand.
Offline BoBear2681

JGO Coder


Medals: 19



« 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, //red
         (argb >>  8) & 0xff, //green
         (argb      ) & 0xff  //blue
   };
   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.
Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #17 - Posted 2012-02-25 21:03:55 »

1  
Color color = new Color(img.getRGB(x,y));

FTFY

Offline BoBear2681

JGO Coder


Medals: 19



« Reply #18 - Posted 2012-02-26 02:04:24 »

D'oh!  Thanks.
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.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (40 views)
2014-12-09 22:41:13

BurntPizza (75 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (113 views)
2014-11-26 15:22:04

toopeicgaming1999 (100 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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