-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblack_hole.c
104 lines (68 loc) · 1.85 KB
/
black_hole.c
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
#ifndef __bh_
#define __bh_
#include "ship.c"
#include "bullet.c"
struct Black_Hole{
//Maximum axis velocity of the bullet
static const double HOLE_VEL = 10.0;
double HOLE_PROPULSION;
LTexture* hole_texture = NULL;
//Initializes the variables
Black_Hole(double, double, double, int);
//sets window and renderer
void set_texture(LTexture*);
//Moves the bullet, return -1 if good, else is the rock hit
int move(Ship);
//Shows the bullet on the screen
void render();
//checks for collisions with rocks or enemies
int collide(Ship);
//The X and Y offsets of the bullet
double mPosX, mPosY;
//degrees of the bullet
double degrees;
double img_radius;
int roto;
};
Black_Hole::Black_Hole(double x, double y, double degree, int d)
{
img_radius = 45;
degrees = degree;
HOLE_PROPULSION = 0;
//Initialize the velocity
mPosX = x;
mPosY = y;
roto = d;
}
void Black_Hole::set_texture(LTexture* text1)
{
hole_texture = text1;
}
int Black_Hole::move(Ship ship)
{
//Move the bullet left or right
if(roto == -1)degrees -= 1;
if(roto == 1)degrees += 1;
int col = collide(ship);
return col;
}
void Black_Hole::render()
{
if(roto == -1)hole_texture->render( mPosX, mPosY, NULL, degrees, NULL, SDL_FLIP_NONE );
else hole_texture->render( mPosX, mPosY, NULL, degrees, NULL, SDL_FLIP_VERTICAL );
}
int Black_Hole::collide(Ship ship)
{
// SHORTCODE: BLACKHOLE COLLISION
if(mPosX + 75 <= ship.mPosX + ship.SHIP_WIDTH
&& mPosX - 75 + hole_texture->mWidth >= ship.mPosX)
{
if(mPosY + 75 <= ship.mPosY + ship.SHIP_HEIGHT
&& mPosY - 75 + hole_texture->mHeight >= ship.mPosY)
{
return 1;
}
}
return -1;
}
#endif