PDA

View Full Version : Multiple Simultanious Operations



TheElusiveYak
26-01-2005, 04:52 PM
Hi I'm working in TP7.0 and im writeing a 2D tilebased game. How does one work in the movements of the npc's and have instantaneoud reaction when you try to move your charicter? The NPC's are working on a crude but complex AI system that varies in the time to process the commands. Also how do you add in a time system so that the npc's age, crops grow ect. I am doing the map as a 2d linked list grid, is that a bad idea? I'm fairly new so any help would be very appriciated.

TheLion
26-01-2005, 05:58 PM
Those are a lot of questions in one post! ;) hehe

Like with everything in the programming world, there are multiple solutions for what you are asking... All I can do is give you some theories that popped up into my brain while reading your post:

-> Movement of AI and player: Most commonly this is done by moving one of the two first, if you move the AI chars first and then move you can first check if the AI chars collide anywhere while moving and then check the player against the new AI chars for collisions while moving... If you think about it, it is highly unlikely that 2 people start moving at the exact same millisecond, so it doesn't matter if one starts moving a millisecond before your player and makes your player collide... A frame is VERY short, so this will be not really noticable! ;)

-> Time: Sounds like a cool idea, almost Creatures like! ;) I have never done this but the idea that popped in my brain was to give them a default lifespan and adding a random value to it or substracting a random value from it... then every Xth frame or you do some sort of GetTickCount() calculation and determine that after every 5 minutes a year passes (or something like that), and go through a list of your "age affected sprites" and do something with their lifespan, in the case of people you can substract a constant value from their life span and pick a picture according to their lifespan (very young, older, old-folk, ancient). With crop, well for crop you would need a smaller scale than years but of course you can always adjust the scale, so say you adjust the scale to, say 30 secs for each month, so every month you increase the cropstate (0 = draw dirt tile, 1 = draw very small plant tile, 2 = draw small crop tile, 3 = draw crop, 4 = if harvested draw dirt, otherwise rotting crop, etc). A very simple approach and of course it has to be optimised and adjusted to your own view! ;)

When making a turn-based game, you can of course do it a lot easier by simply saying each turn equals a quarter year! ;)

P.S. For almost really doing things simulataniously you should look into threads. Threads allow you do multiple things at the same time (almost like running 2 seperate apps in your own application), in which you could for example keep a real-time timer running. I would suggest you study threads carefully tho, how cool they might be they can also be dangerous if implemented badly (well in the sense of crashing your app and making it unstable) and they could also cause your application to start sucking CPU power ... again if implemented badly! ;) For games however I would suggest trying to do as much as you can in your game loop and only resort to threads when there is no other option available! ;)


P.S. For really making your game characters come alive and look a bit different each time (since you are thinking about aging you might be thinking about rebirthing and dying AI as well) you should look into Genetic Algorithms, they are not too hard to do and they could really give your game a very interesting feature! ;)

Lightning
26-01-2005, 06:19 PM
Hi I'm working in TP7.0 and im writeing a 2D tilebased game
Ah the old days of DOS programming :D
I still have some BGI drivers capable of 1024x768 and 65535 colors :drunk:
Well from what i know you don't have threads in DOS but i hurd they can be implemented, back in the old days i used interrupts for keyboard, timer, and you could make something similar to a thread with them.
Some guys want to make a DOS version of Lazarus (that would be extremly hard for my brain :) ).
About movement, where is the problem, if you know how to get the mouse position you could use a list or a matrix to store your objects on the map and move them in the list/matrix then draw the map+objects in a off-screen matrix(image) or a page if your driver supports pages then swich the page or draw the matrix to the screen
Well you might get more information at http://www.freepascal.org

TheElusiveYak
26-01-2005, 09:01 PM
Thanks for the help, actually I already thought of implementing a genetics factor in the game. The overall object is to make a self reproducing population of lifelike individuals and they will be able to farm, hunt, and build on their own :). Thanks again for your help!

TheLion
27-01-2005, 08:11 AM
Hi I'm working in TP7.0 and im writeing a 2D tilebased game
Ah the old days of DOS programming :D

If I'm correct Turbo Pascal 7 also supports Microsoft Windows programming. I think we used Pascal 7 in school using the windows "GUI" and I remember seeing windows functions in the help manual... It could be tho that there is a difference between Turbo Pascal 7 and Turbo Pascal 7 for Windows. :) Oh wait that's Borland Pascal 7.0 ... the one with Windows support... okay my fault! ;) *confusing names* :roll: