-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shot.cpp
76 lines (64 loc) · 2.08 KB
/
Shot.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
using namespace std;
#include "Shot.h"
#include "Graphic.h"
#include "Enemy.h"
#include "Tower.h"
#include "EnemyManager.h"
#include<iostream>
#include <vector>
#include <sstream>
#include<iostream>
#include<fstream>
#include<GL/glut.h>
#include<math.h>
Shot::Shot(string type, Tower * newTower, Enemy * newEnemy) {
shotTower = newTower;
targetEnemy = newEnemy;
if(shotTower->type == "Gun"){
myGraphic = new Graphic("circle",0,0);
myGraphic->setRadius(4);
myGraphic->setPosition(shotTower->myGraphic->x, shotTower->myGraphic->y);
myGraphic->setColor(191,122,10);
}
else if(shotTower->type == "Rod"){
myGraphic = new Graphic("circle",0,0);
myGraphic->setRadius(4);
myGraphic->setPosition(shotTower->myGraphic->x, shotTower->myGraphic->y);
myGraphic->setColor(255,162,10);
}
else if(shotTower->type == "Net"){
myGraphic = new Graphic("circle",0,0);
myGraphic->setRadius(4);
myGraphic->setPosition(shotTower->myGraphic->x, shotTower->myGraphic->y);
myGraphic->setColor(29,189,8);
}
else if(shotTower->type == "BP"){
myGraphic = new Graphic("circle",0,0);
myGraphic->setRadius(7);
myGraphic->setPosition(shotTower->myGraphic->x, shotTower->myGraphic->y);
myGraphic->setColor(255,255,0);
}
else if(shotTower->type == "Lightning"){
myGraphic = new Graphic("circle",0,0);
myGraphic->setRadius(4);
myGraphic->setPosition(shotTower->myGraphic->x, shotTower->myGraphic->y);
myGraphic->setColor(11,81,230);
}
dead = false;
}
void Shot::update () {
int targetX = targetEnemy->myGraphic->x;
int targetY = targetEnemy->myGraphic->y;
double curXStep = 15 * cos( atan2( (double)(targetY - myGraphic->y),(double)(targetX - myGraphic->x) ) );
double curYStep = 15 * sin( atan2( (double)(targetY - myGraphic->y),(double)(targetX - myGraphic->x) ) );
double targetRotation = atan2( (double)(myGraphic->y-targetY),(double)(myGraphic->x-targetX) );
if( fabs(targetX - myGraphic->x ) > 3 && !targetEnemy->dead)
myGraphic->setPosition( myGraphic->x + curXStep, myGraphic->y + curYStep );
else{
dead = true;
}
}
void Shot::draw () {
if(!dead )
myGraphic -> draw();
}