rendered paste body#include "weapons.h"
#include "globals.h"
#include "players.h"
#include "runningGameScenes.h"
#include <iostream>
// ====================== GLOBALS =============================
using namespace std;
vector <iteam::IT_Weapon> iteam::WeaponsList;
namespace iteam {
// ====================== WEAPONS =============================
weapon::weapon() {
// initialise the weapon
}
void weapon::SetBeginPosition(GLfloat nx, GLfloat ny, GLfloat new_angle) {
x = nx;
y = ny;
angle = new_angle;
//cout << "[WEAPONS COORDS] x = " << x << " y = " << y << " angle = " << angle << "\n";
}
void weapon::SetAcceleration(GLfloat new_accel, GLfloat new_angle) {
// apply a force for to the accelleration of the
GLfloat wrap_test;
acceleration = new_accel;
wrap_test = angle + new_angle;
// seeing as floats can go greater than
if(wrap_test > 360) { // does the adding of these two angle wrap over 360 then turn is back within a 360 range value
angle = (angle + new_angle) - 360;
}
if(wrap_test < 0) { // does if go less than 1? then turn it positive again
angle = (angle + new_angle) + 360;
}
}
void weapon::CaclulateVelocity(void) {
vel_x = acceleration * (GLfloat) cos(angle);
vel_y = acceleration * (GLfloat) sin(angle);
acceleration += IT_FRICTION;
}
void weapon::MoveMe(void) {
CaclulateVelocity();
this->x += vel_x;
this->y += vel_y;
//this->y -= IT_GRAVITY;
// cout << "[WEAPONS PHYSICS] x = " << x << " y = " << y << " vel_x = " << vel_x << " vel_y = " << vel_y << "\n";
}
// ==================== WEAPON CLUSTERS =========================
void AddWeaponTypeToWeaponList(int TypeID) {
// add this weapon to the cluster
WeaponsList.push_back(IT_Weapon()); // add a new weapon type to the weapons list
WeaponsList[WeaponsList.size()-1].TypeID = TypeID;
WeaponsList[WeaponsList.size()-1].Active = false;
}
void AddComponent(int WeaponID, int TypeID, const char texture[], bool IsPhysical, bool Bounces, GLfloat BlastRadius, GLfloat Elasticity) {
WeaponsList[TypeID].components.push_back(weapon()); // add a new component to the weapons type
//cout << "[WEAPONS] Adding texture\n";
WeaponsList[ TypeID ].components[ WeaponsList[ TypeID ].components.size()-1 ].Load(texture);
//cout << "[WEAPONS] Added texture " << texture << "\n";
// set the main values for this conponent
WeaponsList[ TypeID ].components[ WeaponsList[ TypeID ].components.size()-1 ].WeaponID = WeaponID;
WeaponsList[ TypeID ].components[ WeaponsList[ TypeID ].components.size()-1 ].Visible = false;
WeaponsList[ TypeID ].components[ WeaponsList[ TypeID ].components.size()-1 ].IsPhysical = IsPhysical;
WeaponsList[ TypeID ].components[ WeaponsList[ TypeID ].components.size()-1 ].BlastRadius = BlastRadius;
WeaponsList[ TypeID ].components[ WeaponsList[ TypeID ].components.size()-1 ].Bounces = Bounces;
WeaponsList[ TypeID ].components[ WeaponsList[ TypeID ].components.size()-1 ].Elasticity = Elasticity;
}
// ==================== WEAPON FUNCTIONS ========================
int FireWeapon(int TypeID, GLfloat nx, GLfloat ny, GLfloat new_angle, GLfloat new_accel) {
// Set the angle to fire it at
int i;
WeaponsList[0 ].Active = true;
//cout << "[FIRE WEAPON] TypeID = " << TypeID << "\n";
//cout << "[WEAPONS] x = " << nx << " y = " << ny << " angle= " << new_angle << " accel = " << new_accel << "\n";
for(i=0; i < WeaponsList[ 0 ].components.size(); i++) {
// cout << "[FIRE WEAPON] TypeID = " << TypeID << "\n";
WeaponsList[ 0 ].components[ i ].SetBeginPosition( nx, ny, new_angle);
WeaponsList[ 0].components[ i ].SetAcceleration(new_accel, (GLfloat) 0.0);
WeaponsList[ 0 ].components[ i ].Visible = true;
}
return(0);
}
// ==================== TEST FUNCTIONS ============================
void Test_Init(void) {
AddWeaponTypeToWeaponList(IT_WT_GRENADE);
cout << "[WEAPONS] Added weapon type\n";
AddComponent(IT_WC_GRENADE, IT_WT_GRENADE, "data/weapons/grenade.png", true, false, (GLfloat) 20.0, (GLfloat) 0.80);
cout << "[WEAPONS] Added component\n";
}
void Test_Fire(void) {
int retval = FireWeapon( IT_WT_GRENADE, Player[CurPlayer].x, Player[CurPlayer].y, (GLfloat) 180.0, (GLfloat) 10.0);
}
// ====================
void UpdatePhysicalObjects(void) {
// update any active weapons
int i,j;
// cout << "[WEAPON PHYSICS] WeaponList is " << WeaponsList.size() << " items long\n";
for(i=0; i < WeaponsList.size(); i++) { // loop through each weapon in list and test if its active
// cout << "[WEAPON PHYSICS] Weapon " << i << " searched\n";
if(WeaponsList[i].Active == true) { // seems to be active so process the componets
for(j=0; j < WeaponsList[i].components.size(); j++) { // move each component
// cout << "[WEAPON PHYSICS] Weapon " << i << " is active\n";
WeaponsList[i].components[j].CaclulateVelocity();
WeaponsList[i].components[j].MoveMe();
Cam.Begin();
WeaponsList[i].components[j].Draw(0);
//cout << "[WEAPON PHYSICS] x = " << WeaponsList[i].components[j].x << " y = " << WeaponsList[i].components[j].y << "\n";
}
}
}
// this may include any players eventually as all moving things
// in the scene will be reacting to gravity etc.
}
} // namespace iteam closed