CVortiMom.cpp 3.44 KB
Newer Older
1
#include "../../../sdl/sound/CSound.h"
Gerhard Stein's avatar
Gerhard Stein committed
2
#include <base/video/CVideoDriver.h>
3
#include "../../../misc.h"
4

5
#include "CVortiMom.h"
6
#include "CFireBall.h"
7

8 9
CVortiMom::CVortiMom(CMap *p_map, Uint32 x, Uint32 y) :
CVorticonSpriteObject(p_map, x, y, OBJ_MOTHER)
10
{
11
	mHealthPoints = MOTHER_HP;
12 13 14
	state = MOTHER_WALK;
	animframe = 0;
	animtimer = 0;
Gerhard Stein's avatar
Gerhard Stein committed
15
	canbezapped = true;
16 17

	blockedr = blockedl = 0;
18

19 20 21
    const auto diff = g_pBehaviorEngine->mDifficulty;

    if(diff>NORMAL)
22
		mHealthPoints++;
23
    else if(diff<NORMAL)
24
		mHealthPoints--;
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

    if(diff == EXPERT)
    {
        mSprVar = 1;
        mHealthPoints *= 2;
    }
    else if(diff == NINJA)
    {
        mSprVar = 2;
        mHealthPoints *= 3;
    }
    else if(diff == ELITE)
    {
        mSprVar = 3;
        mHealthPoints *= 4;
    }

42 43
}

44 45 46


bool CVortiMom::isNearby(CVorticonSpriteObject &theObject)
47
{
48 49 50
    if( CPlayer *player = dynamic_cast<CPlayer*>(&theObject) )
    {
	if( state == MOTHER_HURT )
Gerhard Stein's avatar
Gerhard Stein committed
51
	{	 	    
52 53
	    if (timer > MOTHER_HURT_SHOW_TIME)
	    {
Gerhard Stein's avatar
Gerhard Stein committed
54
		if(mHealthPoints > 0)
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
		{
		    state = MOTHER_WALK;
		    if (player->getXPosition() > getXPosition())
			dir = RIGHT;
		    else
			dir = LEFT;
		}
	    }
	    
	}
    }
    
    return true;
}

70

71 72 73 74
void CVortiMom::getTouchedBy(CVorticonSpriteObject &theObject)
{
     if( CPlayer *player = dynamic_cast<CPlayer*>(&theObject) )
     {
Gerhard Stein's avatar
Gerhard Stein committed
75
	if(!player->pdie)
76 77
	{
		// don't push the player as he's walking through the exit door
78
		if (!player->level_done)
79
		{
80
			player->push(*this);
81
		}
82 83 84
	}    
     }
}
85 86


87 88 89 90
void CVortiMom::process()
{
	int prob;

91 92 93 94
	switch(state)
	{
	case MOTHER_WALK:

95
		prob = (g_pBehaviorEngine->mDifficulty>NORMAL) ? MOTHER_SPIT_PROB_HARD : MOTHER_SPIT_PROB;
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
		if (getProbability(prob))
		{
			if (onscreen)
			{
				if(dir == RIGHT)
					dir = LEFT;
				else
					dir = RIGHT;

				state = MOTHER_SPIT;
				timer = 0;
			}
		}

		if (dir==RIGHT)
		{
			sprite = MOTHER_WALK_RIGHT_FRAME + animframe;

			if (blockedr)
			{
				dir = LEFT;
			}
			else
			{
120
				xinertia = MOTHER_WALK_SPD;
121 122 123 124 125 126 127 128 129
			}
		}
		else
		{
			sprite = MOTHER_WALK_LEFT_FRAME + animframe;

			if (blockedl)
				dir = RIGHT;
			else
130
				xinertia = -MOTHER_WALK_SPD;
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
		}

		// walk animation
		if (animtimer > MOTHER_WALK_ANIM_RATE)
		{
			animframe ^= 1;
			animtimer = 0;
		}
		else animtimer++;

		break;

	case MOTHER_SPIT:
		sprite = (dir==RIGHT) ?
				MOTHER_SPIT_RIGHT_FRAME:MOTHER_SPIT_LEFT_FRAME;


		if (timer > MOTHER_SPIT_SHOW_TIME)
		{
			CFireBall *newobject = new CFireBall(mp_Map, getXMidPos()-(3<<STC),
												getYPosition()+(11<<STC), dir,
												OBJ_MOTHER, m_index);
153
			gEventManager.add(new EventSpawnObject(newobject));
154

Gerstrong's avatar
Gerstrong committed
155 156 157
			if (onscreen)
				playSound(SOUND_TANK_FIRE);

158 159 160 161 162
			state = MOTHER_WALK;
		}
		else timer++;
		break;
	case MOTHER_HURT:
Gerhard Stein's avatar
Gerhard Stein committed
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
	    if (timer > MOTHER_HURT_SHOW_TIME)
	    {
		if (mHealthPoints <= 0)
		{
		    sprite = MOTHER_DEAD_FRAME;
		    dead = true;
		    timer = 0;

		    playSound(SOUND_VORT_DIE);
		    
		    return;
		}
	    }	    	    	    
	    sprite = MOTHER_HURT_FRAME;
	    timer++;
	    break;
179 180 181
	default: break;
	}
}
Gerhard Stein's avatar
Gerhard Stein committed
182

183
void CVortiMom::getShotByRay(object_t &obj_type)
Gerhard Stein's avatar
Gerhard Stein committed
184
{
185
	if( state != MOTHER_HURT && mHealthPoints>0 )
Gerhard Stein's avatar
Gerhard Stein committed
186
	{
Gerhard Stein's avatar
Gerhard Stein committed
187
		if(mHealthPoints>1 && gVideoDriver.getSpecialFXConfig())
Gerhard Stein's avatar
Gerhard Stein committed
188 189
			blink(10);
		sprite = MOTHER_HURT_FRAME;
190
		mHealthPoints--;
Gerhard Stein's avatar
Gerhard Stein committed
191 192 193 194 195 196
		state = MOTHER_HURT;

	}
}