-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpower.cpp
More file actions
executable file
·123 lines (87 loc) · 2 KB
/
power.cpp
File metadata and controls
executable file
·123 lines (87 loc) · 2 KB
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
#include "power.h"
#include <cmath>
#define PI M_PI
using namespace std;
power::power(){
x = 0;
y = 0;
type = 1;
count = 0;
}
// Function to change properties
void power::set( int nx, int ny, int ntype ){
x = nx;
y = ny;
type = ntype;
}
// Get functions
int power::getx(){
return x;
}
int power::gety(){
return y;
}
int power::getType(){
return type;
}
// Check if ship has collided with powerup
int power::check_collision( double nx, double ny ){
if(!type){
return 0;
}
if( sqrt(pow(x-nx,2)+pow(y-ny,2)) <= 30 ){
return 1;
}
return 0;
}
// Draw function
void power::draw( SDL_Surface* screen, Uint32 color ){
if( type ){
int size = 10;
double ax = x+size*cos(0);
double ay = y+size*sin(0);
double bx = x+size*cos(PI/3);
double by = y+size*sin(PI/3);
double cx = x+size*cos(2*PI/3);
double cy = y+size*sin(2*PI/3);
double dx = x+size*cos(PI);
double dy = y+size*sin(PI);
double ex = x+size*cos(4*PI/3);
double ey = y+size*sin(4*PI/3);
double fx = x+size*cos(5*PI/3);
double fy = y+size*sin(5*PI/3);
Draw_Line(screen, ax,ay, bx,by, color);
Draw_Line(screen, bx,by, cx,cy, color);
Draw_Line(screen, cx,cy, dx,dy, color);
Draw_Line(screen, dx,dy, ex,ey, color);
Draw_Line(screen, ex,ey, fx,fy, color);
Draw_Line(screen, fx,fy, ax,ay, color);
size = 14;
ax = x+size*cos(0);
ay = y+size*sin(0);
bx = x+size*cos(PI/3);
by = y+size*sin(PI/3);
cx = x+size*cos(2*PI/3);
cy = y+size*sin(2*PI/3);
dx = x+size*cos(PI);
dy = y+size*sin(PI);
ex = x+size*cos(4*PI/3);
ey = y+size*sin(4*PI/3);
fx = x+size*cos(5*PI/3);
fy = y+size*sin(5*PI/3);
// Adds rotation effect
if (count <= 15){
Draw_Line(screen, ax,ay, bx,by, color);
Draw_Line(screen, cx,cy, dx,dy, color);
Draw_Line(screen, ex,ey, fx,fy, color);
}else{
Draw_Line(screen, fx,fy, ax,ay, color);
Draw_Line(screen, dx,dy, ex,ey, color);
Draw_Line(screen, bx,by, cx,cy, color);
if(count >= 30){
count = 0;
}
}
count++;
}
}