src/collisions.cpp
// playerUnitHit ******
// This method is called every time a player unit is hit by anything.
// Then, it's responsible of making all the necessary changes in the
// touched player.

playerUnitHit
This method is called every time a player unit is hit by anything.
Then, it's responsible of making all the necessary changes in the
touched player.
playerUnitHit This method is called every time a player unit is hit by anything . Then it ' s responsible of making all the necessary changes in the touched player .
bool playerUnitHit(
	vectorListNodeStruct<playerUnitStruct>& pUnit,
	gameObjectPointerStruct& toucher)
{
	vectorListNodeStruct<enemyUnitStruct>* enemy;
	vectorListNodeStruct<playerUnitStruct>* player2;
	vectorListNodeStruct<bulletUnitStruct>* bullet;
	int counter;
	vectorListNodeStruct<playerUnitStruct> *extraPlayer;
	if (pUnit.data.untouchableTimeLeft>0 || pUnit.data.energyLeft<=0)
		return true;
	pUnit.data.untouchableTimeLeft=pUnit.data.untouchableTimeMax;
	switch(toucher.objectType) {
	case FILE_GAMEDATA_GAMEOBJECT_ENEMY:
		enemy=enemyList.getNode(toucher.listIndex);
		if (pUnit.data.decrementableEnergy)
			pUnit.data.energyLeft-=enemy->data.energyToDrop;
		if (pUnit.data.energyLeft<0) pUnit.data.energyLeft=0;
		break;
	case FILE_GAMEDATA_GAMEOBJECT_PLAYER:
		player2=playerList.getNode(toucher.listIndex);
		playerIncrementScoreForHit(
			toucher, pUnit.data.scoreToGivePerHit);
		if (pUnit.data.decrementableEnergy)
			pUnit.data.energyLeft-=player2->data.energyToDrop;
		if (pUnit.data.energyLeft<0) pUnit.data.energyLeft=0;
		break;
	case FILE_GAMEDATA_GAMEOBJECT_BULLET:
		bullet=bulletList.getNode(toucher.listIndex);
		if (bullet->data.owner.objectType==
			FILE_GAMEDATA_GAMEOBJECT_PLAYER) {
			if (!playerIncrementScoreForHit(
				bullet->data.owner,
				pUnit.data.scoreToGivePerHit)) return false;
		}
		if (pUnit.data.decrementableEnergy)
			pUnit.data.energyLeft-=bullet->data.energyToDrop;
		if (pUnit.data.energyLeft<0) pUnit.data.energyLeft=0;
		break;
	}
	if (pUnit.data.energyLeft<=0) {
		switch(pUnit.data.unitType) {
		case FILE_GAMEDATA_PLAYER_JAVATAR:
			pUnit.data.currentFrame=
				getFrameIndexAndListByName("javatarDeath");
			pUnit.data.vFramesPassed=0;
			break;
		}
		pUnit.data.untouchableTimeLeft=0;
		pUnit.data.unarmedTimeLeft=0;
		pUnit.data.trembling=false;
		pUnit.data.goingToPoint=true;
		pUnit.data.goingToPointX=110;
		pUnit.data.goingToPointY=
			gameWorld.yCamera-
			(20+constructContainerFrame(&pUnit.data).h)+
			constructContainerFrame(&pUnit.data).handlerY;
		if (pUnit.data.isPosRelative) {
			pUnit.data.goingToPointX-=gameWorld.xCamera;
			pUnit.data.goingToPointY-=gameWorld.yCamera;
		}
		setSpeedForLinealMove(
			&pUnit.data,
			pUnit.data.goingToPointX, pUnit.data.goingToPointY,
			160/double(desiredFramesPerSecond));
		for (extraPlayer=playerList.getFirstNode(), counter=0;
		extraPlayer!=NULL;
		extraPlayer=playerList.getNextNode(extraPlayer)) {
			if (!extraPlayer->data.nowActive ||
				extraPlayer->data.id==pUnit.data.id ||
				extraPlayer->data.energyLeft<=0)
				continue;
			counter++;
		}
		if (counter<=0 && !gameWorld.showGameOverMessage) {
			gameWorld.showGameOverMessage=true;
		}
	}else{
		if (pUnit.data.untouchableTimeLeft>0) {
			switch(pUnit.data.unitType) {
			case FILE_GAMEDATA_PLAYER_JAVATAR:
				pUnit.data.currentFrame=
					getFrameIndexAndListByName("javatarTouched");
				pUnit.data.trembling=true;
				pUnit.data.vFramesPassed=0;
				break;
			}
		}
	}
	return true;
}
bool playerUnitHit ( vectorListNodeStruct < playerUnitStruct > & pUnit , gameObjectPointerStruct & toucher ) { vectorListNodeStruct < enemyUnitStruct > * enemy ; vectorListNodeStruct < playerUnitStruct > * player2 ; vectorListNodeStruct < bulletUnitStruct > * bullet ; int counter ; vectorListNodeStruct < playerUnitStruct > * extraPlayer ; if ( pUnit . data . untouchableTimeLeft > 0 || pUnit . data . energyLeft <= 0 ) return true ; pUnit . data . untouchableTimeLeft = pUnit . data . untouchableTimeMax ; switch ( toucher . objectType ) { case FILE_GAMEDATA_GAMEOBJECT_ENEMY : enemy = enemyList . getNode ( toucher . listIndex ) ; if ( pUnit . data . decrementableEnergy ) pUnit . data . energyLeft -= enemy -> data . energyToDrop ; if ( pUnit . data . energyLeft < 0 ) pUnit . data . energyLeft = 0 ; break ; case FILE_GAMEDATA_GAMEOBJECT_PLAYER : player2 = playerList . getNode ( toucher . listIndex ) ; playerIncrementScoreForHit ( toucher , pUnit . data . scoreToGivePerHit ) ; if ( pUnit . data . decrementableEnergy ) pUnit . data . energyLeft -= player2 -> data . energyToDrop ; if ( pUnit . data . energyLeft < 0 ) pUnit . data . energyLeft = 0 ; break ; case FILE_GAMEDATA_GAMEOBJECT_BULLET : bullet = bulletList . getNode ( toucher . listIndex ) ; if ( bullet -> data . owner . objectType == FILE_GAMEDATA_GAMEOBJECT_PLAYER ) { if ( ! playerIncrementScoreForHit ( bullet -> data . owner , pUnit . data . scoreToGivePerHit ) ) return false ; } if ( pUnit . data . decrementableEnergy ) pUnit . data . energyLeft -= bullet -> data . energyToDrop ; if ( pUnit . data . energyLeft < 0 ) pUnit . data . energyLeft = 0 ; break ; } if ( pUnit . data . energyLeft <= 0 ) { switch ( pUnit . data . unitType ) { case FILE_GAMEDATA_PLAYER_JAVATAR : pUnit . data . currentFrame = getFrameIndexAndListByName ( " " ) ; pUnit . data . vFramesPassed = 0 ; break ; } pUnit . data . untouchableTimeLeft = 0 ; pUnit . data . unarmedTimeLeft = 0 ; pUnit . data . trembling = false ; pUnit . data . goingToPoint = true ; pUnit . data . goingToPointX = 110 ; pUnit . data . goingToPointY = gameWorld . yCamera - ( 20 + constructContainerFrame ( & pUnit . data ) . h ) + constructContainerFrame ( & pUnit . data ) . handlerY ; if ( pUnit . data . isPosRelative ) { pUnit . data . goingToPointX -= gameWorld . xCamera ; pUnit . data . goingToPointY -= gameWorld . yCamera ; } setSpeedForLinealMove ( & pUnit . data , pUnit . data . goingToPointX , pUnit . data . goingToPointY , 160 / double ( desiredFramesPerSecond ) ) ; for ( extraPlayer = playerList . getFirstNode ( ) , counter = 0 ; extraPlayer != NULL ; extraPlayer = playerList . getNextNode ( extraPlayer ) ) { if ( ! extraPlayer -> data . nowActive || extraPlayer -> data . id == pUnit . data . id || extraPlayer -> data . energyLeft <= 0 ) continue ; counter ++ ; } if ( counter <= 0 && ! gameWorld . showGameOverMessage ) { gameWorld . showGameOverMessage = true ; } } else { if ( pUnit . data . untouchableTimeLeft > 0 ) { switch ( pUnit . data . unitType ) { case FILE_GAMEDATA_PLAYER_JAVATAR : pUnit . data . currentFrame = getFrameIndexAndListByName ( " " ) ; pUnit . data . trembling = true ; pUnit . data . vFramesPassed = 0 ; break ; } } } return true ; }
playerUnitHit 
This method is called every time a player unit is hit by anything.
playerUnitHit This method is called every time a player unit is hit by anything .
// player unit which was hit
 // the one who touched the player unit
 // for counting other players
 // if this unit is in untouchable or dead state,
 // nothing can affect it now...
 // first change the unit to untouchable state.
 // What kind of thing has hit against the player?
 // it's an enemy unit
 // ENERGY
 // Hurt the player
 // calculate the damage
 // toucher type
 // it's a player unit
 // SCORING
 // Increment the toucher player score
 // ENERGY
 // Hurt the player
 // calculate the damage
 // toucher type
 // it's a bullet unit
 // SCORING
 // Increment the toucher player score
 // increment the score of the player
 // who dropped the bullet
 // ENERGY
 // Hurt the player
 // toucher type
 // switch unit type
 // check for death...
 // DEAD PLAYER
 // we are dead now...
 // set the player information for death
 // continue auto framing
 // dead people isn't untouchable neither unarmed
 // dead players are supposed to fall
 // correct the coordinates to be relative
 // player unit
 // dest pos
 // linear speed
 // EXTRA STUFF FOR DEAD PLAYER
 // set some extra stuff, interesting for dead players
 // firstly check it's the only player
 // Count the active players
 // don't count inactive units, neither this unit, neither
 // those that haven't any more energy (so they are dying
 // right now)
 // there are no other alive players, do what's needed
 // A game over message should be shown
 // Scream the game over thing
 /*			makeSoundGameOver();*/ // Execute the sound of the player being death...
 /*		makeSoundProtagKilled();*/ // PLAYER TOUCHED (not dead)
 // we aren't dead, but have been touched
 // and go tremble
 // continue auto framing
 /*		// Execute the sound of the player being touched...
		makeSoundProtagTouched();*/ // all ok
