void Charmander::fireAtEnemies()
{
    int enemyCount = 0;
	for( int i = 0; i < m_Level->getEnemies().size(); i++)
    {
        Enemy* enemy = m_Level->getEnemies().at(i);
        
        if(enemy != NULL && enemy->getIsActive() == true)
        {
            if(MathUtils::withinRange(enemy->getX(),getX(),450.0f) == true || MathUtils::withinRange(enemy->getY(),getY(),450.0f == true))
            {
                enemyCount++;
                Tile* targetTile = m_Level->getTileForPlayer(enemy);
                float centerX = targetTile->getX() + (targetTile->getWidth() / 2.0f);
                float centerY = targetTile->getY() + (targetTile->getHeight() / 2.0f);
                
                if(enemyCount == 1)
                {
                    if(enemy->getIsActive() == true && getIsActive() == true)
                    {
                        fireProjectile(centerX, centerY,"FireBall",500.0f,3);
                    }
                }
                else
                {
                    break;
                }
                
            }
        }
    }
}
void MultiFight3DWorld::update_world( ) {
    for( int i=0; i<perFrame; i++ ) {
//        phi += omega * dt;
//        rot.fromAngle( phi );

        auto itw = warriors.begin();
        while( itw != warriors.end() ) {
            Warrior3D * w = *itw;

            w->clean_temp( );
            //addEnviroForces              ( w->pos, w->vel, w->force,  w->landed );
            //w->landed = collideWithWorld ( w->pos, w->vel, w->surf );
            w->move( dt );

            //w->gun_rot.set_mul_cmplx( rot, w->rot );
            //w->update( dt );

            //printf( " warriro %i pos (%3.3f,%3.3f) vel (%3.3f,%3.3f) force (%3.3f,%3.3f) \n", itw, w->pos.x, w->pos.y, w->vel.x, w->vel.y, w->force.x, w->force.y );

            //printf( " trigger %i until_reaload %f \n ", w->trigger, w->until_reaload );
            if( w->trigger && ( w->until_reaload <= 0.0 ) ) {
                fireProjectile( w );
                w->until_reaload  = reload_time;
                printf( " fire !!! %i-th projectile % \n ", projectiles.size() );
            }
            w->until_reaload -= dt;

            ++itw;
        }

        auto it_proj = projectiles.begin();
        while( it_proj != projectiles.end() ) {
            Projectile3D * proj = *it_proj;

            //proj ->update_old_pos(    );
            //proj ->evalForce     (    );
            proj ->move          ( dt );

            bool hitted = false;
            //hitted |= proj->check_hit_ground( );
            //hitted |= proj->check_hit_vector<Frigate2D>( warriors );
            Vec3d normal;
            //hitted = collideWithWorld ( proj->pos, proj->vel, normal );
            for( o : objects ) {
                hitted = collideWithObject( o->lpos, objR, proj->pos, proj->vel, normal );
                if (hitted) break;
            }
            //if( hitted ){
            if( proj->time > projLifetime ) {
                it_proj = projectiles.erase( it_proj );
                delete proj;
            } else {
                ++it_proj;
            }
        }

    }
};
Esempio n. 3
0
void FlameTowerPhysicsComponent::fire() {

    emit fireProjectile(projType_, tower_->getPos(), projectilePath_.p2(),
            target_);
    fireCountdown_ = fireInterval_;
    foundTarget_ = false;
#ifndef SERVER
    ((TowerGraphicsComponent*) tower_->getGraphicsComponent())->setFiring(true);
#endif
}
Esempio n. 4
0
void Hero::keyUpEvent(int keyCode)
{
    if(keyCode == KEYCODE_SPACE)
    {
        Tile* targetTile = m_Level->getTileForIndex(m_Level->getSelectedTileIndex());
        float centerX = targetTile->getX() + (targetTile->getWidth() / 2.0f);
        float centerY = targetTile->getY() + (targetTile->getHeight() / 2.0f);
        
        fireProjectile(centerX, centerY);
    }
}
Esempio n. 5
0
void Player::processInput(Display* display) {
	
	toBoat(display);

	if(keyboard->getState(SDLK_x) && !left_projectile->isActive() && shipState) {
		fireProjectile();
	} 

	if(keyboard->getState(SDLK_UP)) { 
		direction = 0;
		if(!isCollision(display)) {
			y--;
		}
	}

	else if(keyboard->getState(SDLK_DOWN)) {
		direction = 2;
		if(!isCollision(display)) {
			y++;
		}
	}
	
	else if(keyboard->getState(SDLK_LEFT)) {
		direction = 3;
		if(!isCollision(display)) {
			x--;
		}
	}
	
	else if(keyboard->getState(SDLK_RIGHT)) {
		direction = 1;
		if(!isCollision(display)) {
			x++;
		}
	}
}
void gameClass::processInput(float deltaTime) // deltaTime = time between frames
{
	float velocity = player->getSpeed() * deltaTime; // adjust player velocity to compensate for fluctuations in frame rate in order to keep player movement smooth
	glm::vec2 oldPos = player->tile.getPos();
	glm::vec2 newPos = { 0.0f, 0.0f };
	int rotat = 0;
	int nrKeys = 0;	
	animationTime += deltaTime;

	if(!isPlayerDead)
	{
		if (keys[GLFW_KEY_UP]) {
			newPos ={newPos.x + 0, newPos.y + velocity*-1 };
			rotat += 90;
			nrKeys++;		
		}
	
		if (keys[GLFW_KEY_DOWN]) {		
			newPos = { newPos.x + 0, newPos.y + velocity*1 };
			rotat += 270;
			nrKeys++;		
		}

		if (keys[GLFW_KEY_RIGHT]) {
			newPos = { newPos.x + velocity, newPos.y + 0 };
			keys[GLFW_KEY_UP] ? rotat += 0 : rotat += 360;
			nrKeys++;
		}
		
		if (keys[GLFW_KEY_LEFT]) {
			newPos = { newPos.x + velocity * -1, newPos.y + 0 };
			rotat += 180;
			nrKeys++;		
		}

		if (nrKeys > 0) { // if an arrow key has been pressed;
		
			float oldRotation = player->tile.getRotation(); // get current rotation
			player->tile.setRotation(rotat / nrKeys); // determine new rotation based on which combination of arrow keys have been pressed

			if (oldRotation != player->tile.getRotation()){ // if rotation has changed
				player->resetIndex();						//reset the animation index and set animation action to walking
				player->setCurrentAction("walking");
				animationTime = 0.0f;
			
			}
			else if (animationTime >= Constants::animationFrameTime) {	// if rotation has not changed and if it is time for the next animation
				animationTime = 0.0f;
				player->increaseIndex();			
			}		
		}
		else if (player->getCurrentAction() == "attack" && (animationTime >= Constants::animationFrameTime)) {
			animationTime = 0.0f;
			player->increaseIndex();
		
		}

		player->tile.adjustPos(newPos);
		bool eraseFlag = false;

		if (checkCollision(player, eraseFlag))
			player->tile.resetPos(oldPos);
		else {// if player does not collide with anything, adjust camera position
			if (player->tile.getPos().x >= Constants::windowWidth / 2 - player->tile.getSize().x / 2 
				&& player->tile.getPos().x <= Constants::mapWidth - Constants::windowWidth / 2 - player->tile.getSize().x / 2) 
			{				
				renderer->setCam(newPos.x * -1.0f, 0.0f);
			}

			if (player->tile.getPos().y >= Constants::windowHeight / 2 - player->tile.getSize().y / 2
				&& player->tile.getPos().y <= Constants::mapHeight - Constants::windowHeight / 2 - player->tile.getSize().y / 2)
			{
				renderer->setCam(0.0f, newPos.y * -1.0f);
			}
		}	

		if (keys[GLFW_KEY_SPACE] && !keysPressed[GLFW_KEY_SPACE]) {		
				
			setKeysPressed(GLFW_KEY_SPACE, true);

			if (projectileTimer > Constants::fireRate) {
				fireProjectile();
				if (player->getCurrentAction() != "attack") { // if attack animation is not playing allready
					player->setCurrentAction("attack");
					player->resetIndex();
					animationTime = 0.0f;
				}
				projectileTimer = 0;

			}
		}			
	}	
}
Esempio n. 7
0
void Tower::update(double delta)
{
	// Increment the shooting timer
	m_ShootingTimer += delta;

	Player::update(delta);

	if(m_Level != NULL)
	{
		if(m_Target != NULL && m_Target->getIsActive())
		{
			// Shoot a projectile if enough time has passed
			if(m_ShootingTimer >= m_Speed)
			{
				Tile* targetTile = m_Level->getTileForIndex( m_Level->getTileIndexForPlayer(m_Target) );

				float centerX = targetTile->getX() + (targetTile->getWidth() / 2.0f);
				float centerY = targetTile->getY() + (targetTile->getHeight() / 2.0f);

				// Fire the projectile
				fireProjectile(centerX, centerY);

				// Reset the shooting timer
				m_ShootingTimer = 0.0;
			}

			// Rotate the tower to follow enemies
			float angle = atan2(getY() - m_Target->getY(), getX() - m_Target->getX());
			m_Angle = angle * 180 / 3.141592;

			// Check to see if the target is still within range
			checkTargetRange(m_Target);
		}
		else
		{
			// Find a targe twithin range
			findTarget();
		}

		// Set the tile's walkable state (the tower's tile location)
		Tile* tile = m_Level->getTileForIndex(m_Level->getTileIndexForPosition(getX(), getY()));

		if(tile != NULL && tile->isWalkableTile())
		{
			tile->setHasTower(true);

			// Go through all the active enemies
			for(int i = 0; i < m_Level->m_Enemies.size(); i++)
			{
				Enemy* enemy = m_Level->m_Enemies.at(i);

				if(enemy != NULL && enemy->getIsActive())
				{
					if(m_Level->getTileForChest() != NULL)
					{
						// Update their pathfinding
						enemy->setDestinationTile(m_Level->getTileForChest());
					}
				}
			}
		}
	}
}