-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTower.cpp
102 lines (75 loc) · 1.93 KB
/
Tower.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using namespace std;
#include "Graphic.h"
#include "Enemy.h"
#include "Tower.h"
#include "TowerManager.h"
#include "EnemyManager.h"
#include<iostream>
#include <vector>
#include <sstream>
#include<iostream>
#include<fstream>
#include<GL/glut.h>
#include<math.h>
Tower::Tower(string tempType,int tempX, int tempY){
type = tempType;
myGraphic = new Graphic("rectangle",tempX,tempY);
myGraphic->setDimensions(36,36);
if(type == "Rod"){
myGraphic = new Graphic("Rod",tempX,tempY);
shotSpeed = 12;
power = 2;
}
else if(type == "Gun"){
myGraphic = new Graphic("Gun",tempX,tempY);
shotSpeed = 10;
power = 4;
}
else if(type == "Net"){
myGraphic = new Graphic("Net",tempX,tempY);
shotSpeed = 3;
power = 5;
}
else if(type == "Lightning"){
myGraphic = new Graphic("Lightning",tempX,tempY);
shotSpeed = 8;
power = 6;
}
else if(type == "BP"){
myGraphic = new Graphic("BP",tempX,tempY);
shotSpeed = 10;
power = 7;
}
curShot = shotSpeed;//start
myGraphic->setDimensions(36,36);
};
void Tower::setPosition(int newX,int newY){
myGraphic->setPosition(newX,newY);
}
void Tower::setMe(Tile * newTile){
myTile = newTile;
setPosition( myTile->myGraphic->x, myTile->myGraphic->y );
set = true;
TowerManager::towerAr.push_back(this);
TowerManager::placingTower = NULL;
}
void Tower::update(){
if(curShot == shotSpeed){
for(unsigned int x = 0; x < EnemyManager::enemyAr.size(); x ++){
Graphic tempGraphic("rectangle",myGraphic->x,myGraphic->y);
tempGraphic.setDimensions(myGraphic->width + 100,myGraphic->height + 100);
tempGraphic.setPosition(myGraphic->x,myGraphic->y);
if( TowerManager::hitTest(&(tempGraphic),EnemyManager::enemyAr.at(x)->myGraphic) ){
EnemyManager::shotAr.push_back( new Shot("shotType",this,EnemyManager::enemyAr.at(x)) );
EnemyManager::enemyAr.at(x)->shoot(power);
curShot = 0;
break;
}
}
}
else
curShot ++;
}
void Tower::draw(){
myGraphic->draw();
}