Adding code for weapons

This commit is contained in:
zombidust 2014-04-11 00:49:55 +03:00
parent 2c1e7f1f4e
commit 1faf1d0881
2 changed files with 51 additions and 0 deletions

18
source/weapons.cpp Normal file
View File

@ -0,0 +1,18 @@
#include "weapons.h"
void Weapon::init(int type, int pType, int pSpeed, int rof, int dmg, std::vector<BaseProjectile*> *projectiles) {
type_ = type;
projectileType_ = pType;
projectileSpeed_ = pSpeed;
rof_ = rof;
damage_ = dmg;
projectiles_ = projectiles;
}
void Weapon::fire(Player player, Point map, int size, std::vector<SDL_Rect> *obstacles) {
(*projectiles_).push_back(new BaseProjectile(player, damage_, map, size, projectileType_, obstacles, projectileSpeed_));
}
int Weapon::getRof() {
return rof_;
}

33
source/weapons.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef WEAPONS_H_
#define WEAPONS_H_
#include "point.h"
#include "projectiles.h"
#include "entities.h"
#include <vector>
class Weapon {
int type_;
int projectileType_;
int projectileSpeed_;
int rof_;
int damage_;
std::vector<BaseProjectile*> *projectiles_;
public:
Weapon()
: type_(0),
projectileType_(0),
projectileSpeed_(10),
rof_(4),
damage_(0),
projectiles_(NULL)
{}
void init(int type, int pType, int pSpeed, int rof, int dmg, std::vector<BaseProjectile*> *projectiles);
void fire(Player player, Point map, int size, std::vector<SDL_Rect> *obstacles);
int getRof();
}
#endif