Example #1
0
	void SpaceShip::update(unsigned long elapsed_millis) {
		PhysicsObject::update(elapsed_millis);
		double elapsed_seconds = elapsed_millis / 1000.0;	
		//accelerate(-50*elapsed_seconds, false, cg::Vector2d(0, 0));
		_hyperAccelerator->update(elapsed_seconds);
		cg::Vector2d position = getPosition();
		_charlesBronsonKilledSecondsAgo = _charlesBronsonKilledSecondsAgo + elapsed_seconds;
		if (_charlesBronsonKilledSecondsAgo >= 1) {
			if (_charlesBronsonStyle >= _maxCharlesBronsonStyle){
				_charlesBronsonKilledSecondsAgo--;
				return;
			}else {
				_charlesBronsonStyle++;
				_charlesBronsonKilledSecondsAgo--;
			}
		}
		
		if(_invulTime > 0) {
			if((_invulTime - elapsed_millis/1000.0)< 0) {
				_invulTime = 0;
				setCollisionRadius(_size[1]/2);
			} else {
				_invulTime-= elapsed_millis/1000.0;
				setCollisionRadius(_size[1]*1.1);
			}
		}		
	}
Example #2
0
ElectricExplosionEffect::ElectricExplosionEffect()
: SpaceObject(1000.0, "ElectricExplosionEffect")
{
    setCollisionRadius(1.0);
    lifetime = maxLifetime;
    for(int n=0; n<particleCount; n++)
        particleDirections[n] = sf::normalize(sf::Vector3f(random(-1, 1), random(-1, 1), random(-1, 1))) * random(0.8, 1.2);
    
    registerMemberReplication(&size);
}
Example #3
0
void BreEnemy::setDifficulty(int difficulty)
{
    this->difficulty = difficulty;
    if (difficulty > 1)
        textureManager.setTexture(sprite, "bre1_v2");
    if (difficulty > 2)
    {
        shieldStrength = maxShieldStrength;
        setCollisionRadius(65);
    }
}
Example #4
0
Nebula::Nebula()
: SpaceObject(5000, "Nebula")
{
    setCollisionRadius(1);  //Nebula need a big radius to render properly from a distance. But they do not really need collision. So set the collision radius to a tiny range.
    setRotation(random(0, 360));
    radar_visual = irandom(1, 3);
    
    registerMemberReplication(&radar_visual);
    
    for(int n=0; n<cloud_count; n++)
    {
        clouds[n].size = random(1024, 1024 * 4);
        clouds[n].texture = irandom(1, 3);
        clouds[n].offset = sf::vector2FromAngle(float(n * 360 / cloud_count)) * random(clouds[n].size / 2.0f, getRadius() - clouds[n].size);
    }
    
    nebula_list.push_back(this);
}
Example #5
0
	void SpaceShip::init() {
		// Read from property file
		_radarSize = cg::Properties::instance()->getDouble("RADAR_SIZE");
		_radarAdvanced = cg::Properties::instance()->getInt("RADAR_ADVANCED");
		
		_invulTimeMax = cg::Properties::instance()->getDouble("SHIP_RESPAWN_INVUL");
		_invulTime = _invulTimeMax;

		_size = cg::Vector2d(
								cg::Properties::instance()->getDouble("SHIP_LENGTH"),
								cg::Properties::instance()->getDouble("SHIP_HEIGHT")
							);

		cg::tWindow win = cg::Manager::instance()->getApp()->getWindow();
		setUniverseDimensions(win.width,win.height);
		setCollisionRadius(_size[1]/2);
		setVelocity(cg::Vector2d(0, 0));
		setPosition(cg::Vector2d(win.width/2, win.height/2));
		setCollisionCenter(getPosition());
		_maxCharlesBronsonStyle = cg::Properties::instance()->getDouble("SHIP_SHOTS");
		_charlesBronsonStyle = _maxCharlesBronsonStyle;
		_charlesBronsonKilledSecondsAgo = 0;
		
	}
Example #6
0
void BreEnemy::update(float delta)
{
    if (invulnerability > 0)
        invulnerability -= delta;
    switch(state)
    {
    case BS_FlyIn:
        if (sprite.getPosition().y < 80.0)
        {
            sprite.setPosition(sprite.getPosition() + sf::Vector2f(0, moveSpeed * delta));
        }else
        {
            new BreEnemyHud(this);
            state = BS_MoveLeftRight;
            moveDir = random(0, 100) < 50 ? 1 : -1;
        }
        break;
    case BS_MoveLeftRight:
        sprite.setPosition(sprite.getPosition() + sf::Vector2f(moveDir * moveSpeed * delta, 0));
        if (sprite.getPosition().x < 40.0)
            moveDir = 1;
        if (sprite.getPosition().x > 280.0)
            moveDir = -1;

        if (shotDelay > 0)
        {
            shotDelay -= delta;
            if (difficulty > 1)
                shotDelay -= delta * 0.1;
        }else{
            if (random(0, 100) < 30)
            {
                if (random(0, 100) < 50)
                {
                    state = BS_LaserCharge;
                    shotDelay = laserChargeTime;
                }else{
                    state = BS_MouthOpen;
                    enemySpawnCount = 3 + 2 * difficulty;
                }
            }else{
                for(int n=-2; n<=2; n++)
                    new Bullet(sprite.getPosition() + sf::Vector2f(-n*15, -50), 0, 180 + n * 7, 90.0);
                shotDelay = normalShotDelay;
            }
        }
        break;
    case BS_LaserCharge:
        if (shotDelay > 0)
        {
            shotDelay -= delta;
            if (difficulty > 1)
                shotDelay -= delta * 0.3;
        }else{
            state = BS_LaserFire;
            laser[0] = new BreLaser(this);
            laser[1] = new BreLaser(this);
            shotDelay = 0.5;
        }
        break;
    case BS_LaserFire:
        if (shotDelay > -0.5) //Why -0.5?
        {
            shotDelay -= delta;
        }
        else
        {
            shotDelay = normalShotDelay;
            state = BS_MoveLeftRight;
            laser[0]->destroy();
            laser[1]->destroy();
        }
        break;
    case BS_MouthOpen:
        if (mouthPos < 30)
        {
            mouthPos += delta * 40;
            if (difficulty > 1)
                mouthPos += delta * 5;
            shotDelay = 0.2;
        }else if (shotDelay > 0)
        {
            shotDelay -= delta;
            if (difficulty > 1)
                shotDelay -= delta * 0.3;
        }else{
            shotDelay += 0.2;
            if (enemySpawnCount > 0)
            {
                BasicEnemyBase* e = new BasicEnemy();
                e->setTargetPosition(sf::Vector2f(random(20, 300), random(20, 200)));
                e->wait(sprite.getPosition() + sf::Vector2f(0, 50), sprite.getPosition() + sf::Vector2f(0, 100));
                e->flyIn();
                if (enemySpawnCount % 5 == 0)
                    e->giveShield();
                enemyList.push_back(e);
                enemySpawnCount --;
            }else{
                state = BS_MouthClose;
            }
        }
        break;
    case BS_MouthClose:
        if (mouthPos > 0)
        {
            mouthPos -= delta * 40;
        }
        else
        {
            mouthPos = 0;
            shotDelay = normalShotDelay;
            state = BS_MoveLeftRight;
        }
        break;
    }
    if (laser[0])
    {
        laser[0]->setPosition(getPosition() + sf::Vector2f(18, 7));
        laser[0]->setRotation(-shotDelay*30.0f);
    }
    if (laser[1])
    {
        laser[1]->setPosition(getPosition() + sf::Vector2f(-18, 7));
        laser[1]->setRotation(shotDelay*30.0f);
    }
    if (difficulty > 2 && shieldStrength < maxShieldStrength)
    {
        shieldCharge += delta;
        if (shieldCharge >= shieldChargeTime)
        {
            shieldCharge -= shieldChargeTime;
            if (shieldStrength == 0)
                setCollisionRadius(65);
            shieldStrength ++;
        }
    }
    
    mouth.setPosition(sprite.getPosition() + sf::Vector2f(0, mouthPos));
    shield.setPosition(sprite.getPosition());
    setPosition(sprite.getPosition()); // Set position for collision
    foreach(BasicEnemyBase, e, enemyList)
    {
        if (e->state == ES_CenterField)
            e->dive(sf::Vector2f(random(20, 300), 340));
        if (e->state == ES_Outside)
        {
            e->wait(sf::Vector2f(random(20, 300), -40), sprite.getPosition() + sf::Vector2f(0, 100));
            e->flyIn();
        }
    }
}
Example #7
0
bool BreEnemy::takeDamage(sf::Vector2f position, int damageType, int damageAmount)
{
    if (damageType >= 0)
        return false;
    if (invulnerability > 0)
        return true;

    if (state != BS_FlyIn)
    {
        if (shieldStrength > 0)
        {
            shieldStrength -= damageAmount;
            damageAmount = 0;
            if (shieldStrength <= 0)
            {
                setCollisionRadius(50);
                damageAmount = -shieldStrength;
                shieldStrength = 0;
            }
        }
        shieldCharge = 0.0;
        health -= damageAmount;
    }
    if (health < maxHealth / 2 && !moneyshieldDeployed)
    {
        moneyshieldDeployed = true;
        P<Transmission> t = new Transmission();
        t->setText("Deploying corperate|money shield");
        t->top();
        
        if (difficulty < 2)
        {
            for(float f=0; f<=360; f+=20)
            {
                new MoneyShield(this, f, 100, false);
                new MoneyShield(this, f, 80, true);
            }
        }else{
            for(float f=0; f<=360; f+=20)
            {
                new MoneyShield(this, f, 110, false);
                new MoneyShield(this, f, 90, true);
                new MoneyShield(this, f, 70, false);
            }
        }
    }

    if (health <= 0)
    {
        health = 0;
        destroy();
        destroyed();
        for(unsigned int n=0; n<4; n++)
        {
            new BreDeath(getPosition(), n);
        }
        foreach(BasicEnemyBase, e, enemyList)
            e->destroy();
        P<ScoreManager>(engine->getObject("score"))->add(500);
        if (difficulty > 1)
            P<ScoreManager>(engine->getObject("score"))->add(200);
        for(unsigned int n=0; n<30; n++)
            new Explosion(sprite.getPosition() + sf::Vector2f(random(-60, 60), random(-80, 80)), 15);
    }
    invulnerability = 0.10;
    return true;
}