CSpirogrip.cpp 5.44 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * CSpirogrip.cpp
 *
 *  Created on: 29 Dez 2012
 *      Author: Gerstrong
 */


#include "CSpirogrip.h"
#include "engine/galaxy/common/ai/CPlayerBase.h"
#include <engine/galaxy/common/ai/CPlayerLevel.h>
#include "misc.h"

/*
15 16 17 18 19 20 21 22 23
$2824W #Spirogrip back up down 0
$2842W #Spriogrip pause down 1
$2860W #Spirogrip back up left 2
$287EW #Spirogrip pause left 3
$289CW #Spirogrip back up up 4
$28BAW #Spirogrip pause up 5
$28D8W #Spirogrip back up right 6
$28F6W #Spirogrip puase right 7
$2914W #Spirogrip spin 8
Gerhard Stein's avatar
Gerhard Stein committed
24
$2932W #Spirogrip spin 9
25 26 27 28 29 30 31 32 33 34
$2950W #Spirogrip spin
$296EW #Spirogrip spin
$298CW #Spirogrip spin
$29AAW #Spirogrip spin
$29C8W #Spirogrip spin
$29E6W #Spirogrip spin
$2A04W #Spirogrip move down 16
$2A22W #Spirogrip move left 17
$2A40W #Spirogrip move up 18
$2A5EW #Spirogrip move right 19
35 36 37 38 39
 */


namespace galaxy {  
  
40
enum GRIPACTIONS
41
{
42 43 44 45 46 47 48 49 50 51 52
    A_GRIP_BACK_UP_DOWN = 0,
    A_GRIP_PAUSE_DOWN = 1,
    A_GRIP_BACK_UP_LEFT = 2,
    A_GRIP_PAUSE_LEFT = 3,
    A_GRIP_BACK_UP_UP = 4,
    A_GRIP_PAUSE_UP = 5,
    A_GRIP_BACK_UP_RIGHT = 6,
    A_GRIP_PAUSE_RIGHT = 7,
    A_GRIP_SPIN = 8,
    A_GRIP_MOVE_DOWN = 16,
    A_GRIP_MOVE_LEFT = 17,
Gerhard Stein's avatar
Gerhard Stein committed
53 54
    A_GRIP_MOVE_RIGHT = 18,
    A_GRIP_MOVE_UP = 19
55 56
};

Gerhard Stein's avatar
Gerhard Stein committed
57 58 59 60 61 62
const int MOVE_SPEED = 50;

const int TIME_UNTIL_SPIN = 50;
const int TIME_UNTIL_FLY = 150;
const int TIME_UNTIL_PAUSE = 50;
const int TIME_UNTIL_BACKUP = 100;
63 64 65 66 67 68

  
CSpirogrip::CSpirogrip(CMap *pmap, const Uint16 foeID, const Uint32 x, const Uint32 y) :
CStunnable(pmap, foeID, x, y),
mTimer(0)
{
Gerhard Stein's avatar
Gerhard Stein committed
69 70 71 72 73 74 75 76 77 78 79 80 81
    mActionMap[A_GRIP_BACK_UP_DOWN] = (GASOFctr) &CSpirogrip::processBackup;
    mActionMap[A_GRIP_PAUSE_DOWN] = (GASOFctr) &CSpirogrip::processPause;
    mActionMap[A_GRIP_BACK_UP_LEFT] = (GASOFctr) &CSpirogrip::processBackup;
    mActionMap[A_GRIP_PAUSE_LEFT] = (GASOFctr) &CSpirogrip::processPause;
    mActionMap[A_GRIP_BACK_UP_UP] = (GASOFctr) &CSpirogrip::processBackup;
    mActionMap[A_GRIP_PAUSE_UP] = (GASOFctr) &CSpirogrip::processPause;
    mActionMap[A_GRIP_BACK_UP_RIGHT] = (GASOFctr) &CSpirogrip::processBackup;
    mActionMap[A_GRIP_PAUSE_RIGHT] = (GASOFctr) &CSpirogrip::processPause;
    mActionMap[A_GRIP_SPIN] = (GASOFctr) &CSpirogrip::processSpin;
    mActionMap[A_GRIP_MOVE_DOWN] = (GASOFctr) &CSpirogrip::processMove;
    mActionMap[A_GRIP_MOVE_LEFT] = (GASOFctr) &CSpirogrip::processMove;
    mActionMap[A_GRIP_MOVE_UP] = (GASOFctr) &CSpirogrip::processMove;
    mActionMap[A_GRIP_MOVE_RIGHT] = (GASOFctr) &CSpirogrip::processMove;    
82
  
Gerhard Stein's avatar
Gerhard Stein committed
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
    // Adapt this AI
    setupGalaxyObjectOnMap(0x2824, A_GRIP_BACK_UP_DOWN);

    xDirection = CENTER;
    yDirection = DOWN;
}

void CSpirogrip::processBackup()
{    
  mTimer++;
  if( mTimer < TIME_UNTIL_PAUSE )
      return;
  
  mTimer = 0;
    
  if(xDirection == LEFT)
      setAction(A_GRIP_PAUSE_LEFT);
  else if(xDirection == RIGHT)
      setAction(A_GRIP_PAUSE_RIGHT);

  if(yDirection == UP)
      setAction(A_GRIP_PAUSE_UP);
  else if(yDirection == DOWN)
      setAction(A_GRIP_PAUSE_DOWN);

108 109 110
}


Gerhard Stein's avatar
Gerhard Stein committed
111 112 113 114 115 116 117 118 119
void CSpirogrip::processPause()
{
  mTimer++;
  if( mTimer < TIME_UNTIL_SPIN )
      return;
  
  mTimer = 0;
    
  setAction(A_GRIP_SPIN);
120

Gerhard Stein's avatar
Gerhard Stein committed
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
}

void CSpirogrip::processSpin()
{
  mTimer++;
  if( mTimer < TIME_UNTIL_FLY )
      return;
  
  mTimer = 0;

  playSound(SOUND_SPIROFLY);
  
  // Look at the Player coords and define a direction
  xDirection = yDirection = CENTER;
  if(getProbability(500))
      xDirection = mKeenAlignmentX;
  else
      yDirection = mKeenAlignmentY;
  
  if(xDirection == LEFT)
      setAction(A_GRIP_MOVE_LEFT);
  else if(xDirection == RIGHT)
      setAction(A_GRIP_MOVE_RIGHT);

  if(yDirection == UP)
      setAction(A_GRIP_MOVE_UP);
  else if(yDirection == DOWN)
      setAction(A_GRIP_MOVE_DOWN);
  
}



void CSpirogrip::processMove()
155 156
{
  // Move normally in the direction
Gerhard Stein's avatar
Gerhard Stein committed
157 158 159 160
  moveXDir( xDirection*MOVE_SPEED );
  moveYDir( yDirection*MOVE_SPEED );
  
  if( blockedl )
161
  {
Gerhard Stein's avatar
Gerhard Stein committed
162 163 164
    xDirection = RIGHT;
    yDirection = CENTER;
    setAction(A_GRIP_BACK_UP_RIGHT);    
165
  }
Gerhard Stein's avatar
Gerhard Stein committed
166
  else if( blockedr )
167
  {
Gerhard Stein's avatar
Gerhard Stein committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
    xDirection = LEFT;
    yDirection = CENTER;
    setAction(A_GRIP_BACK_UP_LEFT);
  }
	
  if( blockedu )
  {
    xDirection = CENTER;
    yDirection = UP;
    setAction(A_GRIP_BACK_UP_UP);
  }
  else if( blockedd )
  {
    xDirection = CENTER;
    yDirection = DOWN;
    setAction(A_GRIP_BACK_UP_DOWN);
  }
  
  mTimer++;
  if( mTimer < TIME_UNTIL_BACKUP )
      return;
  
  mTimer = 0;
  
  if(getProbability(500))
  {            
      if(xDirection == LEFT)
	  setAction(A_GRIP_BACK_UP_LEFT);
      else if(xDirection == RIGHT)
	  setAction(A_GRIP_BACK_UP_RIGHT);
      
      if(yDirection == UP)
	  setAction(A_GRIP_BACK_UP_UP);
      else if(yDirection == DOWN)
	  setAction(A_GRIP_BACK_UP_DOWN);
  }
      
205 206 207 208 209 210
}


bool CSpirogrip::isNearby(CSpriteObject &theObject)
{
	if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) )
Gerhard Stein's avatar
Gerhard Stein committed
211 212 213 214 215 216 217 218
	{	    	    
		if( player->getXMidPos() < getXMidPos() )
			mKeenAlignmentX = LEFT;
		else
			mKeenAlignmentX = RIGHT;

		if( player->getYMidPos() < getYMidPos() )
			mKeenAlignmentY = UP;
219
		else
Gerhard Stein's avatar
Gerhard Stein committed
220
			mKeenAlignmentY = DOWN;
221 222 223 224 225 226 227 228 229 230 231 232 233 234
	}

	return true;
}

void CSpirogrip::getTouchedBy(CSpriteObject &theObject)
{
	if(dead || theObject.dead)
		return;

	CStunnable::getTouchedBy(theObject);

	// Was it a bullet? Than make it stunned.
	if( dynamic_cast<CBullet*>(&theObject) )
Gerhard Stein's avatar
Gerhard Stein committed
235
	{				
236 237 238
		theObject.dead = true;
	}

Gerhard Stein's avatar
Gerhard Stein committed
239
	if( CPlayerBase *player = dynamic_cast<CPlayerBase*>(&theObject) )
240 241
	{
		player->kill();
Gerhard Stein's avatar
Gerhard Stein committed
242
	}
243 244 245 246 247
}


void CSpirogrip::process()
{
Gerhard Stein's avatar
Gerhard Stein committed
248
	performCollisions();		
249 250 251 252 253 254 255 256

	if(!processActionRoutine())
	    exists = false;
	
	(this->*mp_processState)();
}

}