-
Notifications
You must be signed in to change notification settings - Fork 0
/
UFO.cpp
74 lines (60 loc) · 1.59 KB
/
UFO.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
66
67
68
69
70
71
72
73
74
#include "UFO.h"
#include "Assets.h"
#include "SDLWindow.h"
UFO::UFO() {
name = "UFO/" + name;
collisionType = ICollideableType::UFO;
setAnimation( AnimationId::UFO );
Vector2f windowSize = sdl->getWindowSize();
box.size = windowSize * DefaultSizePercent;
box.pos.x = windowSize.x; // start offscreen right
box.pos.x--; // 1 pixel in to be sure it doesn't immediately die for being offscreen
box.pos.y = box.size.y / 2;
velocity.x = -DefaultUFOSpeed;
deathSound = SFXId::Explode2;
particleCloudProperties.setNumParticles( 10, 20 );
particleCloudProperties.setSizes( 14, 25 );
sfxChannel = sdl->loopSound( SFXId::UFO );
if( withChance( .75 ) ) {
itemDrop = AnimationId::ItemThickLaser;
}
}
UFO::~UFO() {
if( sfxChannel != -1 ) {
Mix_HaltChannel( sfxChannel );
}
}
void UFO::update( float t ) {
Sprite::update( t ) ;
if( exitedWorldBounds() ) {
// Here we shortcut all the usual in the object dying and just remove it
dead = true;
}
}
void UFO::onHit( ICollideable *o ) {
switch( o->collisionType ) {
case ICollideableType::Bullet:
die();
break;
case ICollideableType::Bunker:
break;
case ICollideableType::BunkerPiece:
break;
case ICollideableType::Invader:
break;
case ICollideableType::Item:
break;
case ICollideableType::Player:
break;
case ICollideableType::UFO:
break;
case ICollideableType::NotCollideable:
default:
error( "Colliding with non-collideable" );
break;
}
}
int UFO::getScore() const {
int baseScore = Sprite::getScore();
return baseScore * randInt( 1, 5 );
}