-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayState.cpp
140 lines (119 loc) · 3.01 KB
/
PlayState.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
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
//
// PlayState.cpp
// SDL Game Programming Book
//
// Created by shaun mitchell on 09/02/2013.
// Copyright (c) 2013 shaun mitchell. All rights reserved.
//
#include <iostream>
#include "PlayState.h"
#include "Game.h"
#include "InputHandler.h"
#include "TextureManager.h"
#include "JewelBoard.h"
#include "MovingObject.h"
#include "ScorePanel.h"
#include <model/Match.h>
const std::string PlayState::s_playID = "PLAY";
static bool m_keyPpressed = false;
static bool m_paused = false;
class TNT : public MovingObject
{
public:
TNT()
:MovingObject("assets/spark.png", 60 * 1000, true, 0.2)
{
Trajectory trj = {
{ 265, 557},
{ 258, 553},
{ 256, 550},
{ 254, 546},
{ 252, 538},
{ 254, 526},
{ 255, 520},
{ 253, 517},
{ 249, 515},
{ 241, 512},
{ 227, 511},
{ 220, 510},
{ 217, 508},
{ 214, 504},
{ 208, 382},
{ 208, 382},
{ 208, 378},
{ 206, 376},
{ 205, 374},
{ 180, 372}
};
setTrajectory(trj);
setAlphaOscillation(0.8);
setRandomSize(0.3);
}
};
PlayState::PlayState()
{
ScorePanel* panel = new ScorePanel(TheGame::Instance()->getMatch());
JewelBoard* board = new JewelBoard(TheGame::Instance()->getMatch());
m_gameObjects.push_back(board);
m_gameObjects.push_back(new TNT);
m_gameObjects.push_back(panel);
}
void PlayState::update()
{
if(m_loadingComplete && !m_exiting)
{
/*if(TheInputHandler::Instance()->isKeyDown(SDL_SCANCODE_ESCAPE))
{
TheGame::Instance()->getStateMachine()->pushState(new PauseState());
}*/
// if(TheInputHandler::Instance()->getButtonState(0, 8))
// {
// TheGame::Instance()->getStateMachine()->pushState(new PauseState());
// }
/* if(TheGame::Instance()->getMatch().getPlayerLives() == 0)
{
TheGame::Instance()->getStateMachine()->changeState(new GameOverState());
}*/
bool keyPpressed = TheInputHandler::Instance()->isKeyDown(SDL_SCANCODE_P);
if (keyPpressed && !m_keyPpressed)
m_paused = !m_paused;
m_keyPpressed = keyPpressed;
if (!m_paused)
//m_jewelBoard->update();
GameState::update();
}
}
void PlayState::render()
{
if(m_loadingComplete)
{
/* if(pLevel != 0)
{
pLevel->render();
}
*/
TheTextureManager::Instance()->draw("background", 0,0,
755, 600);
GameState::render();
for(int i = 0; i < TheGame::Instance()->getMatch().getPlayerLives(); i++)
{
TheTextureManager::Instance()->drawFrame("lives", i * 30, 0, 32, 30, 0, 0, nullptr, 0.0, 255);
}
}
//m_jewelBoard->draw();
// GameState::render();
}
bool PlayState::onEnterImpl()
{
TheGame::Instance()->getMatch().restart();
TheTextureManager::Instance()->load("assets/BackGround.jpg", "background");
std::cout << "entering PlayState\n";
return true;
}
bool PlayState::onExit()
{
m_exiting = true;
TheInputHandler::Instance()->reset();
std::cout << "exiting PlayState\n";
return true;
}