-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bullit.cpp
113 lines (99 loc) · 2.5 KB
/
Bullit.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "Bullit.h"
//constructor
Bullit :: Bullit(float xx, float yy,int dir,int ww, int hh){
setHealth(1);
setDirectionGoing(dir);
setSpeed(30);
setNumOfVertices(3);
setDistance(0);
width = 50;
height = 50;
setXPos((xx+ww/2-width/2)-(xx+ww/2));
setYPos((yy+hh+height+10)-(yy+hh/2));
float dist=sqrt(pow(getXPos(),2)+pow(getYPos(),2));
setXPos(xx+ww/2-width/2+dist*cos(getDirectionGoing()*PI/180));
setYPos(yy+hh/2-height/2+dist*sin(getDirectionGoing()*PI/180));
x=xx;
y=yy;
w=ww;
h=hh;
setNumOfVertices(3);
//define the bullit
vertices[0] = getXPos(); //left x
vertices[1] = getYPos(); //left y
vertices[2] = getXPos()+width; //right x
vertices[3] = getYPos(); //right y
vertices[4] = getXPos()+width/2; //top x
vertices[5] = getYPos()+height; //top y
}
//destructor
Bullit::~Bullit(){}
//methods
int Bullit:: getDistance(){
return Distance;
}
void Bullit:: setDistance(int newDistance){
Distance=newDistance;
}
float Bullit:: getX(){
return x;
}
void Bullit:: setX(float newX){
x=newX;
}
float Bullit:: getY(){
return y;
}
void Bullit:: setY(float newY){
y=newY;
}
int Bullit:: getW(){
return w;
}
void Bullit:: setW(int newW){
w=newW;
}
int Bullit:: getH(){
return h;
}
void Bullit:: setH(int newH){
h=newH;
}
void Bullit:: setVertices(){
//redefine the ship with rap around
if(getXPos()<0-width)
setXPos(2000);
else if(getXPos()>2000 && isAlive())
setXPos(0-width);
if(getYPos()<0-height)
setYPos(2000);
else if(getYPos()>2000 && isAlive())
setYPos(0-height);
vertices[0] = getXPos(); //left x
vertices[1] = getYPos(); //left y
vertices[2] = getXPos()+width; //right x
vertices[3] = getYPos(); //right y
vertices[4] = getXPos()+width/2; //top x
vertices[5] = getYPos()+height; //top y
}
void Bullit:: move(){
setXPos(getXPos()+getSpeed()*cos(getDirectionGoing()*PI/180));
setYPos(getYPos()+getSpeed()*sin(getDirectionGoing()*PI/180));
//glTranslatef(getX()+getW()/2,getY()+getH()/2,0.0);
//glRotatef(getDirectionGoing()-90,0.0,0.0,1.0);
//glTranslatef(-getX()-getW()/2,-getY()-getH()/2,0.0);
//setYPos(getYPos()+getSpeed());
setDistance(getDistance()+getSpeed());
if(getDistance()>=1000){
setAlive(false);
setXPos(3000);
setYPos(3000);
}
setVertices();
glTranslatef(getXPos()+width/2,getYPos()+height/2,0.0);
glRotatef(getDirectionGoing()-90,0.0,0.0,1.0);
glTranslatef(-getXPos()-width/2,-getYPos()-height/2,0.0);
}
char Bullit:: objectIs(){
return 'b';
}