HomeNewsFeaturesLicensingDownloadsScreenshotsFAQRoadmap Contact Us
Search:
9 Online

Community

Discussion Topics Recent Postings User Contributions General Articles Example Documentation Credits

Licensed Developer

Programmer's Manual Artists Manual Tutorials and Articles

Programming: Game Code

Game Code Overview Server Side Game Code Client Side Game Code

Programming: System

Alphabetical Function List Renderer File System Collision & Ray Casting Low Level Audio Game Audio The Console Console Variable List Multiplayer Localisation Maths Library Memory Manager Model File Formats Texture Formats

Art: Overviews

Specifications Shaders Particle Systems Lens Flares Cipher console Cipher file types Tutorials Reference

Art: Tools

Shader Designer Particle Designer 3dsmax tools Model Conversion Font Generator

Cipher Engine
Game Development Search Engine
GameDev.net
You are not signed in - [sign in] [register]

Projectiles

Overview

Author: Mattxl
Date Submitted: 2004-01-01 00:00:22
Downloads: cg_projectile.cpp

Source Code

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).


Description

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

Mattxl 1st January, 2004 16:03
Oopps! Sorry about the formatting. It shouldn't have made those long ones all one line. Also I forgot to mention, call UpdateProjectiles() once every frame. It handles the movement, collision, and drawing.


Mattxl 23rd January, 2005 14:28
I keep forgetting to let everyone know that I fixed all the bugs in this code and it works much more effecient now. I have been extremely busy lately so I haven't had much time to do any uploading. Anyways... anyone who wants the new code just post here with your email address or email me and I'll send it to you.

mattxl20@msn.com

Matt


Rhuarc 23rd January, 2005 15:02
I'd like to try it out :). Anything to help me familiarize myself with the engine more is great.

rhuarc@shadowforgeserver.net


dakz0rz 11th March, 2005 01:11
heya mattxl... can you please send me your latest copy of it?
thanks in advance

dakz0rz@gmail.com


Krezling 16th March, 2005 17:48
Could you send me the latest version of that code please?
Thanks

super_trd@hotmail.com




Register and Sign In to discuss this article