-
Notifications
You must be signed in to change notification settings - Fork 8
/
Generator.cpp
85 lines (81 loc) · 2.09 KB
/
Generator.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
75
76
77
78
79
80
81
82
83
84
85
#include "Generator.h"
#include "Engine.h"
Generator::Generator()
{
IsActive = false;
ScrollOffset = 0;
curTick = 0;
tickDelay = 0;
numEnts = 1;
bEasySpawn = false;
mpEntity = NULL;
}
Generator::~Generator()
{
}
//================================================================================================//
/*************************
** Trigger a new entity **
**************************/
//================================================================================================//
void Generator::Trigger()
{
if(numEnts<=0)
{
IsActive = false;
return;
}
IsActive = true;
numEnts--;
curTick = 0;
if(gpEngine->mPlayer.bJustSpawned && !dynamic_cast<PowerDroid*>(mpEntity) && !dynamic_cast<BreakScenery*>(mpEntity) && !dynamic_cast<Fire*>(mpEntity) && !dynamic_cast<Boss*>(mpEntity))
return;
//dont spawn it if we are recording.
if(gpEngine->bRecording && mpEntity == gpEngine->pRecordEnt)
return;
if(gpEngine->fGameDifficulty == 3)
{
bEasySpawn = !bEasySpawn;
if(!bEasySpawn)
return;
}
Entity* pEnt=NULL;
pEnt = mpEntity->Clone();
if(pEnt==NULL)
return;
pEnt->Spawn(Pos);
gpEngine->GiveEntityToList(pEnt);
}
//================================================================================================//
/*************************
** update the generator **
**************************/
//================================================================================================//
void Generator::Update()
{
curTick++;
if(curTick>=tickDelay)
Trigger();
}
void Generator::LoadFromFile(CFileIO &fIO)
{
fIO.ReadBinary(&iEntType,1);
fIO.ReadBinary(&ScrollOffset,1);
fIO.ReadBinary(&Pos.x,1);
fIO.ReadBinary(&Pos.y,1);
fIO.ReadBinary(&numEnts,1);
fIO.ReadBinary(&tickDelay,1);
if(!(mpEntity = gpEngine->CreateEntity(iEntType)))
return;
mpEntity->LoadFromFile(fIO);
}
void Generator::WriteToFile(CFileIO &fIO)
{
fIO.WriteBinary(&iEntType,1);
fIO.WriteBinary(&ScrollOffset,1);
fIO.WriteBinary(&Pos.x,1);
fIO.WriteBinary(&Pos.y,1);
fIO.WriteBinary(&numEnts,1);
fIO.WriteBinary(&tickDelay,1);
mpEntity->WriteToFile(fIO);
}