-
Notifications
You must be signed in to change notification settings - Fork 0
/
BigAsteroid.cpp
executable file
·65 lines (50 loc) · 1.23 KB
/
BigAsteroid.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
#include "Vector.h"
#include "BigAsteroid.h"
#include "BigAsteroidAnimation.h"
#include "Vector.h"
#include "Visitor.h"
#include "Bullet.h"
BigAsteroid::BigAsteroid(float x, float y):speed(0.3){
animation = new BigAsteroidAnimation(60);
this->pos_x = x;
this->pos_y = y;
velocity = new Vector(512-x,384-y);
mass = 10;
damaged = false;
needsRemoved = false;
}
BigAsteroid::~BigAsteroid(){
}
void BigAsteroid::update(){
animation->update();
pos_x += speed*velocity->x;
pos_y += speed*velocity->y;
if((pos_x > 1024 || pos_x < 0 || pos_y > 768 || pos_y < 0) && damaged){
markForRemoval();
}
}
void BigAsteroid::render(SDL_Surface* screen){
animation->render(screen,pos_x,pos_y);
}
void BigAsteroid::accept(Visitor* v, Sprite* s){
//v->visit(this,s);
}
void BigAsteroid::explode(){
}
void BigAsteroid::operator+(const Bullet* bullet){
velocity->x += bullet->velocity().x/mass;
velocity->y += bullet->velocity().y/mass;
damaged = true;
}
bool BigAsteroid::markedForRemoval(){
return needsRemoved;
}
void BigAsteroid::markForRemoval(){
needsRemoved = true;
}
float BigAsteroid::getX(){
return pos_x;
}
float BigAsteroid::getY(){
return pos_y;
}