![]() |
![]() |



Author: Mattxl
Date Submitted: 2004-01-01 00:00:22
Downloads: cg_projectile.cpp
Projectile Source Instructions
This is all in the client code. If you have multiplayer just move the appropriate functions to where they should be and link them through the client - server code. There's 5 steps.
1) Add cg_projectiles.cpp to your cgame project.
2) In cg_local.h add the following typedef struct for the projectiles.
typedef struct cg_projectile_s
{
int id1;
int id2;
int model;
int particle_1;
int particle_2;
float speed;
iteminfo_t projectile;
vec3_t origin;
vec3_t axis[3];
iteminfo_t particle1;
iteminfo_t particle2;
struct cg_projectile_s *next;
}cg_projectile_t;
3) Then declare an extern pointer of the struct in cg_local.h to manage the linked list.
extern cg_projectile_t* cg_prolist;
4) Expose all the following functions to the game code by putting them in cg_local.h.
// cg_projectile.cpp
void ProjectileInit(void);
void CreateProjectile(int model, float speed, vec3_t origin, vec3_t axis[], int particle_1, int particle_2);
void UpdateProjectiles(void);
void MoveProjectiles(void);
void CollideProjectiles(void);
void DrawProjectiles(void);
cg_projectile_t* ProjectileFindEnd(void);
void DeleteProjectile(cg_projectile_t* projectile);
void DestroyProjectiles(void);
5) Declare the pointer in cg_main.c so that the game code can use it.
cg_projectile_t* cg_prolist;
After that, just put all the model and particle loading in ProjectileInit() and call it where you load your files. To create a projectile, call CreateProjectile() with all the appropriate info. Model being the projectile's model int from registering. Speed being a float value of how much to increment every frame (try 0.1f for really slow). Origin being where it starts. Axis being the axis of the camera or other so it travels in the right direction. Particle_1 and Particle_2 being the int returned from registering the particle system (pass NULL if not used).Download the file and copy the source instructions.
A few modifications to the movement need to be made and the inaccuracy level needs to be added. I'll get right on it and release a new cpp file when it's done. Until then, have fun experimenting with it.
[Recent Contributions] [Recent Source Code]
User Contributed Comments