-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bullet.cpp
103 lines (90 loc) · 1.98 KB
/
Bullet.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
#include "Bullet.h"
Bullet::Bullet(float x, float y, float mouseX, float mouseY, int gun){
float velX = 0;
float velY = 0;
float angle = 0;
Bullet::distanceTraveled = 0;
Bullet::gun = gun;
SetID(BULLET);
if(mouseX - x >= 0){
angle = atan((mouseY - y)/(mouseX - x));
}
else{
angle = atan((mouseY - y)/(mouseX - x)) + M_PI;
}
float distance = sqrt((x - mouseX)*(x - mouseX) + (y - mouseY)*(y - mouseY));
switch(gun){
case PISTOL:
vel = 10;
velX = vel*cos(angle);
velY = vel*sin(angle);
//how many pixels the bullet travels;
range = 200;
SetDamage(50);
damage = 50;
//maxBullets = 3;
break;
case SHOTGUN:
vel = 10;
velX = vel*cos(angle);
velY = vel*sin(angle);
//how many pixels the bullet travels;
range = 100;
SetDamage(50);
damage = 50;
//maxBullets = 1;
break;
case RIFLE:
vel = 20;
velX = vel*cos(angle);
velY = vel*sin(angle);
//how many pixels the bullet travels;
range = 500;
SetDamage(100);
//maxBullets = 1;
break;
}
//std::cout << "velY:: "<< velY << std::endl;
GameObject::Init(x, y, velX, velY, 1, 1, 0, 0, 0);
}
void Bullet::Destroy(){
}
void Bullet::Update(GameObject *otherObject){
if(GetAlive()){
GameObject::Update(otherObject);
//this needs to change depending on the gun
distanceTraveled += vel;
if(distanceTraveled > range)
SetAlive(false);
if(x < LEVEL_LEFT_X)
SetAlive(false);
else if(x > LEVEL_RIGHT_X)
SetAlive(false);
else if(y < LEVEL_TOP_Y)
SetAlive(false);
else if(y > LEVEL_BOT_Y)
SetAlive(false);
}
}
void Bullet::Render(){
if(GetAlive()){
switch(GetGun()){
case PISTOL:
al_draw_filled_circle(x, y, 2, al_map_rgb(255, 255, 255));
break;
case SHOTGUN:
al_draw_filled_circle(x, y, 2, al_map_rgb(255, 255, 255));
break;
case RIFLE:
al_draw_filled_circle(x, y, 2, al_map_rgb(255, 255, 255));
break;
}
}
}
void Bullet::Collided(GameObject *otherObject){
if(otherObject->GetID() == ENEMY){
//switch(GetGun())
//damage the enemy
SetAlive(false);
}
}