Back to index

kdeartwork  4.3.2
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Static Private Attributes
Seaweed Class Reference

Special class to represent seaweed. More...

Inheritance diagram for Seaweed:
Inheritance graph
[legend]
Collaboration diagram for Seaweed:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Seaweed (Screen *s, int x, int y, int life)
 Constructor.
 ~Seaweed ()
virtual bool tickUpdate ()
 Reimplemented from Sprite::tickUpdate() to handle keeping track of Seaweed lifetime.
virtual bool canCollide () const
virtual void collision (Sprite *sprite)
 Called when a collision occurs with any Sprite on-screen if canCollide() returns true.
void addFrame (const Frame &frame)
 Appends a frame of animation to the end of the current list.
void setFrameDelay (int delay)
 Sets the amount of time to show a frame for.
void setDieAfterLastFrame (bool dieAfterLast)
 Sets whether this Sprite should automatically call kill() after the last frame of animation has run.
Screenscreen () const
bool isKilled () const
int depth () const
QRect geom () const
void erase ()
 Erases this Sprite from its Screen, using the current animation frame to form the clear mask.
void paint ()
 Draws this Sprite onto the Screen.
virtual void kill ()
 Kills this Sprite.

Static Public Member Functions

static bool isTooClose (int newX)

Protected Member Functions

bool timerTick ()
 Increments the animation timer.

Protected Attributes

Screenm_screen
 The Screen that we belong to.
int m_currentFrame
 The current frame of animation.
int m_x
 Our current logical x position.
int m_y
 Our current logical y position.
int m_z
 Our current depth.
QVector< Framem_frames
 Array of animation frames.
bool m_isKilled
 True if we've been killed.
bool m_killAfterLastFrame
 True if we should auto-kill after the last frame.
int m_ticksSinceFrameChange
 Number of timer ticks since we last changed frame.
int m_frameDelay
 Number of milliseconds to show a frame for.

Private Attributes

int m_ticks
 Number of animation ticks elapsed.
int m_lifeTimeMS
 Life time of seaweed in milliseconds.

Static Private Attributes

static QList< int > m_positions

Detailed Description

Special class to represent seaweed.

Seaweed can disappear over time, and when this happens, this class will automatically spawn another one.

Definition at line 186 of file aasaver.cpp.


Constructor & Destructor Documentation

Seaweed::Seaweed ( Screen s,
int  x,
int  y,
int  life 
) [inline]

Constructor.

The x, y, and z coordinates are all in logical coordinates.

Parameters:
sThe Screen to be created in.
xThe x coordinate to place the seaweed at.
yThe y coordinate to place the seaweed at.
lifeThe length of time in milliseconds the seaweed will live for.

Definition at line 202 of file aasaver.cpp.

                                              : Sprite(s, x, y, 21),
        m_ticks(0), m_lifeTimeMS(life)
    {
        m_positions.append(x);
    }
Seaweed::~Seaweed ( ) [inline]

Definition at line 208 of file aasaver.cpp.

    {
        m_positions.removeAll(m_x);
    }

Member Function Documentation

void Sprite::addFrame ( const Frame frame) [inherited]

Appends a frame of animation to the end of the current list.

Parameters:
frameFrame of animation to add. It should be the same size as the other frames already in the list.

Definition at line 39 of file sprite.cpp.

{
    m_frames.append(frame);
}

Here is the caller graph for this function:

virtual bool Sprite::canCollide ( ) const [inline, virtual, inherited]
Returns:
true if this sprite can be involved in a collision with another Sprite. The other sprite doesn't necessarily have to have this also set to true.

Reimplemented in TeethSprite.

Definition at line 97 of file sprite.h.

{ return false; }

Here is the caller graph for this function:

virtual void Sprite::collision ( Sprite sprite) [inline, virtual, inherited]

Called when a collision occurs with any Sprite on-screen if canCollide() returns true.

Parameters:
spriteThe Sprite that a collision happened with. It is safe to kill() the Sprite, move it, etc.

Reimplemented in TeethSprite.

Definition at line 106 of file sprite.h.

    {
        Q_UNUSED(sprite); // Base class does nothing.
    }

Here is the caller graph for this function:

int Sprite::depth ( ) const [inline, inherited]
Returns:
The depth of the Sprite. 0 is closest to the screen.

Definition at line 161 of file sprite.h.

    {
        return m_z;
    }

Here is the caller graph for this function:

void Sprite::erase ( ) [inherited]

Erases this Sprite from its Screen, using the current animation frame to form the clear mask.

This should be called before any change which will change the on-screen display of the object, such as motion or animation changes.

Definition at line 44 of file sprite.cpp.

Here is the caller graph for this function:

QRect Sprite::geom ( ) const [inherited]
Returns:
The rectangular geometry of this object in the Pixel coordinate system.

Definition at line 90 of file sprite.cpp.

{
    return QRect(m_x, m_y, m_frames[0].width(), m_frames[0].height());
}

Here is the caller graph for this function:

bool Sprite::isKilled ( ) const [inline, inherited]
Returns:
true if this Sprite is dead. If true, it will probably soon be deleted by its Screen.

Definition at line 153 of file sprite.h.

    {
        return m_isKilled;
    }

Here is the caller graph for this function:

static bool Seaweed::isTooClose ( int  newX) [inline, static]

Definition at line 213 of file aasaver.cpp.

    {
        foreach(int i, m_positions) {
            if(qAbs(i - newX) < 3)
                return true;
        }

        return false;
    }

Here is the caller graph for this function:

virtual void Sprite::kill ( ) [inline, virtual, inherited]

Kills this Sprite.

The parent Screen will delete this Sprite on the next animation cycle.

Reimplemented in FishSprite, and RandomMovingSprite.

Definition at line 189 of file sprite.h.

    {
        m_isKilled = true;
    }

Here is the caller graph for this function:

void Sprite::paint ( ) [inherited]

Draws this Sprite onto the Screen.

Definition at line 49 of file sprite.cpp.

Here is the caller graph for this function:

Screen* Sprite::screen ( ) const [inline, inherited]
Returns:
The Screen this Sprite belongs to.

Definition at line 144 of file sprite.h.

    {
        return m_screen;
    }

Here is the caller graph for this function:

void Sprite::setDieAfterLastFrame ( bool  dieAfterLast) [inline, inherited]

Sets whether this Sprite should automatically call kill() after the last frame of animation has run.

Parameters:
dieAfterLastIf true, this Sprite will automatically call kill() after its last frame has elapsed.

Definition at line 136 of file sprite.h.

    {
        m_killAfterLastFrame = dieAfterLast;
    }

Here is the caller graph for this function:

void Sprite::setFrameDelay ( int  delay) [inline, inherited]

Sets the amount of time to show a frame for.

Parameters:
delayThe frame delay, in milliseconds of time.

Definition at line 124 of file sprite.h.

Here is the caller graph for this function:

virtual bool Seaweed::tickUpdate ( ) [inline, virtual]

Reimplemented from Sprite::tickUpdate() to handle keeping track of Seaweed lifetime.

Calls the inherited tickUpdate() as well.

Reimplemented from Sprite.

Definition at line 227 of file aasaver.cpp.

Here is the call graph for this function:

bool Sprite::timerTick ( ) [protected, inherited]

Increments the animation timer.

Returns:
true if time has elapsed past m_frameDelay since the last frame change.

Definition at line 54 of file sprite.cpp.

{
    ++m_ticksSinceFrameChange;
    if (m_ticksSinceFrameChange * m_screen->msPerTick() < m_frameDelay)
        return false;

    //Ring! Ring!
    m_ticksSinceFrameChange = 0;
    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

int Sprite::m_currentFrame [protected, inherited]

The current frame of animation.

Definition at line 52 of file sprite.h.

int Sprite::m_frameDelay [protected, inherited]

Number of milliseconds to show a frame for.

Definition at line 61 of file sprite.h.

QVector<Frame> Sprite::m_frames [protected, inherited]

Array of animation frames.

Definition at line 57 of file sprite.h.

bool Sprite::m_isKilled [protected, inherited]

True if we've been killed.

Definition at line 58 of file sprite.h.

bool Sprite::m_killAfterLastFrame [protected, inherited]

True if we should auto-kill after the last frame.

Definition at line 59 of file sprite.h.

int Seaweed::m_lifeTimeMS [private]

Life time of seaweed in milliseconds.

Definition at line 189 of file aasaver.cpp.

QList< int > Seaweed::m_positions [static, private]

Definition at line 190 of file aasaver.cpp.

Screen* Sprite::m_screen [protected, inherited]

The Screen that we belong to.

Definition at line 51 of file sprite.h.

int Seaweed::m_ticks [private]

Number of animation ticks elapsed.

Definition at line 188 of file aasaver.cpp.

int Sprite::m_ticksSinceFrameChange [protected, inherited]

Number of timer ticks since we last changed frame.

Definition at line 60 of file sprite.h.

int Sprite::m_x [protected, inherited]

Our current logical x position.

Definition at line 53 of file sprite.h.

int Sprite::m_y [protected, inherited]

Our current logical y position.

Definition at line 54 of file sprite.h.

int Sprite::m_z [protected, inherited]

Our current depth.

Definition at line 55 of file sprite.h.


The documentation for this class was generated from the following file: