When my game is done, I'm going to have 6/7 different weapon types (although I may want to add new weapons in later, so I want to adopt a general technique for handling weapons in the game). At the moment, I have only lasers, and already have 8 methods in a class for that, although 6 of those 8 could be used for other weapon types aswell. So rather than having 6/7 versions of same 6 methods, to handle all the weapons, the plan was to write the code so that 6-10 methods could handle all different weapon types.
Anyway, at present, I use linked lists for the weapons, with different linked lists for the weapon type. That way, every time a laser etc goes off the screen, its just a case of getting rid of that link in the list. But I'm having some problems generalising the code.
These are some of the weapon types:
Code:
/* Laser Structure */
struct LaserStruct
{
unsigned int weapon_position[2];
unsigned int weapon_speed;
LaserStruct *next_weapon;
};
/* Missile Structure */
struct MissileStruct
{
unsigned int weapon_position[2];
MissileStruct *next_weapon;
};
And this is some of the code:
Code:
unsigned int CGameWeapons::GetWeaponPosition(unsigned int array_idx1, void *current_node)
{
if( (array_idx1 < 2)&&(current_node != NULL) )
{
return (current_node->weapon_position[array_idx1]);
}
else
{
return (RETURN_ERROR);
}
}
void CGameWeapons::SetWeaponPosition(unsigned int array_idx1, unsigned int position, void struct *current_node)
{
if( (current_node != NULL)&&(array_idx1 < 2) )
{
current_node->weapon_position[array_idx1] = position;
}
return;
}
Although in order to generalise it, I had to declare the argument to the methods as void (rather than type LaserStruct or MissileStruct - which depends on the type of weapon), and because of that, when I try and compile, it says " `void*' is not a pointer-to-object type ". I understand the problem, but I'm not sure how to solve it.
In the method declaration etc, I did try changing the pointer from type void to type void struct, although that didn't work, lol. Any ideas?