Hi.
This is Aaron from VGA, also known as Valiant8086. I'm replying on list because I wanted to allow for dialogue with other developers. Keeping parts of this conversation public may help others including me in the long run. If you're not interested, feel free to exercise your delete button.


There are several ways to do this. first, I think you're talking about a global list of enemies. How are you determining location. If you make a game board and you try to move the enemy on the board, you'll need to set the handle the previous location had for the enemy to null.

If you're actually making a board here, my favorite way to handle this is to make what I call squares or room objects. These objects are in an array called board or something like that. The objects have handles within them that are of the type needed for every type of object that can be in that room. Each of these handles is probably an array to permit having more than one of that object in the same place. This allows you to support the various types of objects because the primary object the board just has all the other handles as properties. Also, you can make all the enemies the same type of object, and just change the enemy's properties to give the enemy's specific behavior, but it be still the same actual object as the last enemy just with the values all set different, for instance he can walk faster, so on.

Some of my theories don't work the same if you're using a different type of board than I typically use at the moment. For instance a side scroller could probably use a slightly different approach.

If you do use this idea, I have found it useful to create another array that lists handles every one of that type of object in your game at the current time. This array is global and is just a list of handles each pointing to a specific copy of the enemies in the world or weapon etc. Every time you create an object, the object is built as just that, an object. Like this, enemy newEnemy; for example, creates an enemy called newEnemy. You can create this within a function and need not make it global scope, I'll explain why that works.

You immediately upon creation, insert that object into your global array of those objects. Since that array is global, you have now made a global copy of the object. Note that if you need to assign any values on the object, you need do that to the newEnemy before you insert it to the global array or specifically modify the values on the one in the global array instea od the newEnemy object, because once newEnemy goes out of scope as your creation function is finished, newEnemy will no longer exist, but the copy you inserted onto the global array will still be there.

So you use handles to that specific item in the array now to represent that object where ever you need it to be. To destroy the object completely, nuke all handles to it and then remove the object from the array. Remembjer, if you're creating a handle to a handle, such as placing an enemy in a room you make that room's handle point to the handle of the desired object in the global array, you will in fact be working with the object in the global array and any modifications you make using the handle that you have on the room will apply to the object in the global array, assuming you're doing it right. This is a confusing concept that has caused me to have to rewrite big chunks of my games more than once. When I finally get it to work though, it's dead simple to extend, understand, and reuse.

For instance in Yellowbonnet we may have an array called worldCharacters. This is of type character, character is a class I have defined that has all the properties and functions necessary to create something that behaves like a character, it has the talk function, the fight function and so on. I have a function to create a new character, this function might look a little like this

void createCharacter()
{
character newCharacter;
newCharacter.maxStrength = 12; newCharacter.maxHealth = 85; //you get the point here, assign the values at this point before you do what comes next worldCharacters.insert_last(newCharacter); //now that I inserted it, I need to be sure and not try modifying newCharacter in this same function afterwards, because it won't apply to the one in worldCharacters. I could however do something like this int theCharacterIndex = worldCharacters.length-1; //since we just added it to the end of worldCharacters we can create an integer that will help us reference the last item in worldCharacters worldCharacters[theCharacterIndex].currentHealth = worldCharacters[theCharacterIndex].maxHealth;
}

Hope that function is helpful, let's try to explain how you put it on the board

I use methods on the objects themselves to make them move themselves. I essentially can ask worldCharacters[4] for instance, to move east. It will access it's internal set of coordinates that it maintains in order to remain aware of its own location, and then it will insert itself onto the array that the board object in the location the character is moving to has, and finally delete itself from the array in the original location by using insert_last and remove_at methods on those arrays, it takes a little hacking to find the character in the starting location so that the remove_at actually delets the proper one.

I'll leave it there because I don't know if I'm helping at this point. You may be like I was and not have the slightest clue what I'm talking about. It took me quite a bit of experimentation to start to get this to make sense. Tell you what, I'm happy to try and chat with you about this, but I'm profoundly deaf. I prefer to text chat. If you have skype, add aarontech.valiant.
On 11/8/2015 4:22 AM, Gavin Grundlingh wrote:
Hi all,

Could someone please reply to me off list about the following issue I'm having?

I'm trying to create a game board with moving enemies on it. I've created an 
enemy class with various properties and methods, and each time I spawn an 
enemy, I store it in a global enemy array that I also reference using my 
position. The problem is, say I'm at position 10 and the enemy spawns at 
position 4, I can't destroy it when it gets to position 10 because its position 
in the array doesn't change. How can I fix this? Also, how do I put enemies of 
different types inthe array?

Regards,

Gavin
---
Gamers mailing list __ [email protected]
If you want to leave the list, send E-mail to [email protected].
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/[email protected].
If you have any questions or concerns regarding the management of the list,
please send E-mail to [email protected].


---
Gamers mailing list __ [email protected]
If you want to leave the list, send E-mail to [email protected].
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/[email protected].
If you have any questions or concerns regarding the management of the list,
please send E-mail to [email protected].

Reply via email to