-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBullet.cpp
96 lines (93 loc) · 1.67 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
#include "hge.h"
#include "hgesprite.h"
#include <iostream>
using namespace std;
extern HGE *hge;
class Bullet
{
private:
hgeSprite* sprite;
HTEXTURE tex;
float x, y;
float dx;
float dy;
float speed;
double friction;
enum direction {LEFT, RIGHT, UP};
direction d;
bool state;
public:
Bullet()
{
x = 0; y = 0;
d = RIGHT;
dx = 0; dy = 0;
speed = 200;
friction = 0.7;
sprite = new hgeSprite(0, 7, 7, 7, 7);
state = false;
}
void shoot(float x, float y, int d)
{
this->x = x; this->y = y; this->d = (direction)d;
this->state = true;
cout << "bang!\n";
}
void Update()
{
float dt=hge->Timer_GetDelta();
switch(d)
{
case LEFT:
dx-=speed*dt;
// Do some movement calculations and collision detection
dx*=friction; dy*=friction; x+=dx; y+=dy;
break;
case RIGHT:
dx+=speed*dt;
// Do some movement calculations and collision detection
dx*=friction; dy*=friction; x+=dx; y+=dy;
break;
case UP:
dy-=speed*dt;
// Do some movement calculations and collision detection
dx*=friction; dy*=friction; x+=dx; y+=dy;
break;
}
}
void Render()
{
sprite->Render(x, y);
}
bool GetState()
{
return state;
}
void Reload()
{
state = false;
}
float GetX()
{
return x;
}
float GetY()
{
return y;
}
void LoadTexture()
{
tex = hge->Texture_Load("Bullet1.png");
if(!tex)
{
MessageBoxA(NULL, "Can't load one of the following files:\n Bullet.png", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
hge->System_Shutdown();
hge->Release();
}
sprite->SetTexture(tex);
}
void Kill()
{
state = false;
}
};