-
Notifications
You must be signed in to change notification settings - Fork 0
/
Block.cpp
123 lines (113 loc) · 3.19 KB
/
Block.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
#include <windows.h> // Header File For Windows
#include <stdio.h> // Header File For Standard Input / Output
#include <stdarg.h> // Header File For Variable Argument Routines
#include <math.h> // Header File For Math Operations
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include "glut.h"
#include "baseTypes.h"
#include "ShapeDraw.h"
#include "collInfo.h"
#include "object.h"
//#include "inputmapper.h"
#include "Block.h"
#include "field.h"
#include "fieldmanager.h"
#include "gamedefs.h"
#include "gameobjects.h"
#include "random.h"
#include "stateManager.h"
#include "inputmanager.h"
#include "SoundManager.h"
BlockC::BlockC(int id, float width, float height, float startX, float startY, TextureMapEnum textMapEnum)
:mHealth(false)
,curHealth(SILVER_HEALTH)
,invincible(false)
{
mEnabled = true;
mCollInfo.shape = CollInfoC::SHAPE_RECTANGLE;
mID = id;
mWidth = width;
mHeight = height;
mPosition.x = startX;
mPosition.y = startY;
mBlockSprite.setSpriteSheet(TextureMapManagerC::GetInstance()->getTextureMap(textMapEnum), 1, mWidth, mHeight);
if (textMapEnum == TextureMapEnum::BLOCK_SILVER_MAP) {
invincible = false;
mHealth = true;
mBlockSprite.setSpriteSheet(TextureMapManagerC::GetInstance()->getTextureMap(textMapEnum), 6, mWidth, mHeight);
}
if (textMapEnum == TextureMapEnum::BLOCK_GOLD_MAP) {
invincible = true;
mHealth = false;
mBlockSprite.setSpriteSheet(TextureMapManagerC::GetInstance()->getTextureMap(textMapEnum), 6, mWidth, mHeight);
}
};
void BlockC::setType(TextureMapEnum textMapEnum)
{
if (textMapEnum == TextureMapEnum::BLOCK_SILVER_MAP) {
invincible = false;
mHealth = true;
curHealth = SILVER_HEALTH;
mBlockSprite.setSpriteSheet(TextureMapManagerC::GetInstance()->getTextureMap(textMapEnum), 6, mWidth, mHeight);
} else if (textMapEnum == TextureMapEnum::BLOCK_GOLD_MAP) {
invincible = true;
mHealth = false;
mBlockSprite.setSpriteSheet(TextureMapManagerC::GetInstance()->getTextureMap(textMapEnum), 6, mWidth, mHeight);
} else {
invincible = false;
mHealth = false;
mBlockSprite.setSpriteSheet(TextureMapManagerC::GetInstance()->getTextureMap(textMapEnum), 1, mWidth, mHeight);
}
}
BlockC::~BlockC()
{
};
void BlockC::update(DWORD milliseconds)
{
mBlockSprite.update(milliseconds);
}
void BlockC::disable()
{
mEnabled = false;
}
bool BlockC::isEnabled()
{
return mEnabled;
}
void BlockC::render()
{
mBlockSprite.render(mPosition);
}
void BlockC::setRandomColor()
{
mBlockColor = getRangedRandom(0,256);
mBlockColor += getRangedRandom(0,256) << 8;
mBlockColor += getRangedRandom(0,256) << 16;
}
bool BlockC::applyDamage()
{
if (invincible) {
SoundManagerC::GetInstance()->playSound(SoundEnum::BLOCK_METALLIC_SOUND);
return false;
}
if (mHealth) {
--curHealth;
if (curHealth <= 0) {
disable();
SoundManagerC::GetInstance()->playSound(SoundEnum::BLOCK_DESTROYED_SOUND);
return true;
}
else
{
SoundManagerC::GetInstance()->playSound(SoundEnum::BLOCK_METALLIC_SOUND);
}
}
else
{
disable();
SoundManagerC::GetInstance()->playSound(SoundEnum::BLOCK_DESTROYED_SOUND);
return true;
}
return false;
}