File: IngredientGroup.h

package info (click to toggle)
burgerspace 1.9.2-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,524 kB
  • sloc: sh: 10,939; cpp: 5,791; makefile: 240
file content (178 lines) | stat: -rw-r--r-- 5,837 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*  $Id: IngredientGroup.h,v 1.14 2010/05/26 03:13:01 sarrazip Exp $
    IngredientGroup.h - Group of sprites representing an "ingredient"

    burgerspace - A hamburger-smashing video game.
    Copyright (C) 2001-2010 Pierre Sarrazin <http://sarrazip.com/>

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
*/

#ifndef _H_IngredientGroup
#define _H_IngredientGroup

#include <flatzebra/Sprite.h>

#include <assert.h>
#include <vector>

class IngredientSprite;
class EnemySprite;


class IngredientGroup
/*  An ingredient is represented as 4 sprites.
    An object of this class stores pointers to Sprite objects
    that belong to the same group.
    They are stored in a vector of Sprite pointers,
    in left-to-right order.
    This object does not own the Sprite pointers that it stores.
*/
{
public:

    typedef std::vector<class IngredientGroup *> List;

    enum State { NORMAL, FALL1, BOUNCE, STALL, FALL2, REST };

    IngredientGroup(int yTarget, bool topBun);
    /*  Constructs an empty group that has the given vertical target.
        The vertical target is the position where the group's member
        sprites must stop falling.
        'topBun' indicates if this group represents a top bun.
        See the method isTopBun().
    */

    ~IngredientGroup();
    /*  Does not delete the member sprites.
    */

    void setMember(size_t index, IngredientSprite *s);
    /*  This object does not own the member sprites.
    */

    IngredientSprite *getMember(size_t index) const
    {
        assert(index < 4);
        assert(members[index] != NULL);
        return members[index];
    }

    size_t getNumMembers() const
    {
        return 4;
    }

    bool areAllMembersLowered() const;

    void startFalling(int speedFactor, int numOfFloorsToGo = 1);
    /*  Gives an downward speed of 'speedFactor' to the sprites of this group
        and to the sprites of the carried enemies.
        Puts this group in the FALL1 state.
        'numOfFloorsToGo' must be the number of floors that must be
        travelled by this group.
    */

    State getState() const { return state; }

    void bounce(int speedFactor);
    /*  Gives an upward speed of 'speedFactor' to the sprites of this group
        and to the sprites of the carried enemies.
        Puts this group in the BOUNCE state and sets the bounce time
        to a positive number of ticks.
    */

    void stall();
    /*  Stops the sprites of this group and the sprites of the carried enemies.
        Puts this group in the STALL state and sets the stall time
        to a positive number of ticks.
    */

    void fallBack(int speedFactor);
    /*  Gives an downward speed of 'speedFactor' to the sprites of this group
        and to the sprites of the carried enemies.
        Puts this group in the FALL2 state.
    */

    void fallToNextFloor(int speedFactor);
    /*  Gives an downward speed of 'speedFactor' to the sprites of this group
        and to the sprites of the carried enemies.
        Puts this group in the FALL1 state.
    */

    void stop();
    /*  Sets the speed of all members to zero.
        Makes all members normal (i.e., not lowered).
        Aligns all members of the vertical position of the first member.
    */

    int  getVerticalTarget() const { return verticalTarget; }

    void addCarriedEnemy(EnemySprite *s);
    /*  Adds 's' to this group's list of carried enemies.
        Tells 's' that this group is its carrying group.
    */

    const flatzebra::SpriteList &getCarriedEnemies() const { return carriedEnemies; }
    flatzebra::SpriteList &getCarriedEnemies() { return carriedEnemies; }
    void clearCarriedEnemies() { carriedEnemies.clear(); }

    int getBounceTime() const { return bounceTime; }
    int decBounceTime()
            { if (bounceTime != 0) bounceTime--; return bounceTime; }
    int getStallTime() const { return stallTime; }
    int decStallTime()
            { if (stallTime != 0) stallTime--; return stallTime; }

    void   setNumFloorsToGo(size_t n) { numFloorsToGo = n; }
    size_t getNumFloorsToGo() const { return numFloorsToGo; }
    size_t decNumFloorsToGo()
            { if (numFloorsToGo != 0) numFloorsToGo--; return numFloorsToGo; }
    flatzebra::Couple getCenterPos() const;

    bool isTopBun() const { return topBunFlag; }
    /*  Indicates if this group represents a top bun.
        When a top bun reaches the plate, the corresponding hamburger
        is done.  When all hamburgers are done, the level is done.
    */

    void restore(int bounceTime, int stallTime,
                            State state, size_t numFloorsToGo)
    {
        this->bounceTime = bounceTime;
        this->stallTime = stallTime;
        this->state = state;
        this->numFloorsToGo = numFloorsToGo;
    }

private:

    IngredientSprite *members[4];
    int verticalTarget;
    flatzebra::SpriteList carriedEnemies;
    int bounceTime;
    int stallTime;
    State state;
    size_t numFloorsToGo;
    bool topBunFlag;

    // Forbidden operations:
    IngredientGroup(const IngredientGroup &);
    IngredientGroup &operator = (const IngredientGroup &);

};


#endif  /* _H_IngredientGroup */