Hi,
DaSnipeKid wrote:
Anyways i have been looking into Java Programming for a while and i can't seem to find a way of learning how to make games at least 2D games. There are some things out there but its just the code and it does not tell you how/why did you need that and how to use it. If there is ever a good tutorial i have always wanted to know how to continue from where i am but it just seems impossible.
With 'normal' programming, you get input, do some calculations, output the answer, and you are finished.
In a game you do
Code:
world = new World();
for (;;) {
world.display();
inp = getUserInput();
world.processInput(inp); // Update the world with what the user did
}
This is about as simple as you can have it.
For a game of hangman, 'world' is the hidden word you have to guess, the letters you have guessed so far, and how often you guessed wrong. 'display' shows the letters you have guessed right, and how close you are to losing. The user input gets a new letter from the user, and 'processInput' updates the 'world' with the new letter.
(for simplicity, I left out details like leaving the loop when you lose or win, but that should be simple to add).
A game like tetris also fits in this pattern. In that case, the user input can be empty (if you don't press any button).
There is nobody that says output must be done with
System.out.printf("text\n"); // Sorry, but being a C/C++ programmer, I use printf in Java as well :)
If you store positions of tetris blocks, you can also 'print' by drawing images at the right place.
If you loop above 20-30 times a second, you get fluent motion (if you move the position a small amount every iteration).
So there you have it. Add a 'global' world to the program, and loop repeatedly, getting input from the keyboard/mouse, and 'printing' by drawing graphics at the right place, and you have a game. :)
Happy exploring this world :)
_________________
My project: Messing about in
FreeRCT,
dev blog, and IRC #freerct at oftc.net