Build a Game From Scratch Using Java and GraphicsGale

For those who are interested in learning how to program a game from scratch using Java, here is a good starting point with a solid working example that you can use. Everything provided is free to use and gives you all the tools you need to get something going.

If you don’t know Java, you will need to learn some basics. You can use the example code provided to start learning. :wink:

Tools You Need:

Eclipse IDE for Java Developers (MARS.1) [[download here ]
GraphicsGale Free Animation software [[download here ]
Tiled – Free tile map editor [[download here ]
Startup Project Files: [ download here ]

After you have the three programs installed and working good, you will need to import the project file into Eclipse.

[]Start Eclipse and click on File->Import
[
]Under General, choose Existing Projects into Workspace and click Next
[]Choose Select archive file and Browse for the startup_project.zip file
[
]In the Projects window, check off Startup and click Finish
[]Expand the Startup folder in the Project Explorer pane
[
]Double-click the Game.java file to open it in the editor
[*]Click Run to see what the code does.

I would also recommend that you make a backup of this folder. I just copy the project in Eclipse and paste it as a different project name before I begin a new game.

What you should happen is your computer will go into full-screen mode at 1024x768 resolution (can be changed to what ever you need) and you should see a FPS counter at the top and a custom mouse cursor. The program basically loads a sprite-sheet and creates a sprite for our mouse cursor and draws it to the screen in place of a windows cursor. To exit the program, press the ESC key on the keyboard.

Sprites:

I’ve included a very cool program for drawing pixel sprites and animations called GraphicsGale. If you don’t have Photoshop or don’t want all the overhead, try this program out.

All artwork is in .PNG format and the transparent color is R255-G0-B255, that bright Fuchsia color. Sprites can be any size; even larger than the screen but I’ve never actually tested it. They are cut out from the SpriteSheet using an x and y coordinate and a width and height value.

Create a new SpriteSheet:

In the SpriteSheet.java class file near the top you will see how the sheets are created as public static SpriteSheets so that they can be used anywhere in the program. This is very useful later on when you need to draw sprites or assign frames to animations, etc.

The .PNG file needs to be placed in your ‘res’ folder in Eclipse in order for it to work with your program. If you are still having problems compiling the program because it cant find the file it could be because you forgot the ‘/’ in front of the file path or you might have to refresh the project folder by right-clicking on it and choosing refresh.

Here is the function definition for creating a new SpriteSheet.

SpriteSheet(width, height, filepath)

example:

SpriteSheet sheetPlayer = new SpriteSheet( 320, 240, “/folder/filename.png” );

Create a new Sprite:

In the Sprite.java class file near the top you will see how the sprites are created as public static Sprites so that they can be used anywhere in the program. This is very useful later on when you need to draw sprites of assign character sprite frames in their animations, etc.

First you need to have created a SpriteSheet where your sprite image data is located. Using the following function declaration, you can cut a sprite out from that SpriteSheet by telling it where it is located x, y and the dimensions of the sprite.

Sprite(x, y, width, height, SpriteSheet)

example:

Sprite playerFrame01 = new Sprite( x, y, w, h, sheetPlayer );

Remelic

Here are the corrected links (I was unable to edit):

Eclipse IDE for Java Developers (MARS.1) [ download here ]
GraphicsGale Free Animation software [ download here ]
Tiled – Free tile map editor [ download here ]
Startup Project Files: [ download here ]

Remelic