2
* Copyright (c) 2007, Olof Naessen and Per Larsson
6
* Redistribution and use in source and binary forms, with or without modification,
7
* are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright notice,
10
* this list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
* * Neither the name of the Darkbits nor the names of its contributors may be
15
* used to endorse or promote products derived from this software without
16
* specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
#include "sewersbackground.hpp"
34
#include "resourcehandler.hpp"
36
SewersBackground::SewersBackground()
38
mSewersBackground0 = ResourceHandler::getInstance()->getBitmap("sewersbackground0.bmp");
39
mSewersBackground1 = ResourceHandler::getInstance()->getBitmap("sewersbackground1.bmp");
43
void SewersBackground::draw(BITMAP* dest, int scroll)
45
draw_sprite(dest, mSewersBackground0, -((scroll / 4) % 320), 0);
46
draw_sprite(dest, mSewersBackground0, -((scroll / 4) % 320) + 320, 0);
48
drawSmoke(dest, scroll);
50
draw_sprite(dest, mSewersBackground1, -((scroll / 2) % 320), 0);
51
draw_sprite(dest, mSewersBackground1, -((scroll / 2) % 320) + 320, 0);
54
void SewersBackground::drawSmoke(BITMAP* dest, int scroll)
56
std::list<Particle>::iterator it = particles.begin();
57
while (it != particles.end()) {
58
int r = it->ttl / 4 > 10 ? 10 : it->ttl / 4;
60
int x = ((int)it->x - scroll / 3 + 100500) % 600;
61
circlefill(dest, x, it->y, r, makecol(78, 71, 28));
62
circlefill(dest, x - r / 3, it->y - r / 3, (r * 3) / 4, makecol(117, 110, 67));
68
void SewersBackground::logic()
71
float x = rand() % 150;
73
float dx = (rand() % 20) / 100.0 - 0.2;
74
float dy = -0.5 - (rand() % 50) / 100.0;
75
int ttl = 90 + rand() % 80;
76
particles.push_back(Particle(x, y, dx, dy, ttl));
79
if (particles.empty()) {
83
std::list<Particle>::iterator it = particles.begin();
84
while (it != particles.end()) {
85
it->x += it->dx + (rand() % 3 - 1) / 3.0;
86
it->y += it->dy + (rand() % 3 - 1) / 3.0;
91
while (particles.begin()->ttl <= 0) {
92
particles.erase(particles.begin());