Trying to create a game using the standard libraries

As the subject title states I want to create a game that uses only the standard java libraries. I am using jre7 last I knew if that is helpful.

I am using netbeans as well. I want it to be an isometric game and have no external images, if at all possible. I want to create the tiles and objects using Java’s native graphic drawing libraries… Is that possible?

You mean something like procedural generation, or do you mean you want to use regular images but want them all contained within the .jar file? Both are possible.

Yes that’s possible as well. The amount of work to achieve it depends on what you meant by the previous part of your message.

You can refer my game engine. It uses Swing and AWT which is available in the standard library.


http://i.imgur.com/8kMwZ3h.png

https://code.google.com/p/game-engine-for-java/

@CodeHead

Well I am hoping to stay away from images if at all possible. I know that sounds odd and entirely not within the norm, but i suck horridly at drawing lol.

@SHC

I will look into it thanks for the offer!

Shure its possible.

For inspiration and some coding tricks, have a look at the previous J4K games and their posted sourcecode.

http://www.java4k.com/index.php?action=home

You can generate all graphics in code, or alternatively store images in code an re-create them from there.
(stored as a String for example)

You can basically create a whole game in just one class-file if you wish to.

I assume you have no previous experience of game development? Do you have a good knowledge of the Java language? Are you familiar with swing & awt? Here are the topics I think you should research and also the things that you need to know:

  • The Java language
  • Swing & AWT
  • File handling (saving & loading)
  • The game loop
  • Double buffering
  • AABB collision detection & response

That’s probably the bear minimum that you need to know to make a game.
Regarding your second question about graphic drawing libraries; unless you want to draw some very simple coloured rectangles then you should use sprites. You can draw each pixel with code, but that’s just hassle and not worth it; you’ll probably end up with something that looks worse than something that you draw. I suck at pixel art too but if you play around with an image editing software or pixel art software like Photoshop, GIMP, GraphicsGale etc. you should be able to draw something half-decent. I advise sticking to relatively small (max 32x32 pixels) sprites to start with.

You dont need to learn much about Swing and AWT apart from
the nessecary steps to create a Window with the canvas to draw to, and how to handle inputs.

For most games, you dont need all these fancy Buttons, Lists and Layout managers.

@Damocles
The link doesn’t work?
A single class seems a bit odd…

@Troubleshoots
I have programmed in java for several years now. Having started several times to create games but something always comes up that makes me stop (usually i get fustrated or system corrupts). I have use Swing and AWT for a while but it was always bare basic stuff I want to dive deeper. I have done file handling but not very good with it (dont fully understand the reader/writer stuff beyond text file usage)
As for the rest I know of them but have very little understandung of them.
As for photo editting they are not my friends… I know MSPaint after that the others confuse me.

I strongly advise not to read the code for the Java4K entries. A lot of it is heavily optimised and hard to understand. If you didn’t know, Java4K is where developers try to make games that are <4 kilobytes, which usually requires a lot of crude optimization.

If you’re serious about game development then using just the Java API isn’t a good choice as it lacks the performance that most games need. However, for beginners it’s a great place to start. Try searching on Youtube for some simple Java game development tutorials, then once you’ve set up a basic window and set up a basic game loop I suggest searching through Google for articles/tutorials/forum posts regarding the topics I listed above (game loops, aabb collision, etc). Don’t just watch/read articles and tutorials though; maybe try creating a pong or snake game. Once you’re at the stage of feeling comfortable with those principles of game development, I challenge you to create a very simple platform game using coloured rectangles for tiles (load the map from a text file) and a coloured rectangle for the player.

After that is where it gets more difficult. If you don’t care too much about performance for your game, you could continue to use swing & AWT for it, however if you want to create faster, better games then you should consider looking into some game engines (I recommend LibGDX for Java). Game engines can be hard to learn; they’re much more advanced and use OpenGL for rendering. You could also consider learning how to use OpenGL (for Java learn LWJGL) which can be confusing and is a vast, vast topic. Learning OpenGL will give you a much better understanding of how things work and you’ll even be able to create your own game engine if you want.

As a whole, game development is a huge and confusing topic, but the number one thing is that when learning, don’t give up. Good luck.

@Troubleshoots: <4, not >4.

Every one of my games in made and I will be happy to help and answer any querys. If this is your first time I would suggest that you do use images , generating them in the code is a painstaking process litteraly piece by piece.

If you are using the term “isometric” to mean stuff like the classic QBert pyramid, that can certainly be done with simple graphics that you can draw yourself. All you need is a polygon and to choose whether to fill it or just paint the border. These things are provided in AWT & Graphics2D libraries. Drawing the equivalent of a QBert might be easier to do as an import.

It is possible to get by without explicitly double buffering. If you use a Swing JComponent or JPanel, the double buffering is handled automatically. It’s not the fastest, but for a simple isometric game it could very well be fine.

The biggest hurdle, my guess, is getting the game loop to work. There are a couple different methods. One of the simplest is to use a util.Timer to call an update() method and then a render(), at a fixed repeating increment. A more popular alternative is to use a while loop and calculate elapsed time during the update() and render(), and then use the elapsed time to calculate how much to sleep in order to make the increment a fixed repeating amount.

Alternatively, logic can be written that makes the updates proportional to the elapsed time. (In this case, there is no requirement for a fixed repeating time interval. The interval can vary (within reason). But all these game loops work with core Java.

So basically the answer to your initial question is yes.

I have gotten horribly stalled out with “Hexara” (a puzzle game), but the graphics and graphic effects are all drawn with Java2D, with the sole exception of the little symbols/icons within the hexes which I think I made with Microsoft Paint. At this point the sound is all procedural as well, using only the javax.sound.sampled library.

Yeah, it is possible to write a game using nothing but the Java API.

Even though it is possible, I wouldn’t say it was an easy task. I did a lot of research into the Graphics2D library and BasicStroke library in order to manipulate the graphics. You can draw anything you want, but for game play purposes, it’ll be very slow if you draw complex images.

However, if you are curious… I was forced to deal with the pure API in the 2013 Java4K Competition. It was a challenge to find a way to display that many graphics, keep it relatively smooth, and stay under that 4K limit. I learned so much from the experience, but it isn’t one for the faint of heart.

If I were to say a suggestion, I’d just use images. They are pretty easy to manipulate and work with. Since you can even compress images inside the jar, there is no reason to even use the Java2D Graphics API for custom images unless you were trying to learn more about it.

Thank you guys for the advice and encouragement!

I don’t plan on going heavy on the textures and imagery I think eventually I will do files but first I want to better understand the libraries i have available. My ultimate goal is to make a isometric 8-bit mmorpg with graphics like zelda nes.