-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasteroid.cpp
More file actions
executable file
·135 lines (84 loc) · 1.75 KB
/
asteroid.cpp
File metadata and controls
executable file
·135 lines (84 loc) · 1.75 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
124
125
126
127
128
129
130
131
132
133
134
135
#include "asteroid.h"
#include <cmath>
#define PI M_PI
using namespace std;
asteroid::asteroid(){
size = 0;
x = 0;
y = 0;
vx = 0;
vy = 0;
omega = 0;
}
int asteroid::getSize(){
return size;
}
double asteroid::getx(){
return x;
}
double asteroid::gety(){
return y;
}
double asteroid::getvx(){
return vx;
}
double asteroid::getvy(){
return vy;
}
Uint32 asteroid::getColor(){
return color;
}
void asteroid::setx( double nx ){
x = nx;
}
void asteroid::sety( double ny ){
y = ny;
}
void asteroid::setvx( double nvx ){
vx = nvx;
}
void asteroid::setvy( double nvy ){
vy = nvy;
}
void asteroid::move(){
x += vx;
y += vy;
theta += omega;
}
void asteroid::set(int nsize, double nx, double ny, double nvx, double nvy, Uint32 ncolor){
size = nsize;
x = nx;
y = ny;
vx = nvx;
vy = nvy;
color = ncolor;
double om = rand()%10-5;
omega = om/20;
}
void asteroid::draw( SDL_Surface* screen ){
double ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy;
ax = x+size*20*cos(theta);
ay = y+size*20*sin(theta);
bx = x+size*16*cos(theta+PI/3);
by = y+size*16*sin(theta+PI/3);
cx = x+size*20*cos(theta+2*PI/3);
cy = y+size*20*sin(theta+2*PI/3);
dx = x+size*24*cos(theta+PI);
dy = y+size*24*sin(theta+PI);
ex = x+size*20*cos(theta+4*PI/3);
ey = y+size*20*sin(theta+4*PI/3);
fx = x+size*20*cos(theta+5*PI/3);
fy = y+size*20*sin(theta+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);
}
int asteroid::check_collision( double nx, double ny ){
if (sqrt(pow((nx-x),2)+pow((ny-y),2)) < size*22 ){
return 1;
}
return 0;
}