-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCLevel4.cpp
More file actions
177 lines (149 loc) · 5.11 KB
/
Copy pathCLevel4.cpp
File metadata and controls
177 lines (149 loc) · 5.11 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//Includes
#include "GamerCamp/GameSpecific/Levels/Act_2/CCutsceneAct2.h"
#include "GamerCamp/GameSpecific/Levels/Act_3/COutroScene3.h"
#include <functional>
// Include own .h
#include "CLevel4.h"
//////////////////////////////////////////////////////////////////////////
// Constructor and Destructor
//////////////////////////////////////////////////////////////////////////
CLevel4::CLevel4()
: CLevelBase(
GetGCTypeIDOf( CLevel4 ), // GC Type
std::string( "OgmoEditor/Act_1_Level_4.oel" ), // Ogmo Level
"Loose/Backgrounds/Act1/Level_4/00.png", // Background
1, // Level Goals
4,
60.0f // Level Time
)
, m_bIsBarrierActivated( true )
{
}
CLevel4::~CLevel4()
{
}
//////////////////////////////////////////////////////////////////////////
// CCNode Virtual Methods
//////////////////////////////////////////////////////////////////////////
void CLevel4::onEnter()
{
// Call base class first
CLevelBase::onEnter();
}
//////////////////////////////////////////////////////////////////////////
// IGCGameLayer Virtual Methods Override from Parent
//////////////////////////////////////////////////////////////////////////
void CLevel4::VOnCreate()
{
// Call base class first
CLevelBase::VOnCreate();
// Add Barrier
// - Barrier starting position
cocos2d::Vec2 v2BarrierStartPos( 1580.0f, -150.0f );
// - Barrier factory creation parameters
CGCFactoryCreationParams& sParams = m_sBarrierCreateParams;
sParams.strClassName = "CObjBarrier";
sParams.strPlistFile = "TexturePacker/Sprites/Barrier/Barrier.plist";
sParams.strPhysicsShape = "barrier";
sParams.eB2dBody_BodyType = b2_kinematicBody;
sParams.bB2dBody_FixedRotation = true;
// Create player object
m_pcGCOBarrier = static_cast< CObjBarrier* >( CGCFactory_ObjSpritePhysics::GetFactory().CreateInstance( sParams, v2BarrierStartPos ) );
// Level Label
m_pLevelLabel->setString( "Level 1-4" );
}
void CLevel4::VOnUpdate( f32 fTimeStep )
{
// Call base class first
CLevelBase::VOnUpdate( fTimeStep );
if( m_bIsBarrierActivated && m_bTutorialIsSkipped )
{
UpdateBarrier();
}
}
void CLevel4::VOnDestroy()
{
// Call base class first
CLevelBase::VOnDestroy();
}
void CLevel4::VOnReset()
{
m_bIsBarrierActivated = true;
// Call base class first
CLevelBase::VOnReset();
}
//////////////////////////////////////////////////////////////////////////
// B2ContactListener Virtual Methods Override from Parent
//////////////////////////////////////////////////////////////////////////
void CLevel4::BeginContact( b2Contact* pB2Contact )
{
// Call base class first
CLevelBase::BeginContact( pB2Contact );
}
void CLevel4::EndContact( b2Contact* pB2Contact )
{
// Call base class first
CLevelBase::EndContact( pB2Contact );
}
void CLevel4::PreSolve( b2Contact* pB2Contact, const b2Manifold* pOldManifold )
{
// Call base class first
CLevelBase::PreSolve( pB2Contact, pOldManifold );
}
void CLevel4::PostSolve( b2Contact* pB2Contact, const b2ContactImpulse* pImpulse )
{
// Call base class first
CLevelBase::PostSolve( pB2Contact, pImpulse );
}
//////////////////////////////////////////////////////////////////////////
// CLevelBase Virtual Method
//////////////////////////////////////////////////////////////////////////
void CLevel4::PlayBackgroundMusic()
{
m_pcAudioManager->PlayBackgroundMusic( GameConfig::EBackgroundSounds::EBS_Level4, false );
}
void CLevel4::NextLevel()
{
// We don't have level 5 right now, but if we save level 1 as before.
// The level 1 cutscene will not show up when player presses "Continue" at the main menu scene.
m_pcDataManager->SaveLevel( 5 );
ReplaceScene( TGCGameLayerSceneCreator< COutroScene3 >::CreateScene() );
}
// Method to update the position of the barrier
void CLevel4::UpdateBarrier()
{
// Variable to store the pixels to meters ratio
f32 fPTM_Ratio = IGCGAMELAYER_B2D_PIXELS_PER_METER;
// Variable to store the distance barrier has to move in pixels
f32 fMoveDistanceinPixels = 180.0f;
// Variable to store the distance barrier has to move in meters
f32 fMoveDistanceinMeters;
// Variable to store the velocity of the barrier.
f32 fVelocity;
// Variable to store the time barrier has to move
f32 fTime;
//Calculating the velocity of the barrier from 0 seconds to half the total time.
if( m_fLevelTimeElapsed <= m_fLevelTime / 3 )
{
//m_pcGCOBarrier->SetSpritePosition( Vec2( m_pcGCOBarrier->GetSpritePosition().x , 160*(m_fLevelTimeElapsed * 2 / m_fLevelTime)- 150.0f ));
fMoveDistanceinMeters = fMoveDistanceinPixels / fPTM_Ratio;
fTime = m_fLevelTime / 2;
fVelocity = fMoveDistanceinMeters / fTime;
}
//Calculating the velocity of the barrier in the last second of the level.
else if( ( int )m_fLevelTimeElapsed == ( ( int )m_fLevelTime ) - 1 )
{
f32 fMoveDistanceinPixels = 160.0f;
fMoveDistanceinMeters = fMoveDistanceinPixels / fPTM_Ratio;
fTime = 1;
fVelocity = fMoveDistanceinMeters / fTime;
//m_pcGCOBarrier->SetSpritePosition( Vec2( 1580.0f , 185.0f ) );
}
// Setting the velocity to 0 in other cases.
else
{
//m_pcGCOBarrier->SetSpritePosition( Vec2( 1580.0f , 10.0f ) );
fVelocity = 0.0f;
}
m_pcGCOBarrier->SetVelocity( cocos2d::Vec2( 0.0f, fVelocity ) );
}