Changeset View
Changeset View
Standalone View
Standalone View
objects.cpp
Show First 20 Lines • Show All 152 Lines • ▼ Show 20 Line(s) | 152 | if (speed > 3.75) | |||
---|---|---|---|---|---|
153 | return true; | 153 | return true; | ||
154 | // is center of ball in cup? | 154 | // is center of ball in cup? | ||
155 | if (!contains(ball->pos() - pos())) | 155 | if (!contains(ball->pos() - pos())) | ||
156 | return true; | 156 | return true; | ||
157 | // warp through blackhole at most 10 times per shot | 157 | // warp through blackhole at most 10 times per shot | ||
158 | if (m_runs > 10 && game && game->isInPlay()) | 158 | if (m_runs > 10 && game && game->isInPlay()) | ||
159 | return true; | 159 | return true; | ||
160 | 160 | | |||
161 | playSound("blackholeputin"); | 161 | game->playSound(Sound::BlackHolePutIn); | ||
162 | 162 | | |||
163 | const double diff = m_maxSpeed - m_minSpeed; | 163 | const double diff = m_maxSpeed - m_minSpeed; | ||
164 | const double newSpeed = m_minSpeed + speed / 3.75 * diff; | 164 | const double newSpeed = m_minSpeed + speed / 3.75 * diff; | ||
165 | 165 | | |||
166 | ball->setVelocity(Vector()); | 166 | ball->setVelocity(Vector()); | ||
167 | ball->setState(Stopped); | 167 | ball->setState(Stopped); | ||
168 | ball->setVisible(false); | 168 | ball->setVisible(false); | ||
169 | ball->setForceStillGoing(true); | 169 | ball->setForceStillGoing(true); | ||
170 | 170 | | |||
171 | const double distance = Vector(pos() - m_exitItem->pos()).magnitude(); | 171 | const double distance = Vector(pos() - m_exitItem->pos()).magnitude(); | ||
172 | BlackHoleTimer* timer = new BlackHoleTimer(ball, newSpeed, distance * 2.5 - newSpeed * 35 + 500); | 172 | BlackHoleTimer* timer = new BlackHoleTimer(ball, newSpeed, distance * 2.5 - newSpeed * 35 + 500); | ||
173 | 173 | | |||
174 | connect(timer, SIGNAL(eject(Ball*,double)), this, SLOT(eject(Ball*,double))); | 174 | connect(timer, SIGNAL(eject(Ball*,double)), this, SLOT(eject(Ball*,double))); | ||
175 | connect(timer, SIGNAL(halfway()), this, SLOT(halfway())); | 175 | connect(timer, SIGNAL(halfway()), this, SLOT(halfway())); | ||
176 | 176 | | |||
177 | playSound("blackhole"); | 177 | game->playSound(Sound::BlackHole); | ||
178 | return false; | 178 | return false; | ||
179 | } | 179 | } | ||
180 | 180 | | |||
181 | Kolf::BlackHoleTimer::BlackHoleTimer(Ball* ball, double speed, int msec) | 181 | Kolf::BlackHoleTimer::BlackHoleTimer(Ball* ball, double speed, int msec) | ||
182 | : m_speed(speed), m_ball(ball) | 182 | : m_speed(speed), m_ball(ball) | ||
183 | { | 183 | { | ||
184 | QTimer::singleShot(msec, this, SLOT(emitEject())); | 184 | QTimer::singleShot(msec, this, SLOT(emitEject())); | ||
185 | QTimer::singleShot(msec / 2, this, SIGNAL(halfway())); | 185 | QTimer::singleShot(msec / 2, this, SIGNAL(halfway())); | ||
Show All 13 Lines | 195 | { | |||
199 | ball->setPos(m_exitItem->pos() + 10 * direction); | 199 | ball->setPos(m_exitItem->pos() + 10 * direction); | ||
200 | ball->setVelocity(speed * direction); | 200 | ball->setVelocity(speed * direction); | ||
201 | 201 | | |||
202 | ball->setForceStillGoing(false); | 202 | ball->setForceStillGoing(false); | ||
203 | ball->setState(Rolling); | 203 | ball->setState(Rolling); | ||
204 | 204 | | |||
205 | m_runs++; | 205 | m_runs++; | ||
206 | 206 | | |||
207 | playSound("blackholeeject"); | 207 | game->playSound(Sound::BlackHoleEject); | ||
208 | } | 208 | } | ||
209 | 209 | | |||
210 | void Kolf::BlackHole::halfway() | 210 | void Kolf::BlackHole::halfway() | ||
211 | { | 211 | { | ||
212 | playSound("blackhole"); | 212 | game->playSound(Sound::BlackHole); | ||
213 | } | 213 | } | ||
214 | 214 | | |||
215 | void Kolf::BlackHole::load(KConfigGroup* cfgGroup) | 215 | void Kolf::BlackHole::load(KConfigGroup* cfgGroup) | ||
216 | { | 216 | { | ||
217 | setExitPos(cfgGroup->readEntry("exit", exitPos().toPoint())); | 217 | setExitPos(cfgGroup->readEntry("exit", exitPos().toPoint())); | ||
218 | setExitDeg(cfgGroup->readEntry("exitDeg", m_exitDeg)); | 218 | setExitDeg(cfgGroup->readEntry("exitDeg", m_exitDeg)); | ||
219 | setMinSpeed(cfgGroup->readEntry("minspeed", m_minSpeed)); | 219 | setMinSpeed(cfgGroup->readEntry("minspeed", m_minSpeed)); | ||
220 | setMaxSpeed(cfgGroup->readEntry("maxspeed", m_maxSpeed)); | 220 | setMaxSpeed(cfgGroup->readEntry("maxspeed", m_maxSpeed)); | ||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Line(s) | 341 | { | |||
343 | const double speed = Vector(ball->velocity()).magnitude(); | 343 | const double speed = Vector(ball->velocity()).magnitude(); | ||
344 | if (speed > 3.75) | 344 | if (speed > 3.75) | ||
345 | return true; | 345 | return true; | ||
346 | //miss if center of ball not inside cup | 346 | //miss if center of ball not inside cup | ||
347 | if (!contains(ball->pos() - pos())) | 347 | if (!contains(ball->pos() - pos())) | ||
348 | return true; | 348 | return true; | ||
349 | //place ball in hole | 349 | //place ball in hole | ||
350 | ball->setState(Holed); | 350 | ball->setState(Holed); | ||
351 | playSound("holed"); | 351 | game->playSound(Sound::Holed); | ||
352 | ball->setPos(pos()); | 352 | ball->setPos(pos()); | ||
353 | ball->setVelocity(Vector()); | 353 | ball->setVelocity(Vector()); | ||
354 | return false; | 354 | return false; | ||
355 | } | 355 | } | ||
356 | 356 | | |||
357 | //END Kolf::Cup | 357 | //END Kolf::Cup | ||
358 | 358 | | |||
359 | 359 | |