-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayState.cpp
68 lines (59 loc) · 1.72 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
#include "PlayState.h"
#include "LevelParser.h"
#include "TextureManager.h"
#include "Game.h"
#include "SoundManager.h"
#include "AnimatedGraphic.h"
void PlayState::onEnter()
{
Game::Instance()->setLevel(Game::Instance()->getCurrentLevel() + 1);
SoundManager::Instance()->playSound("start", 0);
TextureManager::Instance()->load("images/bullet1.png", "bullet1", Game::Instance()->getRenderer());
TextureManager::Instance()->load("images/smallexplosion.png", "smallexplosion", Game::Instance()->getRenderer());
TextureManager::Instance()->load("images/tankexplosion.png", "tankexplosion", Game::Instance()->getRenderer());
TextureManager::Instance()->load("images/map.png", "map", Game::Instance()->getRenderer());
LevelParser levelParser;
pLevel = levelParser.parseLevel("level.xml");
pGameOver = new AnimatedGraphic();
}
void PlayState::onExit()
{
delete pLevel;
}
void PlayState::update()
{
pLevel->update();
if (Game::Instance()->gameOver())
{
pGameOver->update();
}
}
void PlayState::render()
{
pLevel->render();
// draw border
for (int i = 0; i<30; ++i) // 30 rows
{
TextureManager::Instance()->drawFrame("map", 640, i*16, 16, 16, 2, 2, Game::Instance()->getRenderer());
}
// draw player lives
for (int i = 0; i<Game::Instance()->getPlayerLives(); ++i)
{
if (i>=3)
{
break;
}
TextureManager::Instance()->drawFrame("graphics", 660 +i*32, 400, 32, 32, 0, 20, Game::Instance()->getRenderer());
}
// --------------------------------------------------
// draw remain enemies
for (int i = 0; i<pLevel->getLevelObjects()->size(); ++i)
{
ShooterObject* pObject = (*pLevel->getLevelObjects())[i];
pObject->drawAt(660 + i%3 * 32, i/3 * 32);
}
if (Game::Instance()->gameOver())
{
pGameOver->draw();
}
}