The best way to put units into a game?

Started by
18 comments, last by Evil_Toaster 22 years ago
Heya all. I have been busy coding an isometric engine for the last six months or so, i''ve coded tools to generate isometric tiles and import graphics into the engine. The engine itself has the graphics, map and user input sections working, and i want to add units to it now. I''ve had a look at the articles but i can''t seem to locate one that tells me a good way of putting units into an engine. Could someone perhaps point me to an article or offer some suggestions? The game is an arcade rpg similar to diablo, so i''m looking at putting a lot of units in. Their data structures shouldnt be more than about 15 items i think. Should i put the units in as objects which maintain themselves and check the map when they need to move? Do i put them into a unit manager which runs through arrays of unit data structures? Also, what is a good way of writing an interface between the units and map for pathfinding and collision detection? Thanks -ET
Toaster of exotic breads, scourge of the seven bakeries!
Advertisement
A popular way of doing it is to have a world class, which contains is the map. This class will have some form of list(s) in it (vector/linked list, whatever you want to do) that stores the objects data. Depending on your game, you might want to have different lists for enemies, npc's, items etc, or you can just use one list to store all objects (provided you inherited eveything from a base class). The world class will have a draw method which will draw everything (by calling the draw methods for each object on the map). You can easily control and limit what objects you want to draw etc (ie depending on your position etc).

this is just a very basic overview, but i hope it gave you some ideas.

[edited by - Tylon on March 24, 2002 2:50:12 PM]
Thanks, but thats a little too vague I know sort of what i'm trying to get, but theres a few details that i'm not sure how to get right... Let me get a bit more specific here.. coz i'm running into quite a few problems here...

At the moment i have a map class, it holds the map which is an array of whatever size, it has a camera object inside it which holds the current position of the viewport.

I then have a unit manager which connects to the map manager, so it can see the map and access it to find out what is where. Inside the unit manager i create the units. The units take care of their own movement and drawing procedures, but i'm having problems with visibility from within a unit. The unit doesnt know where it is on the map, and so the draw procedure needs external input. Now, i can solve this by connecting each unit to the map manager aswell and let the units query the map manager about various things, that seems like a bit of a long way around. So what i need to know is how to relate the units to the map properly. From which object do i calculate where the unit is on the map and if the unit is on the screen? I'm just getting myself confused here.

-ET

[edited by - Evil_Toaster on March 24, 2002 4:32:31 PM]
Toaster of exotic breads, scourge of the seven bakeries!
You should put that post in The Iosmetric forum to get help from all the crazy iso people!!

Brian

Doin an isometric game my self.... but it''s more along the lines of X-com...........
TFTD rulez!
I would suggest searching the isometric forum for words such as "units". I know of about 3 such discussions there, and definately when concerned about unit size and tile sizes, etc.

Anyways, here is the short answer to your question:
(A)(best way) You can divide your map into "sectors" or "quads" so that when your camera can view any of these, you run through a vector or linked-list saved for that sector and draw the units in that list.

(B)(easy way?) simply keep your objects sorted by world position. Since you know the range of tiles you can draw by your camera, use this also to draw only objects within camera view as well. This will hurt you later though when you got thousands of objects to search though. Hence the above (a) suggestion helps to cull out unnecessary drawing.

OH...AND BY THE WAY, USE A (X,Y,Z) POSITION TO THE DAMN UNITS, THEN YOU KNOW ITS WORLD POSITION...

[edited by - GalaxyQuest on March 25, 2002 6:12:20 PM]
quote:Original post by Ikus
TFTD rulez!


you mean x-com II ?
yeah, still one of my fav iso games!
Woah, YEAH TFTD is one of the best games ever :D

quite weird to see people who are still fans of it nowdays :D
TFTD = T ? from the deep

F = F*ck*rs
T = Terror

Terror From The Deep

I like this game too... maybe I should play it this evening...

rapso->greets();

This topic is closed to new replies.

Advertisement