2 Copyright 2008 Fela Winkelmolen <fela.kde@gmail.com>
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "gameengine.h"
27 Gift::Gift(const QString
&type
)
33 int sp
= qrand() % (MAXIMUM_GIFT_SPEED
- MINIMUM_GIFT_SPEED
+ 1);
34 m_speedFactor
= MINIMUM_GIFT_SPEED
+ sp
;
38 void Gift::move(qreal speed
, int updateInterval
)
40 for (int i
= 0; i
< updateInterval
; ++i
) {
45 void Gift::step(qreal speed
)
47 const qreal linearIncreaseFactor
= 0.00008 * speed
;
48 const qreal exponentialIncreaseFactor
= 0.002;
49 m_speed
+= m_speedFactor
* linearIncreaseFactor
;
50 m_speed
+= m_speed
* exponentialIncreaseFactor
;
55 void Gift::startFall(int x
, int y
)
63 void Gift::execute(GameEngine
*gameEngine
)
66 m_game
->addScore(GIFT_SCORE
);
68 if (type() == "Gift100Points") {
69 m_game
->addScore(100 - GIFT_SCORE
);
71 else if (type() == "Gift200Points") {
72 m_game
->addScore(200 - GIFT_SCORE
);
74 else if (type() == "Gift500Points") {
75 m_game
->addScore(500 - GIFT_SCORE
);
77 else if (type() == "Gift1000Points") {
78 m_game
->addScore(1000 - GIFT_SCORE
);
80 else if (type() == "GiftAddLife") {
81 if (m_game
->m_lives
.count() < MAXIMUM_LIVES
) {
82 m_game
->m_lives
.append(new Life
);
85 else if (type() == "GiftLoseLife") {
86 m_game
->handleDeath();
88 else if (type() == "GiftNextLevel") {
91 else if (type() == "GiftMagicEye") {
94 else if (type() == "GiftMagicWand") {
97 else if (type() == "GiftSplitBall") {
100 else if (type() == "GiftAddBall") {
101 m_game
->m_balls
.append(new Ball
);
103 else if (type() == "GiftUnstoppableBall") {
104 giftUnstoppableBall();
106 else if (type() == "GiftBurningBall") {
109 else if (type() == "GiftDecreaseSpeed") {
110 m_game
->changeSpeed(1.0/CHANGE_SPEED_RATIO
);
112 else if (type() == "GiftIncreaseSpeed") {
113 m_game
->changeSpeed(CHANGE_SPEED_RATIO
);
115 else if (type() == "GiftEnlargeBar") {
116 Bar
*bar
= &m_game
->m_bar
;
118 m_game
->moveBar(bar
->position().x() + bar
->getRect().width()/2);
120 else if (type() == "GiftShrinkBar") {
121 m_game
->m_bar
.shrink();
123 else if (type() == "GiftStickyBar") {
124 m_game
->m_bar
.setType("StickyBar");
126 else if (type() == "GiftMoreExplosion") {
130 kError() << "Unrecognized gift type!!!";
134 void Gift::giftNextLevel()
136 m_game
->loadNextLevel();
139 void Gift::giftMagicEye()
141 // make all hidden bricks visible
142 foreach (Brick
*brick
, m_game
->m_bricks
) {
143 if (!brick
->isDeleted() && !brick
->isVisible()) {
145 ++m_game
->m_remainingBricks
;
150 void Gift::giftMagicWand()
152 foreach (Brick
*brick
, m_game
->m_bricks
) {
153 // make Unbreakbable Bricks Breakable
154 if (!brick
->isDeleted() && brick
->type() == "UnbreakableBrick") {
155 brick
->setType("BreakableBrick");
156 ++m_game
->m_remainingBricks
;
157 kDebug() << m_game
->m_remainingBricks
;
160 // Make Multiple Bricks single
161 if (brick
->type() == "MultipleBrick3") {
162 brick
->setType("MultipleBrick1");
163 m_game
->addScore(AUTOBRICK_SCORE
* 2);
165 if (brick
->type() == "MultipleBrick2") {
166 brick
->setType("MultipleBrick1");
167 m_game
->addScore(AUTOBRICK_SCORE
);
172 void Gift::giftSplitBall()
174 // TODO: better copy (type, speed, etc...)
175 QList
<Ball
*> newBalls
;
176 foreach (Ball
*ball
, m_game
->m_balls
) {
177 Ball
*newBall
= new Ball
;
178 // give it a nice direction...
179 newBall
->directionX
= ball
->directionX
;
180 newBall
->directionY
= ball
->directionY
;
181 if (ball
->directionY
> 0)
182 newBall
->directionY
*= -1;
184 newBall
->directionX
*= -1;
186 newBall
->toBeFired
= ball
->toBeFired
;
187 newBall
->setType(ball
->type());
188 newBall
->moveTo(ball
->position());
189 newBalls
.append(newBall
);
191 m_game
->m_balls
+= newBalls
;
194 void Gift::giftUnstoppableBall()
196 foreach (Ball
*ball
, m_game
->m_balls
) {
197 if (ball
->type() == "BurningBall") {
198 ball
->setType("UnstoppableBurningBall");
199 } else if (ball
->type() != "UnstoppableBurningBall") {
200 ball
->setType("UnstoppableBall");
205 void Gift::giftBurningBall()
207 foreach (Ball
*ball
, m_game
->m_balls
) {
208 if (ball
->type() == "UnstoppableBall") {
209 ball
->setType("UnstoppableBurningBall");
210 } else if (ball
->type() != "UnstoppableBurningBall") {
211 ball
->setType("BurningBall");
216 void Gift::giftMoreExplosion()
218 QList
<Brick
*> explodingBricks
;
219 foreach (Brick
*brick
, m_game
->m_bricks
) {
220 if (!brick
->isDeleted() && brick
->type() == "ExplodingBrick") {
221 explodingBricks
.append(brick
);
225 foreach (Brick
*brick
, explodingBricks
) {
226 foreach (Brick
*nearbyBrick
, brick
->nearbyBricks()) {
227 if (nearbyBrick
->type() == "UnbreakableBrick") {
228 ++m_game
->m_remainingBricks
;
230 if (nearbyBrick
->type() == "HiddenBrick" &&
231 !nearbyBrick
->isVisible()) {
233 ++m_game
->m_remainingBricks
;
236 nearbyBrick
->setType("ExplodingBrick");