Exemplo n.º 1
0
/// <summary>
/// Processes this instance.
/// </summary>
void Player::process()
{
	normalShotTime += timeStep;
	specialShotTime += timeStep;
	pwrUpTime += timeStep;
	pulseTime += timeStep;

	this->hitDetection();
	this->detectEdge();
	this->processPowerUps();

	if (getHealth() <= 0)
	{
		setDeleted(true);
		resourceHandler->getSound(ResourceHandler::Sound::FX_ENEMY_DEATH).play();
	}

	// Ship collision
	for (auto& i : objects)
	{
		if (i->getType() == Shooter::ShooterType::PLAYER) continue;

		if (this->sat(i->sprite, this->sprite))
		{
			// Kill the player, (ship collisions never end well)
			this->setHealth(this->getHealth() - 1);
			i->setHealth(i->getHealth() - 1);
		}
	}
}
Exemplo n.º 2
0
/// <summary>
/// Processes the bullet
/// </summary>
void Bullet::process()
{

	// Checks if its deleted
	if (!getDeleted())
	{

		// If degrees is set (not -1), do rotational movement
		if (deg != -1) // Rotational movement
		{
			double move_x = timeStep.asSeconds() * speedX * cos(deg) - sin(deg);
			double move_y = timeStep.asSeconds() *  speedY * sin(deg) + cos(deg);
			this->sprite->move(move_x, move_y);
		}
		else // Linear movement.
		{
			this->sprite->setPosition(
				sprite->getPosition().x + (timeStep.asSeconds() * speedX),
				sprite->getPosition().y + (timeStep.asSeconds() * speedY));

		}

		// If the bullet is out of bounds, we set delete flag
		if (isOutOfBounds())
		{
			setDeleted(true);
		}
	}
}
Exemplo n.º 3
0
/**
 * Moves all the group's entries (recursively) to Backup group; subgroups are deleted.
 * Returns true if successful.
 */
bool PwGroupV3::moveToBackup() {
    PwGroup* parentGroup = this->getParentGroup();
    if (!parentGroup) {
        LOG("PwGroupV3::moveToBackup fail - no parent group");
        return false;
    }

    PwGroup* backupGroup = getDatabase()->getBackupGroup(true);
    // For v3, backupGroup is guaranteed to be not NULL

    parentGroup->removeSubGroup(this);
    // detach this branch from the parent group; memory will be released later.

    // flag the group and all its children deleted
    setDeleted(true);
    QList<PwGroup*> childGroups;
    QList<PwEntry*> childEntries;
    getAllChildren(childGroups, childEntries);
    // V3 does not backup subgroups, so move only entries
    for (int i = 0; i < childEntries.size(); i++) {
        if (!childEntries.at(i)->moveToBackup()) {
            LOG("PwGroupV3::moveToBackup fail on child entry");
            return false;
        }
    }
    childGroups.clear();
    childEntries.clear();
    LOG("PwGroupV3::moveToBackup OK");
    return true;
}
Exemplo n.º 4
0
void CircleGameObject::updatePos() {
    PhysicsObject::updatePos();
    if (getShape() != NULL) {
        float lowerBound = -Context::getInstance()->getH();
        if (getShape()->getCenter().y() < lowerBound) {
            setDeleted(true);
        }
    }
}
Exemplo n.º 5
0
void Unit::update( const int& dt )
{
	DT = dt;
	if( isDeleted() )
		return;
	if( Char.state.hp < 0 )
		return die();
	if( dist( UnitManager::GetPlayer( ) ) > 2000 ){
		return setDeleted();
	}

	Actions.updateTimers( dt );

	if( physBody )
		Image.setPosition( (float)physBody->p.x, (float)physBody->p.y );

	if( !Actions.loaded )
		return;

	while( !Actions.nextFrame( ) ){
		const Frame& frame = Actions.action->frames[Actions.frame];

		if( frame.func != LUA_NOREF ){

			extern LuaScript* luaScript;

			this->pushUData( luaScript->getState() );
			int ret_val = luaScript->ExecChunkFromReg( frame.func, 1 );
			if( ret_val == -1 )	{
				Debug::debug( Debug::PROTO,
					"An error occurred while executing a local function. obj id  " +
					citoa(UnitId) + ", proto_name '" + Actions.proto->name + "', action '" +
					Actions.action->name  + "', frame " + citoa(Actions.frame) +
					": " + luaScript->getString( -1 ) + ".\n" );
			}

			for(int i = 0; i > ret_val; ++i ){
				switch( luaScript->getType( 1 ) ){
					case LUA_TNUMBER:
						Actions.params.Push( (int)luaScript->getNumber( 1 ) );
						break;
					case LUA_TSTRING:
						Actions.params.Push( luaScript->getChar( 1 ) );
						break;
				}
			}
		}

		// Make a pause on false result;
		if( !update( frame ) )
			break;

	}

}
Exemplo n.º 6
0
/// <summary>
/// Resets the path with use of the pathTemplate. And then sets current path to the first value in the queue.
/// </summary>
void Enemy::setInitPath()
{

	setDeleted(false);
	this->path = pathTemplate;
	this->currentPath = this->path.front();
	this->acceleration = 0;
	this->path.pop();

	this->sprite->setPosition(currentPath.x, currentPath.y);
}
Exemplo n.º 7
0
/// <summary>
/// A function which determines weither the player and a powerup collided.
/// </summary>
/// <param name="player">The player.</param>
/// <returns>Bool value which determines a pickup or not</returns>
bool Powerup::hitDetection(std::shared_ptr<Player>& player)
{
	// CHeck hit detection
	bool retVal = sat(this->sprite, player->sprite);

	// Check if there was a hit collision
	if (retVal)
	{
		// Set status to deleted
		resourceHandler->getSound(ResourceHandler::Sound::FX_PICKUP_HEALTH).play();
		setDeleted(true);
	}

	return retVal;
}
Exemplo n.º 8
0
/// <summary>
/// Processes the powerup
/// </summary>
void Powerup::process()
{

	// Check if the powerup is deleted or not, if it is, we do not want to move it.
	if (!getDeleted())
	{
		this->sprite->setPosition(
			sprite->getPosition().x + (timeStep.asSeconds() * speedX),
			sprite->getPosition().y + (timeStep.asSeconds() * speedY));

	}

	// Check if the powerup is out of bounds
	if (isOutOfBounds())
	{
		setDeleted(true);
	}
}
Exemplo n.º 9
0
/// <summary>
/// Processes this instance.
/// </summary>
void Enemy::process()
{
	// Update sf::Time's in enemy
	shootTime += timeStep;
	sleepTime += timeStep;

	this->hitDetection();
	this->emotes();
	this->movement();
	this->shootProcess();

	// If health is 0, play death sound and set deleted status.
	if (getHealth() <= 0){
		// Play Death Sound
		resourceHandler->getSound(ResourceHandler::Sound::FX_ENEMY_DEATH).play();
		setDeleted(true);
	}
}
Exemplo n.º 10
0
/// <summary>
/// Initializes a new instance of the <see cref="Bullet"/> class.
/// </summary>
/// <param name="window">The window.</param>
/// <param name="bulletType">Type of the bullet.</param>
/// <param name="timeStep">The time step.</param>
/// <param name="resourceHandler">The resource handler.</param>
Bullet::Bullet(sf::RenderWindow& window, Bullet::Type bulletType, const sf::Time& timeStep, std::shared_ptr<ResourceHandler>& resourceHandler) :
Object(window),
bulletType(bulletType),
timeStep(timeStep),
deg(-1) // Set rotation as -1 while not inited.
{
	setDeleted(false);

	// Define the bullet texutres as a standard shot
	if (Bullet::Type::standardShot == bulletType){
		sprite = std::shared_ptr<GameShape>(new GameShape(GameShape::CIRCLE, 3, 10));
		sprite->setTexture(&resourceHandler->getTexture(ResourceHandler::Texture::REGULAR_BULLET_1));
	}

	// Define the bullet textures as a heavy shot 
	else if (Bullet::Type::heavyShot == bulletType)
	{
		sprite = std::shared_ptr<GameShape>(new GameShape(GameShape::TRIANGLE, 40.0f));
		sprite->setTexture(&resourceHandler->getTexture(ResourceHandler::Texture::HEAVY_SHOT_TEXTURE));
	}

}
Exemplo n.º 11
0
void Player::update( double delta )
{
	if ( !timers["death_anim"].isRunning() && !timers["death_anim"].hasFinished() )
	{
		if ( input != nullptr )
			input->update( *this, delta );
		Entity::update( delta );

		if ( velocity.length() != 0.0f && !timers["shooting_anim"].isRunning() )
		{
			if ( utils::closestToZero( velocity.x, velocity.y ) == velocity.y )
			{
				if ( velocity.x > 0 )
					direction = "right";
				else
					direction = "left";
			}
			else
			{
				if ( velocity.y > 0 )
					direction = "down";
				else
					direction = "up";
			}
		}

		if ( health <= 0 )
			die();

		if ( timers["shooting_anim"].isRunning() )
		{
			state = "shooting";
		}
	}

	if ( timers["death_anim"].hasFinished() )
		setDeleted();
}
Exemplo n.º 12
0
void Unit::update( const int& dt )
{
	DT = dt;
	if( isDeleted() )
		return;

	// FIXME: move to prototypes
	if( Char.state.hp < 0 ){
		extern LuaScript* luaScript;
		luaScript->push( std::string("die") );
		emitEvent( luaScript->getState() );
		if(isDeleted())
			return;
	}

	if( dist( UnitManager::GetPlayer( ) ) > 2000 ){
		return setDeleted();
	}

	Actions.updateTimers( dt );

	if( physBody )
		Image.setPosition( (float)physBody->p.x, (float)physBody->p.y );

	if( !Actions.loaded )
		return;

	while( !Actions.nextFrame( ) ){
		const Frame& frame = Actions.action->frames[Actions.frame];

		if( frame.func != LUA_NOREF ){

			extern LuaScript* luaScript;

			this->pushUData( luaScript->getState() );
			int ret_val = luaScript->ExecChunkFromReg( frame.func, 1 );
			if( ret_val == -1 )	{
				Debug::debug( Debug::PROTO,
					"An error occurred while executing a local function. Id: %d, proto_name '%s', action '%s', frame %d: %s.\n",
					UnitId, Actions.proto->name.c_str(),
					Action::getName(Actions.action->id).c_str(), Actions.frame,
					luaScript->getChar(-1) );
			}

			for(int i = 0; i > ret_val; ++i ){
				switch( luaScript->getType( 1 ) ){
					case LUA_TNUMBER:
						Actions.params.Push( (int)luaScript->getNumber( 1 ) );
						break;
					case LUA_TSTRING:
						Actions.params.Push( luaScript->getChar( 1 ) );
						break;
				}
			}
		}

		// Make a pause on false result;
		if( !update( frame ) )
			break;

	}

}
Exemplo n.º 13
0
/// <summary>
/// Defines movement processing for the enemy
/// </summary>
void Enemy::movement()
{
	// do not process movement if sleep is in action
	if (sleepTime < this->currentPath.sleepTime) return;

	// Start point of the path
	sf::Vector2f length;
	length.x = abs(this->currentPath.x - path.front().x);
	length.y = abs(this->currentPath.y - path.front().y);

	// End point of the path
	sf::Vector2f currentPosition;
	currentPosition.x = abs(this->currentPath.x - this->sprite->getPosition().x);
	currentPosition.y = abs(this->currentPath.y - this->sprite->getPosition().y);


	// The difference between the goto and current position
	float dx = this->path.front().x - this->currentPath.x;
	float dy = this->path.front().y - this->currentPath.y;
	float len = sqrtf(dx * dx + dy * dy);

	// Defines acceleration
	if (this->currentPath.acceleration != 0)
	{
		// Accelerate
		float accelerateTick = this->currentPath.acceleration * 0.18;
		if (this->acceleration + accelerateTick > 0) this->acceleration += this->currentPath.acceleration * 0.18;
		else this->acceleration = 0;
	}
	else
	{
		// Deaccelerate
		if (this->acceleration >= 1)
		{
			this->acceleration -= this->currentPath.acceleration * 0.18;
		}
	}


	dx = (dx / len) * timeStep.asSeconds() * (speed.x + acceleration);
	dy = (dy / len) * timeStep.asSeconds() * (speed.y + acceleration);

	// Check if the enemy has reached a path point or not ( move him if not)
	if (
		currentPosition.x < length.x ||
		currentPosition.y < length.y
		)
	{

		if (currentPosition.x < length.x)
		{
			this->sprite->move(dx, 0);
		}

		if (currentPosition.y < length.y)
		{
			this->sprite->move(0, dy);
		}

	}

	// ENemy has travelled the path, get a new one
	else
	{

		// Check if there is any other paths to go
		if (path.size() > 1)
		{
			currentPath = path.front();
			path.pop();

			// Reset the sleep time
			sleepTime = sf::milliseconds(0);
		}

		// If there is no paths to go.
		else
		{
			LOGD("Enemy#" << this << " delete flag set");
			setDeleted(true);

			// If the enemy has repeat option on, reinit it.
			if (this->getRepeat() == 1){
				setInitPath();
			}

		}

	}

}