CFleex.cpp 3.72 KB
Newer Older
1 2
#include "CFleex.h"

3 4 5 6
#include <engine/galaxy/common/ai/CPlayerLevel.h>

namespace galaxy
{
Gerhard Stein's avatar
Gerhard Stein committed
7

8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
$2C78W  #Fleex walking 0
$2C96W  #Fleex walking
$2CB4W  #Fleex track Keen 2
$2CD2W  #Fleex track Keen
$2CF0W  #Fleex track Keen
$2D0EW  #Fleex track Keen
$2D2CW  #Fleex look 6
$2D4AW  #Fleex look
$2D68W  #Fleex stunned 8
*/

enum FLEEXACTIONS
{
Gerhard Stein's avatar
Gerhard Stein committed
22 23 24 25
    A_FLEEX_WALK = 0,
    A_FLEEX_TRACK = 2,
    A_FLEEX_LOOK = 6,
    A_FLEEX_STUNNED = 8
26 27 28 29 30 31 32 33 34 35 36 37
};


const int WALK_SPEED = 30;
const int TRACK_SPEED = 120;

const int TIME_LOOKING = 200;
const int TIME_UNTIL_LOOK = 200;
const int DISTANCE_UNTIL_TRACK = 8<<CSF;


CFleex::CFleex(CMap* pmap, const Uint16 foeID, const Uint32 x, const Uint32 y) : 
Gerhard Stein's avatar
Gerhard Stein committed
38 39 40 41 42
    CStunnable(pmap, foeID, x, y),
    mHealth(4),
    mTimer(0),
    mKeenAlignment(LEFT),
    mGoodTrackChance(false)
43
{
Gerhard Stein's avatar
Gerhard Stein committed
44 45 46 47
    mActionMap[A_FLEEX_WALK] = (GASOFctr) &CFleex::processWalk;
    mActionMap[A_FLEEX_TRACK] = (GASOFctr) &CFleex::processTrack;
    mActionMap[A_FLEEX_LOOK] = (GASOFctr) &CFleex::processLook;
    mActionMap[A_FLEEX_STUNNED] = (GASOFctr) &CStunnable::processGettingStunned;
48 49 50
    
    setupGalaxyObjectOnMap(0x2C78, A_FLEEX_WALK);
    
Gerhard Stein's avatar
Gerhard Stein committed
51
    xDirection = LEFT;
52 53 54 55 56 57 58 59 60
}



void CFleex::processWalk()
{
    // Move normally in the direction
    if( xDirection == RIGHT )
    {
Gerhard Stein's avatar
Gerhard Stein committed
61
        moveRight( WALK_SPEED );
62 63 64
    }
    else
    {
Gerhard Stein's avatar
Gerhard Stein committed
65
        moveLeft( WALK_SPEED );
66 67 68
    }
    
    mTimer++;
Gerhard Stein's avatar
Gerhard Stein committed
69 70
    if( mTimer < TIME_UNTIL_LOOK )
        return;
71 72 73
    
    mTimer = 0;
    
Gerhard Stein's avatar
Gerhard Stein committed
74
    setAction(A_FLEEX_LOOK);
75 76 77 78 79 80 81 82
}


void CFleex::processTrack()
{
    // Move normally in the direction
    if( xDirection == RIGHT )
    {
Gerhard Stein's avatar
Gerhard Stein committed
83
        moveRight( TRACK_SPEED );
84 85 86
    }
    else
    {
Gerhard Stein's avatar
Gerhard Stein committed
87
        moveLeft( TRACK_SPEED );
88 89 90 91
    }
    
    if(getActionStatus(A_FLEEX_WALK))
    {
Gerhard Stein's avatar
Gerhard Stein committed
92 93
        setAction(A_FLEEX_WALK);
    }
94 95 96 97 98 99 100
}


void CFleex::processLook()
{
    if(getActionStatus(A_FLEEX_TRACK))
    {
Gerhard Stein's avatar
Gerhard Stein committed
101 102
        xDirection = mKeenAlignment;
        setAction(A_FLEEX_TRACK);
103 104 105 106 107 108 109
    }
}



bool CFleex::isNearby(CSpriteObject& theObject)
{
Gerhard Stein's avatar
Gerhard Stein committed
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
    if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) )
    {
        if( player->getXMidPos() < getXMidPos() )
            mKeenAlignment = LEFT;
        else
            mKeenAlignment = RIGHT;


        const int objX = theObject.getXMidPos();
        const int objY = theObject.getYMidPos();
        const int fleexX = getXMidPos();
        const int fleexY = getYMidPos();

        mGoodTrackChance = false;

        if( objX < fleexX - DISTANCE_UNTIL_TRACK ||
                objX > fleexX + DISTANCE_UNTIL_TRACK )
            return false;

        if( objY < fleexY - DISTANCE_UNTIL_TRACK ||
                objY > fleexY + DISTANCE_UNTIL_TRACK )
            return false;

        mGoodTrackChance = true;
    }

    return true;
137 138 139 140 141 142
}


void CFleex::getTouchedBy(CSpriteObject& theObject)
{
    if(dead || theObject.dead)
Gerhard Stein's avatar
Gerhard Stein committed
143
        return;
144 145 146 147 148 149
    
    CStunnable::getTouchedBy(theObject);
    
    // Was it a bullet? Then loose health.
    if( dynamic_cast<CBullet*>(&theObject) )
    {
Gerhard Stein's avatar
Gerhard Stein committed
150 151 152 153 154 155 156 157 158 159 160 161
        mHealth--;
        theObject.dead = true;

        if(mHealth == 0)
        {
            setAction(A_FLEEX_STUNNED);
            dead = true;
        }
        else
        {
            blink(10);
        }
162 163 164 165
    }
    
    if( CPlayerBase *player = dynamic_cast<CPlayerBase*>(&theObject) )
    {
Gerhard Stein's avatar
Gerhard Stein committed
166 167
        player->kill();
    }
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
}



int CFleex::checkSolidD(int x1, int x2, int y2, const bool push_mode)
{
    turnAroundOnCliff( x1, x2, y2 );
    
    return CGalaxySpriteObject::checkSolidD(x1, x2, y2, push_mode);
}



void CFleex::process()
{
    performCollisions();
    
    performGravityHigh();
    
    if( blockedl )
Gerhard Stein's avatar
Gerhard Stein committed
188
        xDirection = RIGHT;
189
    else if(blockedr)
Gerhard Stein's avatar
Gerhard Stein committed
190
        xDirection = LEFT;
191 192
    
    if(!processActionRoutine())
Gerhard Stein's avatar
Gerhard Stein committed
193
        exists = false;
194 195 196 197
    
    (this->*mp_processState)();
}

Gerhard Stein's avatar
Gerhard Stein committed
198

199 200 201 202


  
  
Gerhard Stein's avatar
Gerhard Stein committed
203
}