I sort of have a diffent approach and things to think about.
First once the bullet, laser pulse, etc. has left the gun, it should become it own object.
// Define ammo
typedef struct
{
int player; // who fired it!
int type; // 0 = hand, 1 = bullett, etc.
int range;
int speed;
// start_position
int c_x, c_y, c_z;
// direction vector
int v_x, v_y, v_z;
// current_position
int c_x, c_y, c_z; once the distance between start and current exceed range kill object.
}
// Define weapon
typedef struct
{
int type; Type of weapon
int damage;
int firing_rate; How fast can it shoot, hand gun vs. machine gun
int speed; bullett vs. laser
int range; hand vs. bullett
int picked_up; Does the player have the gun.
int ammo; current ammo supply
int ammo_max; max ammount he can carry.
}Weapon;
// Define player
typedef struct
{
char name[30];
weapon Weapon[8]; // Max weapons in game are 8 but could be what ever number
int score;
int healt;
int gun_selected;
}Player;
static struct Player player[8];
example:
shoot()
{
if (player[0].weapon[player[0].gun_selected].ammo > 0) // Check to see if any ammo left to shoot
{
spawn_shot(player[0].weapon[player[0].gun_selected])
player[0].weapon[player[0].gun_selected].ammo–; take away ammo.
}
I hope this helps.
Originally posted by Leyder Dylan:
[b]Hi,
I’ve a problem with my structure. I’d like to use
a structure for storing the weapons + params and
the bullet fired.
Here’s my structure :
// **********************************************
typedef struct
{
char Name[25];
float x, y, z;
int Speed, Power;
} WEAPON_CONFIG;
// **********************************************
typedef struct
{
int Number_Weapon;
WEAPON_CONFIG* Bullet;
} WEAPON;
For using the structure, I initialise it with :
WEAPON Weapon_Use;
And in my program, I use the structure like this :
Weapon_Use.Bullet[i].Name[0] = …
Weapon_Use.Bullet[i].Power = …
etc …
In fact, I’d like to use a structure like this :
Weapon_Use[0].Bullet[0].Power = …
The “Weapon_Use” variable will be used for storing each weapon
(Desert Eagle, Magnum, …)
And the “…Bullet” variable will be used for each bullet fired.
How can I adapt this structure :
Weapon_Use.Bullet[0].Power
In this :
Weapon_Use[0].Bullet[0].Power
Thanks in advance …[/b]