-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEnemySpawner.cpp
More file actions
58 lines (47 loc) · 1.62 KB
/
Copy pathEnemySpawner.cpp
File metadata and controls
58 lines (47 loc) · 1.62 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
#include "Utility/package.hpp"
#include "package.h"
//---------------------------------------------------------------------------------
// Written by Terence J. Grant - tjgrant [at] tatewake [dot] com
// Find the full tutorial at: http://gamedev.tutsplus.com/series/
//----------------------------------------------------------------------------------
tVector2f EnemySpawner::GetSpawnPosition()
{
tVector2f pos;
do
{
pos = tVector2f(tMath::random() * GameRoot::getInstance()->getViewportSize().width,
tMath::random() * GameRoot::getInstance()->getViewportSize().height);
}
while (pos.distanceSquared(PlayerShip::getInstance()->getPosition()) < 250 * 250);
return pos;
}
EnemySpawner::EnemySpawner()
: mInverseSpawnChance(90)
{
}
void EnemySpawner::update()
{
if (!PlayerShip::getInstance()->getIsDead() && EntityManager::getInstance()->getCount() < 3)
{
if (int32_t(tMath::random() * mInverseSpawnChance) == 0)
{
EntityManager::getInstance()->add(Enemy::createSeeker(GetSpawnPosition()));
}
if (int32_t(tMath::random() * mInverseSpawnChance) == 0)
{
EntityManager::getInstance()->add(Enemy::createWanderer(GetSpawnPosition()));
}
if (EntityManager::getInstance()->getBlackHoleCount() < 2 && int32_t(tMath::random() * mInverseBlackHoleChance) == 0)
{
EntityManager::getInstance()->add(new BlackHole(GetSpawnPosition()));
}
}
if (mInverseSpawnChance > 30)
{
mInverseSpawnChance -= 0.005f;
}
}
void EnemySpawner::reset()
{
mInverseSpawnChance = 90;
}