samspade
Member
Background, I have enemy ships and player ships. I also have missiles. Generally speaking, missiles can be fired by either the player or the enemy and I simply set a variable (target_class) in the missile so it knows which type of thing to attack.
I would do this with:
where class is an object that other objects inherit from. In this case either player_parent or enemy_parent.
The problem is that I now have missiles that I want to be able to attack other missiles as well as the enemy or the player. It is much more important for my objects to inherit code than a class, so I can't really think of a good way restructure the inheritance so that it works.
I'm debating between various alternative solutions.
Option 1 - a double with loop:
This choice seems to have the advantage that it'll pretty much just work. And the disadvantage of looping through all instances twice.
Option 2 - a variable which tracks class instead of inheritance
This advantage would require more set up, but essentially accomplish the same thing as the original. Should also just work.
Option 3 - Create and maintain my own instance lists
This is the most flexible and I assume would be faster than with but adds a lot more overhead for me to work with, maintain, and mess up (for example I think the above code could cause errors assuming the clean up event runs immediately as it could be removed from the list causing it to skip an instance if I looped forward instead of backwards).
Any suggestions on which of these to choose, or if there are other ways how to handle it?
I would do this with:
Code:
///some missile code
with (target_class) {
//do stuff
}
The problem is that I now have missiles that I want to be able to attack other missiles as well as the enemy or the player. It is much more important for my objects to inherit code than a class, so I can't really think of a good way restructure the inheritance so that it works.
I'm debating between various alternative solutions.
Option 1 - a double with loop:
Code:
with (target_class) {
//do stuff
}
with (missile_class) {
if (other.id != id) {
//do exact same stuff
}
}
Option 2 - a variable which tracks class instead of inheritance
Code:
with (destroyable_parent) {
if (class == other.target_class) {
//do stuff
}
}
Option 3 - Create and maintain my own instance lists
Code:
///create event
//add id to class list
///clean up event
//remove id from class list
///use
for (var i = 0; i < size; i += 1) {
//do stuff
}
Any suggestions on which of these to choose, or if there are other ways how to handle it?