beginning with game programming question

I'm just wondering...I've just began with game programming and I can't understand one thing: when you paint all the graphics...how can you program in code what to show? It may sound a bit wierd but maybe I asked it wrong. I mean, imagine a big roleplaying game, with a pretty big world...how does the source code look like in teh paint() method? A world can be huge but still, you don't paint it at the same time. do you have the "map" somehow saved in a file and the code reads from the file what to show depending on where the character is?

I really don't understand how this works.

Hope anyone has the time to help me with this.

Thanx a lot

[673 byte] By [Flawe] at [2007-9-27 22:15:41]
# 1

First of all, you are most likely using double buffering or BufferStrategy, this makes things a lot simplier, because you are drawing directly to them, no anywhere else.

Secondly in RPG, you probably want to draw the map first, the set up inter action between the map and the sprites such as monsters and pc. All this is called one thing. The engine.

The engine works out the interaction between the sprites, you can use a specific class for this, but I prefer to use engine. Thirdly, the engine draws everything. It says what to draw, when, and where. It interacts with the monster AI and the PC(personal character) movement, invoking inventory and drawing all sorts of things, such as graphical effects.

There must also be way for the engine to interact with key/mouse input and load images, for these you might want to create own classes like inputManager and loadManager or something similar.

So you won't most likely use paint at all, but in the main call something like

gameEngine engine = new gameEngine(Frame, Managers, Otherstuff, DoubleBuffering, whatEver);

Now if you want to start the game, you put

engine.start();

or something similar.

OlliPekka at 2007-7-7 12:29:49 > top of Java-index,Other Topics,Java Game Development...
# 2

> asked it wrong. I mean, imagine a big roleplaying

> game, with a pretty big world...how does the source

> code look like in teh paint() method? A world can be

> huge but still, you don't paint it at the same time.

> do you have the "map" somehow saved in a file and the

> code reads from the file what to show depending on

> where the character is?

> I really don't understand how this works.

2D or 3D?

although the theory between the 2 is essencially identical, the implementation is very different.

Take Diablo for example, it simply segments the world into levels, and segments each level into areas. The game only needs to have 1 or 2 areas in memory at a time. When you move from 1 area, to the next, it simply streams the new area into memory from a file. (this does cause a little slow down, but, each area is fairly small, and unless you are playing on a machine with little memory, the game will cache old areas, in the event you back track)

on the other hand, you have Morrowind, arguably the most complex, and impressive 3D RPG made to-date. The way Morrowind handles the vast area it covers, is to break the world down into 'cells' each cell covers roughly a 200metre square of the landscapes geometry.

each time the player avatar moves into a new cell, the next cell is streamed from the datafile. (in a similar way to diablo, though there is far far more data in Morrowind)

there are several obvious optimisations, for instance, if you have a forest of 100 identical trees, you don't need to store 100 copies of the geometry, you just need 1, and the locations to place the other 99.

Also, another important fact, is that the geometry for inside environments is far more dense than for outside landscapes.

Morrowind deals with this, by seperating the 'world' into 2,

you have the outside world, which consists of the hills, trees, outsides of buildings etc.

you then have the inside world, which is simply the geometry for the insides of buildings.

The transition between the 2 is achieved through 'Portals', a portal maybe a door, a trap door, a sewage pipe etc.

Whatever form it takes in the environment, it is simply a mechanism by which the game can pause the gameplay, and allow the appropriate data to be loaded in. (without the player getting frustrated, and start hitting things :)

hope that helps.

Abuse at 2007-7-7 12:29:49 > top of Java-index,Other Topics,Java Game Development...
# 3

> I'm just wondering...I've just began with game

> programming and I can't understand one thing: when you

> paint all the graphics...how can you program in code

> what to show? It may sound a bit wierd but maybe I

If you use Java 3D you take a highlevel approach. You don't think in terms of how to render things. Instead you populate a scene with grafic objects. You can manipulate this scene, for example switch on light from some direction, etcetera. The user can pan, rotate and zoom the scene. Java 3D knows what is visible at all times and displays that on the screen.

uj at 2007-7-7 12:29:49 > top of Java-index,Other Topics,Java Game Development...
# 4

My two pences :

Don't focus right from the start on the interaction between the engine and the renderer. These should be two very different things if you want your game to have a good design and be easily extensible. Take example on the MVC design pattern of Swing components.

So in your case, you will have a sub system handling the Model (the world and the different objects: ennemies, NPC, ...). And you will also have a sub system dedicated to rendering: the View. This renderer will manage the interaction with the AWT Graphic components and will get information from the Model to display them. The Controller will be in charge of collecting events (mouse, keyboard, ...) and giving them to the Model.

You can check the following links for more information on MVC:

http://www.javaworld.com/javaworld/jw-04-1998/jw-04-howto.html

http://ootips.org/mvc-pattern.html

http://java.sun.com/docs/books/tutorial/uiswing/overview/swingFeatures.html#model

Good luck !

lossendil at 2007-7-7 12:29:49 > top of Java-index,Other Topics,Java Game Development...
# 5
oh wow, thanx a lot guys.I kinda get it now but i guess i have to read a lot before starting a project this big. The good thing is that I got my hopes up for Java again ;)Thanx a lot
Flawe at 2007-7-7 12:29:49 > top of Java-index,Other Topics,Java Game Development...