Debian Codegraph @

TetrisAttack/src/CBlock.cpp

raw
1 #include "tetris.h"
2 #include <string>
3 using namespace std;
4
5 CBlock::CBlock(const CBlock& b, int x, int y)
6 : CFieldSprite(b, x, y), active(b.active), type(b.type)
7 { }
8
9 CBlock::CBlock(const CBlock& b, int x, int y, CVector offset)
10 : CFieldSprite(b, x, y, offset), active(b.active), type(b.type)
11 { }
12
13 CBlock::CBlock(const CBlock& b, int x, int y, int fieldWidth, int fieldHeight, CVector offset)
14 : CFieldSprite(b, x, y, fieldWidth, fieldHeight, offset), active(b.active), type(b.type)
15 { }
16
17 CBlock::CBlock(CSurface* s, int x, int y, int fieldWidth, int fieldHeight, CVector offset, BlockType type)
18 : CFieldSprite(s, x,y, 1, 1, fieldWidth, fieldHeight, offset), type(type), active(true)
19 { }
20
21 CBlock::CBlock(const string& fileName, int x, int y, int fieldWidth, int fieldHeight, CVector offset, BlockType type)
22 : CFieldSprite(fileName + "_staticbg.png", x, y, 1, 1, fieldWidth, fieldHeight, offset), type(type), active(true)
23 {
24 // compose block image onto surface
25 CSurface *block = CSprite::getCurrentFrame();
26 CSurface blockBG(*block);
27
28 CSurface *img = CImgLoader::loadImage(fileName + "_staticimg.png", true);
29 int w1 = block->getWidth();
30 int h1 = block->getHeight();
31 int w2 = img->getWidth();
32 int h2 = img->getHeight();
33 int x1 = (w1/2) - (w2/2);
34 int y1 = (h1/2) - (h2/2);
35 block->blit(*img, x1, y1);
36
37 // now create all the animations
38 list<CSurface*> s;
39 for(int i = 15; i > 5; i--)
40 {
41 CSurface* tmp = new CSurface(blockBG);
42 tmp->blitScaleEx(*img, CRect(x1,y1+(h2-i/20.*h2),0,0), 1, i/20.);
43 s.push_back( tmp );
44 }
45 for(list<CSurface*>::reverse_iterator i = s.rbegin(); i != s.rend(); ++i)
46 {
47 s.push_back( (*i) );
48 }
49 addAnimation("hitanim_bottom", new CAnimation(s, 5));
50
51 s.clear();
52 for(int i = 15; i > 5; i--)
53 {
54 CSurface* tmp = new CSurface(blockBG);
55 tmp->blitScaleEx(*img, CRect(x1+(w2-i/20.*w2),y1,0,0), i/20., 1);
56 s.push_back( tmp );
57 }
58 for(list<CSurface*>::reverse_iterator i = s.rbegin(); i != s.rend(); ++i)
59 {
60 s.push_back( (*i) );
61 }
62 addAnimation("hitanim_right", new CAnimation(s, 5));
63
64 s.clear();
65 for(int i = 15; i > 5; i--)
66 {
67 CSurface* tmp = new CSurface(blockBG);
68 tmp->blitScaleEx(*img, CRect(x1,y1,0,0), i/20., 1);
69 s.push_back( tmp );
70 }
71 for(list<CSurface*>::reverse_iterator i = s.rbegin(); i != s.rend(); ++i)
72 {
73 s.push_back( (*i) );
74 }
75 addAnimation("hitanim_left", new CAnimation(s, 5));
76
77 delete img;
78 }
79
80 void CBlock::clear()
81 {
82 CSprite::clear();
83 active = false;
84 }
85
86 void CBlock::update()
87 {
88 CFieldSprite::update();
89 }
90
91 CBlock* CBlock::getClone(int x, int y)
92 {
93 CBlock *clone = new CBlock(*this, x, y);
94
95 return clone;
96 }
97
98 CBlock* CBlock::getClone(int x, int y, CVector offset)
99 {
100 CBlock* clone = new CBlock(*this, x, y, offset);
101 return clone;
102 }
103
104 CBlock* CBlock::getClone(int x, int y, int fieldWidth, int fieldHeight, CVector offset)
105 {
106 CBlock* clone = new CBlock(*this, x, y, fieldWidth, fieldHeight, offset);
107 return clone;
108 }
109
110 bool CBlock::isActive()
111 {
112 return active && !isMoving() && events.size() < 1;
113 }
114
115 bool CBlock::canRemove()
116 {
117 return active && !isMoving();
118 }
119
120 void CBlock::setActive(bool active)
121 {
122 CBlock::active = active;
123 }
124
125 bool CBlock::deleteMe()
126 {
127 if (effect)
128 {
129 return (effect->isDone());
130 }
131 else
132 {
133 return !isAlive();
134 }
135 }
136
137 bool CBlock::sameType(const CBlock &b)
138 {
139 return b.type == type;
140 }