~ubuntu-branches/ubuntu/precise/ballz/precise

« back to all changes in this revision

Viewing changes to src/sewersbackground.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sylvain Beucler
  • Date: 2008-10-15 20:40:45 UTC
  • Revision ID: james.westby@ubuntu.com-20081015204045-q26s9dxhienab3xr
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2007, Olof Naessen and Per Larsson
 
3
 *
 
4
 * All rights reserved.
 
5
 *
 
6
 * Redistribution and use in source and binary forms, with or without modification, 
 
7
 * are permitted provided that the following conditions are met:
 
8
 *
 
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.
 
17
 *
 
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.
 
29
 */
 
30
 
 
31
#include <math.h>
 
32
 
 
33
#include "sewersbackground.hpp"
 
34
#include "resourcehandler.hpp"
 
35
 
 
36
SewersBackground::SewersBackground()
 
37
{   
 
38
    mSewersBackground0 = ResourceHandler::getInstance()->getBitmap("sewersbackground0.bmp");
 
39
    mSewersBackground1 = ResourceHandler::getInstance()->getBitmap("sewersbackground1.bmp");
 
40
        mFrame = 0;
 
41
}
 
42
 
 
43
void SewersBackground::draw(BITMAP* dest, int scroll)
 
44
{
 
45
    draw_sprite(dest, mSewersBackground0, -((scroll / 4) % 320), 0);
 
46
    draw_sprite(dest, mSewersBackground0, -((scroll / 4) % 320) + 320, 0);
 
47
 
 
48
        drawSmoke(dest, scroll);
 
49
 
 
50
    draw_sprite(dest, mSewersBackground1, -((scroll / 2) % 320), 0);
 
51
    draw_sprite(dest, mSewersBackground1, -((scroll / 2) % 320) + 320, 0);
 
52
}
 
53
 
 
54
void SewersBackground::drawSmoke(BITMAP* dest, int scroll)
 
55
{
 
56
        std::list<Particle>::iterator it = particles.begin();
 
57
        while (it != particles.end()) {
 
58
                int r = it->ttl / 4 > 10 ? 10 : it->ttl / 4;
 
59
                if (r > 0) {
 
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));                 
 
63
                }
 
64
                it++;
 
65
        }
 
66
}
 
67
 
 
68
void SewersBackground::logic()
 
69
{
 
70
        if (mFrame++ % 2) {
 
71
                float x = rand() % 150;
 
72
                float y = 240.0;
 
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));
 
77
        }
 
78
 
 
79
        if (particles.empty()) {
 
80
                return;
 
81
        }
 
82
 
 
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;
 
87
                it->ttl--;
 
88
                it++;
 
89
        }
 
90
 
 
91
        while (particles.begin()->ttl <= 0) {
 
92
                particles.erase(particles.begin());
 
93
        }
 
94
 
 
95
}