-
Notifications
You must be signed in to change notification settings - Fork 0
/
rock.c
142 lines (97 loc) · 2.79 KB
/
rock.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#ifndef ____rock__
#define ____rock__
/***********************************************************************/
#include "LTexture.c"
struct Rock{
//Maximum axis velocity of the bullet
double ROCK_VEL;
double ROCK_PROPULSION;
LTexture* textures[4];
//Initializes the variables
Rock(double, double, double, int);
//sets window and renderer
void set_texture(LTexture*, LTexture*, LTexture*, LTexture*);
//Moves the bullet
bool move(int, int);
//Shows the bullet on the screen
void render();
//The X and Y offsets of the bullet
double mPosX, mPosY;
//The velocity of the bullet
double mVelX, mVelY;
//degrees of the bullet
double degrees;
int size;
};
/***********************************************************************/
/***********************************************************************/
Rock::Rock(double x, double y, double degree, int s)
{
ROCK_VEL = 10.0;
ROCK_PROPULSION = 0.2;
textures[0] = NULL;
textures[1] = NULL;
textures[2] = NULL;
textures[3] = NULL;
degrees = degree;
size = s;
//Initialize the offsets to center of image
mPosX = x;
mPosY = y;
//Initialize the velocity
mVelX = cos((degrees) /(180.0 / M_PI)) * 10.0;
mVelY = sin((degrees) /(180.0 / M_PI)) * 10.0;
mPosX += mVelX;
mPosY += mVelY;
}
void Rock::set_texture(LTexture* text_100, LTexture* text_66, LTexture* text_33, LTexture* text_11)
{
textures[0] = text_100;
textures[1] = text_66;
textures[2] = text_33;
textures[3] = text_11;
}
bool Rock::move(int screen_w, int screen_h)
{
// SHORTCODE: ROCK MOVE
double xVar = mVelX * ROCK_PROPULSION;
double yVar = mVelY * ROCK_PROPULSION;
if(size == 100) degrees -= 1;
if(size == 66) degrees += 1;
if(size == 33) degrees -= 1;
if(size == 11) degrees -= 1;
mPosX += xVar; mPosY += yVar;
if(mPosX <= size*-1) {
mPosX = screen_w;
}
if(( mPosX > screen_w + 15)) {
mPosX = 0;
}
if( mPosY <= size*-1 ){
mPosY = screen_h;
}
if ( mPosY > screen_h + 15){
mPosY = 0;
}
return true;
}
void Rock::render()
{
if(size == 100)
{
textures[0]->render( mPosX, mPosY, NULL, degrees, NULL, SDL_FLIP_NONE );
}
else if(size == 66)
{
textures[1]->render( mPosX, mPosY, NULL, degrees, NULL, SDL_FLIP_NONE );
}
else if(size == 33)
{
textures[2]->render( mPosX, mPosY, NULL, degrees, NULL, SDL_FLIP_NONE );
}
else if(size == 11)
{
textures[3]->render( mPosX, mPosY, NULL, degrees, NULL, SDL_FLIP_NONE );
}
}
#endif /* defined(____rock__) */