src/players.cpp
// This function makes a player unit drop a bullet

This function makes a player unit drop a bullet
This function makes a player unit drop a bullet
bool playerDropBullet(vectorListNodeStruct<playerUnitStruct>& unitP) {
	genericUnitTypeDataStruct* myPlayerType;
	genericUnitTypeDataStruct* myBulletType;
	frameDataStruct* myPlayerFrame;
	frameDataStruct* myBulletFrame;
	bulletUnitStruct unitB;
	long double x, y;
	if (!setupBulletUnit(unitB, FILE_GAMEDATA_BULLET_PLAYERFLAME))
		return false;
	myPlayerType=&(playerType[unitP.data.unitType]);
	myPlayerFrame=&(myPlayerType->frames[unitP.data.currentFrame]);
	myBulletType=&(bulletType[unitB.unitType]);
	myBulletFrame=&(myBulletType->frames[unitB.currentFrame]);
	x=unitP.data.x+
		(myPlayerFrame->spawnBulletsX);
	y=unitP.data.y+
		(myPlayerFrame->spawnBulletsY);
	unitB.x=x;
	unitB.y=y+(myBulletFrame->handlerY)-(myBulletFrame->h)/2;
	unitB.canCollideWithEnemies=true;
	unitB.canCollideWithPlayers=true;
	unitB.owner.id=unitP.data.id;
	unitB.owner.listIndex=playerList.getIndex(&unitP);
	unitB.owner.objectType=FILE_GAMEDATA_GAMEOBJECT_PLAYER;
	unitB.linearSpeed=
		gameWorld.xSpeedCamera+700/double(desiredFramesPerSecond);
	unitB.goingToPoint=true;
	unitB.goingToPointX=getRightWall(int(unitB.y));
	unitB.goingToPointX=MIN(unitB.goingToPointX,
		getRightWall(int(unitB.y-(myBulletFrame->handlerY))));
	unitB.goingToPointX=MIN(unitB.goingToPointX,
		getRightWall(int(unitB.y+(myBulletFrame->h)
		-(myBulletFrame->handlerY))));
	unitB.goingToPointY=unitB.y;
	if (unitB.goingToPointX<unitB.x) unitB.x=unitB.goingToPointX;
	setSpeedForLinealMove(
		&unitB,
		unitB.goingToPointX, unitB.goingToPointY,
		unitB.linearSpeed);
	if (!bulletList.isValidIndex(bulletList.addNode(unitB))) {
		logger.logLine("Failed adding node to bulletList");
		return false;
	}
	return true;
}
bool playerDropBullet ( vectorListNodeStruct < playerUnitStruct > & unitP ) { genericUnitTypeDataStruct * myPlayerType ; genericUnitTypeDataStruct * myBulletType ; frameDataStruct * myPlayerFrame ; frameDataStruct * myBulletFrame ; bulletUnitStruct unitB ; long double x , y ; if ( ! setupBulletUnit ( unitB , FILE_GAMEDATA_BULLET_PLAYERFLAME ) ) return false ; myPlayerType = & ( playerType [ unitP . data . unitType ] ) ; myPlayerFrame = & ( myPlayerType -> frames [ unitP . data . currentFrame ] ) ; myBulletType = & ( bulletType [ unitB . unitType ] ) ; myBulletFrame = & ( myBulletType -> frames [ unitB . currentFrame ] ) ; x = unitP . data . x + ( myPlayerFrame -> spawnBulletsX ) ; y = unitP . data . y + ( myPlayerFrame -> spawnBulletsY ) ; unitB . x = x ; unitB . y = y + ( myBulletFrame -> handlerY ) - ( myBulletFrame -> h ) / 2 ; unitB . canCollideWithEnemies = true ; unitB . canCollideWithPlayers = true ; unitB . owner . id = unitP . data . id ; unitB . owner . listIndex = playerList . getIndex ( & unitP ) ; unitB . owner . objectType = FILE_GAMEDATA_GAMEOBJECT_PLAYER ; unitB . linearSpeed = gameWorld . xSpeedCamera + 700 / double ( desiredFramesPerSecond ) ; unitB . goingToPoint = true ; unitB . goingToPointX = getRightWall ( int ( unitB . y ) ) ; unitB . goingToPointX = MIN ( unitB . goingToPointX , getRightWall ( int ( unitB . y - ( myBulletFrame -> handlerY ) ) ) ) ; unitB . goingToPointX = MIN ( unitB . goingToPointX , getRightWall ( int ( unitB . y + ( myBulletFrame -> h ) - ( myBulletFrame -> handlerY ) ) ) ) ; unitB . goingToPointY = unitB . y ; if ( unitB . goingToPointX < unitB . x ) unitB . x = unitB . goingToPointX ; setSpeedForLinealMove ( & unitB , unitB . goingToPointX , unitB . goingToPointY , unitB . linearSpeed ) ; if ( ! bulletList . isValidIndex ( bulletList . addNode ( unitB ) ) ) { logger . logLine ( " " ) ; return false ; } return true ; }
This function makes a player unit drop a bullet
This function makes a player unit drop a bullet
// Unit types
 // Unit frames
 // Other variables
 // set the default values for this bullet...
 // Select the unit types and frames
 // coordinates for the bullet
 // Center vertically the bullet on those coordinates
 // (x is the x coordinate of the bullet handler, while y is the
 // y coordinate of the center of the bullet)
 // What kind of units does this bullet hit?: enemies only
 // can this bullet unit collide with enemies?
 // can this bullet unit collide with players?
 // set the owner
 // speed for the bullet
 // set the linear movement
 // medium x collision point
 // top x collision point
 // bottom x collision point
 // check the bullet won't go backwards, and if it will, don't let
 // it do that: make it appear directly where it must to go
 // (this code assumes some specific horizontal direction for the
 // bullet)
 // player unit
 // dest pos
 // linear speed
 // add the bullet itself
 /*
	// do the sound of the bullet
	makeSoundPlayerDropBullet();
*/ // all ok
