Quad Pang
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Private Attributes
Bongo Class Reference

This is Quad that is controled by the user. More...

#include <Bongo.h>

Inheritance diagram for Bongo:
Quad_impl Quad_impl Quad Quad Quad Quad

List of all members.

Public Member Functions

 Bongo ()
 ~Bongo ()
ArrowFire ()
 Give an arrow object.
void AddArrow ()
 Get back arrow object.
bool IsVulnerable ()
 whether Bongo can be affected by ball hit
void SetLives (int nl)
 Set number of lives.
int Lives ()
 Number of lives.
int Kill ()
 Kill (one life less)
void Free ()
 Bongo is released.
 Bongo ()
 ~Bongo ()
ArrowFire ()
 Give an arrow object.
void AddArrow ()
 Get back arrow object.
bool IsVulnerable ()
 whether Bongo can be affected by ball hit
void SetLives (int nl)
 Set number of lives.
int Lives ()
 Number of lives.
int Kill ()
 Kill (one life less)
void Free ()
 Bongo is released.
Implementation of Quad and Quad_impl
bool Init (XRes *resource, XCongo *xcongo)
 Read Quad from resource file.
bool Display ()
 Draw itself in global cotext. Since quads are intented to be used with opengl, drawing context is global.
const char * ClassName () const
 Used for RTTI.
bool Forse (const double *forse)
bool Init (XRes *resource, XCongo *xcongo)
 Read Quad from resource file.
bool Display ()
 Draw itself in global cotext. Since quads are intented to be used with opengl, drawing context is global.
const char * ClassName () const
 Used for RTTI.
bool Forse (const double *forse)

Private Attributes

bool mbHasArrow
 Whether arrow is available.
int mFlashingTime
 How long bongo will be flashing when hit.
int mbFlashing
 Whether bongo is flashing.
time_t mStartFlashing
 When bongo started to flash.
int mFlashingPeriodFrames
 How many frames will one flash sequence last.
int mbImmortal
 Bongo can't be killed.
int mnLives
 Number of lives left.
int mbCaptured
 Whether bongo is captured.
XResmpArrowResource
 Resource to load arrow from.

Detailed Description

This is Quad that is controled by the user.

It can move only in X-Z access and shot Ball's with Arrows. It can be killed by Balls when it is hit 3 times.

Definition at line 16 of file Bongo.h.


Constructor & Destructor Documentation

Definition at line 12 of file Bongo.cpp.

: mpArrowResource(0), mbCaptured(false), mbFlashing(false)
{ 
}

Definition at line 17 of file Bongo.cpp.

References mpArrowResource.

{
    delete mpArrowResource;
}

Member Function Documentation

void Bongo::AddArrow ( )

Get back arrow object.

Bongo will not be able to shoot another arrow before it get it back.

Definition at line 156 of file Bongo.cpp.

References mbHasArrow.

Referenced by CollisionMaster::Collision().

{ 
    mbHasArrow = true; 
}
void Bongo::AddArrow ( )

Get back arrow object.

Bongo will not be able to shoot another arrow before it get it back.

const char * Bongo::ClassName ( ) const [virtual]

Used for RTTI.

Returns:
Name of the actual class.
See also:
Factory

Reimplemented from Quad_impl.

Definition at line 74 of file Bongo.cpp.

Referenced by CollisionMaster::Collision().

{ 
    return "Bongo"; 
}
const char* Bongo::ClassName ( ) const [virtual]

Used for RTTI.

Returns:
Name of the actual class.
See also:
Factory

Reimplemented from Quad_impl.

bool Bongo::Display ( ) [virtual]

Draw itself in global cotext. Since quads are intented to be used with opengl, drawing context is global.

Returns:
true if ok, false on error.

Reimplemented from Quad_impl.

Definition at line 96 of file Bongo.cpp.

References mbFlashing, mbHasArrow, Quad_impl::mColor, mFlashingPeriodFrames, Quad_impl::mPos, and Quad_impl::mSize.

{
    // used for flashing
    static int counter = 0;
    counter++;

    glPushMatrix();
    
    // use two colors, one for non flashinga and one for 
    // flashing bongo
    GLfloat cor[] = { mColor[0], mColor[1], mColor[2], 1.0 };
    GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 };
    if (mbFlashing && (counter/mFlashingPeriodFrames) % 2)
        memcpy(cor, white, 3 * sizeof(GLfloat) );

    // set material properties
    GLfloat mat_specular[] = { cor[0], cor[1], cor[2], 1.0 };
    GLfloat mat_shininess[] = { 50.0 };
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

    // position and clip plane
    glTranslatef(mPos[0], mPos[1], mPos[2]);
    GLdouble eqn[] = { 0.0, -1.0, 0.0, mSize }; 
    glClipPlane(GL_CLIP_PLANE1, eqn);
    glRotatef(90, -1.0, 0.0, 0.0); 
    if (!mbHasArrow)
        glEnable(GL_CLIP_PLANE1);

    // draw bongo
    glutSolidCone(mSize/2, 2 * mSize, int(mSize * 30), int(mSize * 22) );   /* draw sun */

    if (!mbHasArrow)
        glDisable(GL_CLIP_PLANE1);
    
    glPopMatrix();
    return true;
}
bool Bongo::Display ( ) [virtual]

Draw itself in global cotext. Since quads are intented to be used with opengl, drawing context is global.

Returns:
true if ok, false on error.

Reimplemented from Quad_impl.

Give an arrow object.

AddArrow must be called in order to Fire() again

Definition at line 84 of file Bongo.cpp.

References Arrow::Init(), mbHasArrow, and mpArrowResource.

Referenced by BongoOrthoMover::ProcessKey(), and BongoRealMover::ProcessKey().

{
    if (!mbHasArrow)
        return 0;

    Arrow *carr = new Arrow(this);
    carr->Init(mpArrowResource, 0);
   
    mbHasArrow = false;
    return carr;
}

Give an arrow object.

AddArrow must be called in order to Fire() again

bool Bongo::Forse ( const double *  forse)

Definition at line 79 of file Bongo.cpp.

References Quad_impl::Move().

{ 
    return Move(forse); 
}
bool Bongo::Forse ( const double *  forse)
void Bongo::Free ( )

Bongo is released.

void Bongo::Free ( )

Bongo is released.

Definition at line 172 of file Bongo.cpp.

References mbFlashing, Quad_impl::mPos, mStartFlashing, and Quad_impl::SetActive().

Referenced by Ball::Reincarnate().

{ 
    SetActive(true); mStartFlashing = time(0); 
    mbFlashing = true;  mPos[1] = 0.0;
}
bool Bongo::Init ( XRes resource,
XCongo xcongo 
) [virtual]

Read Quad from resource file.

Parameters:
resourceResource file contained description of Quad object.
xcongoGlobal settings file contained parameters not specific to this quad.
Returns:
true if ok, false on error.

Reimplemented from Quad_impl.

Definition at line 33 of file Bongo.cpp.

References XRes::DoubleValue(), XRes::IntValue(), LOGE, mbHasArrow, mbImmortal, Quad_impl::mColor, mFlashingPeriodFrames, mFlashingTime, mnLives, mpArrowResource, Quad_impl::mPos, and Quad_impl::mSize.

{
    if (!resource->DoubleValue("mSize", &mSize) )
    {
        LOGE("reading Bongo size");
        return false;
    }

    if (!resource->DoubleValue("mPos.mX", &mPos[0])
        || !resource->DoubleValue("mPos.mY",&mPos[1])
        || !resource->DoubleValue("mPos.mZ", &mPos[2]))
    {
        LOGE("reading Bongo position");
        return false;
    }

    
     if (!resource->DoubleValue("mColor.red", &mColor[0])
        || !resource->DoubleValue("mColor.green",&mColor[1])
        || !resource->DoubleValue("mColor.blue", &mColor[2]))
    {
        LOGE("reading Bongo color");
        return false;
    }

    double pom;
    if (!resource->IntValue("mbImmortal", &mbImmortal)
        || !resource->IntValue("mnLives",&mnLives) 
        || !resource->IntValue("mFlashingTime",&mFlashingTime)
        || !resource->DoubleValue("mFlashingPeriodFrames",&pom) ) 
    {
        LOGE("reading Bongo life settings");
        return false;
    }
    mFlashingPeriodFrames = (int)ceil(pom);
    mbHasArrow = true;
    mpArrowResource = new XRes(resource, "mArrow");

    return true;
}
bool Bongo::Init ( XRes resource,
XCongo xcongo 
) [virtual]

Read Quad from resource file.

Parameters:
resourceResource file contained description of Quad object.
xcongoGlobal settings file contained parameters not specific to this quad.
Returns:
true if ok, false on error.

Reimplemented from Quad_impl.

whether Bongo can be affected by ball hit

whether Bongo can be affected by ball hit

we will this method to disable flashing as well, since it is called from Update method. It's not the best way though.

Definition at line 139 of file Bongo.cpp.

References mbFlashing, mbImmortal, mFlashingTime, and mStartFlashing.

Referenced by CollisionMaster::Collision().

{ 
    if (mbImmortal)
        return false;
        
    if (!mbFlashing)
        return true;

    if (mStartFlashing + mFlashingTime > time(0))
        return false;

    // disable flashing
    mbFlashing = false;

    return true;
}
int Bongo::Kill ( )

Kill (one life less)

int Bongo::Kill ( )

Kill (one life less)

Definition at line 22 of file Bongo.cpp.

References mbFlashing, mnLives, and mStartFlashing.

Referenced by CollisionMaster::Collision().

{
    if (mnLives > 1)
    {
        mStartFlashing = time(0); 
        mbFlashing = true; 
    }
    
    return --mnLives; 
}
int Bongo::Lives ( )

Number of lives.

int Bongo::Lives ( )

Number of lives.

Definition at line 166 of file Bongo.cpp.

References mnLives.

Referenced by Ball::Reincarnate().

{ 
    return mnLives; 

}
void Bongo::SetLives ( int  nl)

Set number of lives.

void Bongo::SetLives ( int  nl)

Set number of lives.

Definition at line 161 of file Bongo.cpp.

References mnLives.

Referenced by Ball::Reincarnate().

{ 
    mnLives = nl; 
}

Member Data Documentation

int Bongo::mbCaptured [private]

Whether bongo is captured.

Definition at line 74 of file Bongo.h.

int Bongo::mbFlashing [private]

Whether bongo is flashing.

Definition at line 64 of file Bongo.h.

Referenced by Display(), Free(), IsVulnerable(), and Kill().

bool Bongo::mbHasArrow [private]

Whether arrow is available.

Definition at line 59 of file Bongo.h.

Referenced by AddArrow(), Display(), Fire(), and Init().

int Bongo::mbImmortal [private]

Bongo can't be killed.

Definition at line 70 of file Bongo.h.

Referenced by Init(), and IsVulnerable().

How many frames will one flash sequence last.

Definition at line 68 of file Bongo.h.

Referenced by Display(), and Init().

int Bongo::mFlashingTime [private]

How long bongo will be flashing when hit.

Definition at line 62 of file Bongo.h.

Referenced by Init(), and IsVulnerable().

int Bongo::mnLives [private]

Number of lives left.

Definition at line 72 of file Bongo.h.

Referenced by Init(), Kill(), Lives(), and SetLives().

Resource to load arrow from.

Definition at line 76 of file Bongo.h.

Referenced by Fire(), Init(), and ~Bongo().

time_t Bongo::mStartFlashing [private]

When bongo started to flash.

Definition at line 66 of file Bongo.h.

Referenced by Free(), IsVulnerable(), and Kill().


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