Exemplo n.º 1
0
void keyPressed (unsigned char key, int x, int y) {
    switch (key) {
    case 'f':
        fireWeapon();
        break;
    }
}
Exemplo n.º 2
0
	// Disparo, usa el patrón template
	void CShootRaycast::primaryShoot() {
		if(_primaryCanShoot && _currentAmmo > 0){
			_primaryCanShoot = false;
			_primaryCooldownTimer = 0;
				
			drawParticle("shootParticle");

			decrementAmmo();

			for(int i = 0; i < _numberShots; ++i) {
				CEntity* entityHit = fireWeapon();

				if(entityHit != NULL) {
					triggerHitMessages(entityHit);
				}
			}
			//Sonido de disparo
			emitSound(_audioShoot, "audioShoot");

			//Mensaje de dispersion en mira
			/*std::shared_ptr<CMessageHudDispersion> dispersionMsg = std::make_shared<CMessageHudDispersion>();
			_entity->emitMessage(dispersionMsg);*/
		}
		else if(_currentAmmo == 0) {
			// Ejecutar sonidos y animaciones de falta de balas
			emitSound(_noAmmo, "noAmmo", true);
		}
	}// shoot
Exemplo n.º 3
0
void Turret_t::FinishMove( void ) {

	if ( shoot.check() ) {
		fireWeapon();
	}

	M_ClampAngle360( &angle );

	facingLast = facing = DirFromAngle();
}
Exemplo n.º 4
0
void Racer::fireRocket()
{
	Sound::sound->playSoundEffect(SFX_ROCKETLAUNCH, emitter);

	hkpWorldRayCastInput input;
	hkpWorldRayCastOutput output = hkpWorldRayCastOutput();
	hkVector4 from;

	hkTransform trans = body->getTransform();
	from.setTransformedPos(trans, attachGun);

	input = fireWeapon();

	hkVector4 to = input.m_to;

	to.sub(from);

	to.normalize3();
	// Change this so rocket is facing rocketDir when launched
					
	
	Rocket* currentRocket = new Rocket(Renderer::device, this);
					
	currentRocket->owner = this;

	hkVector4 rocketPos;
	hkTransform bodyTransform;
	bodyTransform.set4x4ColumnMajor((const hkFloat32*) gunDraw->getTransform());

	hkVector4 rocketAttach;
	rocketAttach.setXYZ(Racer::attachGun);

	rocketPos.setTransformedPos(bodyTransform, rocketAttach);


	currentRocket->body->setTransform(bodyTransform);
	currentRocket->body->setPosition(rocketPos);

	to.mul(125.0f);
	currentRocket->body->setLinearVelocity(to);
	currentRocket->update(0.0f);

	DynamicObjManager::manager->addObject(currentRocket);
	currentRocket = NULL;
}
Exemplo n.º 5
0
void Racer::fireLaser()
{
	laserTime = 1.0f;

	Sound::sound->playSoundEffect(SFX_LASER, emitter);

	hkpWorldRayCastInput input;
	hkpWorldRayCastOutput output = hkpWorldRayCastOutput();
	hkVector4 from;

	input = fireWeapon();

	hkVector4 toPoint;
	toPoint.setXYZ(input.m_to);
	toPoint.sub(input.m_from);
	toPoint.mul(0.90f);
	toPoint.add(input.m_from);
	LaserSystem::system->addLaser(&(input.m_from), &(toPoint));

	// Check if anything was hit
	if (input.m_userData == -1)
		return;

	Physics::world->castRay(input, output);

	if (output.hasHit())
	{
		hkpRigidBody* hitBody = (hkpRigidBody*) output.m_rootCollidable->getOwner();

		Racer* attacked = (Racer*) (hitBody->getProperty(0)).getPtr();

		if ((attacked != NULL) && (attacked != this))
		{
			attacked->applyDamage(this, LASER_DAMAGE);
		}
		else if ((hitBody->getProperty(1)).getPtr())
		{
			Landmine* mine = ((Landmine*)(hitBody->getProperty(1)).getPtr());
			mine->owner = this;

			if (!mine->triggered && !mine->destroyed)
				mine->trigger();
		}
	}
}
Exemplo n.º 6
0
void Unit::update(float dt)
{	
	m_weaponUpgradeUI.setPosition(m_position);
	m_weaponUpgradeUI.update(dt);
	m_weaponUpgradeUI.setCurrentWeapon(& m_currentWeapon);
	m_weaponUpgradeUI.setRank(m_rank);
	m_light->setPosition(m_position);
	m_xpBar.update();
	m_xpBar.setPosition(m_position + Vector2D(-20, 20));
	m_anim.update(dt);
	m_anim.setRotation((m_directionAngle - (PI )) * 180 / PI);
	m_anim.setPosition(m_position);
	rankImg.setPosition(Vector2D(m_position + Vector2D(-m_radius + 30, 20)).toSFMLVector());
	m_selectAnimation.update(dt);
	m_selectAnimation.setPosition(m_position);
	//if given a move order
	if (m_state == UNIT_STATE::MOVING)
	{
		//find direction to target
		int direction = getDirectionToTarget();

		//increment angle
		updateAngle(m_positionAngle + dt * m_speed * direction);

		m_directionAngle = m_positionAngle + PI / 2 * direction;
		

		//check if unit is at destination
		if (fabs(m_positionAngle - m_targetAngle) <= fabs(m_speed * dt))
		{
			//set state to waiting
			m_state = UNIT_STATE::WAITING;
		}
	}
	else if (m_state == UNIT_STATE::WAITING)
	{ 
		

	}
	else if (m_state == UNIT_STATE::FIRING)
	{
		fireWeapon();
	}

	if (isPlayer())
	{
		if (m_state == UNIT_STATE::MOVING)
		{
			if (SceneManager::getInstance()->playerColorIndex == 0)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("red");
				m_anim.SetLooping(true);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 1)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("walingAssaltAnimation");
				m_anim.SetLooping(true);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 2)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("yellow");
				m_anim.SetLooping(true);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 3)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("white");
				m_anim.SetLooping(true);
			}
		}
		else if (m_state == UNIT_STATE::WAITING)
		{
			if (SceneManager::getInstance()->playerColorIndex == 0)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("red");
				m_anim.SetLooping(false);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 1)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("walingAssaltAnimation");
				m_anim.SetLooping(false);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 2)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("yellow");
				m_anim.SetLooping(false);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 3)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("white");
				m_anim.SetLooping(false);
			}

		}
		else if (m_state == UNIT_STATE::FIRING)
		{
			if (SceneManager::getInstance()->playerColorIndex == 0)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("red");
				m_anim.SetLooping(true);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 1)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("walingAssaltAnimation");
				m_anim.SetLooping(true);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 2)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("yellow");
				m_anim.SetLooping(true);
			}
			else if (SceneManager::getInstance()->playerColorIndex == 3)
			{
				m_anim.setFramesPerSecond(30);
				m_anim.changeAnimation("white");
				m_anim.SetLooping(true);
			}
		}
	}
	else
	{
		if (m_state == UNIT_STATE::MOVING)
		{
			switch (m_unitType)
			{
			case UNIT_TYPE::ASSAULT:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("scoutWalking");
				m_anim.SetLooping(true);
				break;
			case UNIT_TYPE::CQB:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("tankWalking");
				m_anim.SetLooping(true);
				break;
			case UNIT_TYPE::SNIPER:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("sniperWalking");
				m_anim.SetLooping(true);
				break;
			}
			
		}
		else if (m_state == UNIT_STATE::WAITING)
		{
			switch (m_unitType)
			{
			case UNIT_TYPE::ASSAULT:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("scoutWalking");
				m_anim.SetLooping(true);
				break;
			case UNIT_TYPE::CQB:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("tankWalking");
				m_anim.SetLooping(true);
				break;
			case UNIT_TYPE::SNIPER:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("sniperWalking");
				m_anim.setPosition(m_position + Vector2D(10, 0));
				m_anim.SetLooping(true);
				break;
			}

		}
		else if (m_state == UNIT_STATE::FIRING)
		{
			switch (m_unitType)
			{
			case UNIT_TYPE::ASSAULT:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("scoutShooting");
				m_anim.SetLooping(true);
				break;
			case UNIT_TYPE::CQB:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("tankShooting");
				m_anim.SetLooping(true);
				break;
			case UNIT_TYPE::SNIPER:
				m_anim.setFramesPerSecond(120);
				m_anim.changeAnimation("sniperShooting");
				m_anim.SetLooping(true);
				break;
			}
		}
	}

	m_currentWeapon.update(getPositionByAngle(m_positionAngle), m_directionAngle, dt);

	if (m_isSelected)
	{
		m_selectAnimation.SetLooping(true);
		m_selectAnimation.setDoOnce(true);
	}
	else
	{
		m_selectAnimation.SetLooping(false);
		m_selectAnimation.reset();
	}

	if (m_experience > 600)
	{
		m_xpBar.setFGColor(sf::Color(60, 179, 113, 255));
	}
	
    if (m_rank == UNIT_RANK::A)
	{

	}
	else if (m_rank == UNIT_RANK::B)
	{
		rankImg.setTexture(AssetLoader::getInstance()->findTextureByKey("RankB"));
	}
	else if (m_rank == UNIT_RANK::C)
	{
		rankImg.setTexture(AssetLoader::getInstance()->findTextureByKey("RankC"));
	}
	else if (m_rank == UNIT_RANK::D)
	{
		rankImg.setTexture(AssetLoader::getInstance()->findTextureByKey("RankD"));
	}
	else if (m_rank == UNIT_RANK::E)
	{
		rankImg.setTexture(AssetLoader::getInstance()->findTextureByKey("RankE"));
	}
	else if (m_rank == UNIT_RANK::F)
	{
		rankImg.setTexture(AssetLoader::getInstance()->findTextureByKey("RankF"));
	}
	else if (m_rank == UNIT_RANK::G)
	{
		rankImg.setTexture(AssetLoader::getInstance()->findTextureByKey("RankG"));
	}
}
Exemplo n.º 7
0
void Hero::update()
{
	if (mySpawnPortal)
	{
		mySpawnPortalFrameCounter++;
		if (mySpawnPortalFrameCounter == 1)
		{
			Portal* portal = new Portal();
			portal->setPosition(getPosition());
			getRoom()->addEntity(portal);
			return;
		}
		else if (mySpawnPortalFrameCounter >= 60 * 5)
		{
			mySpawnPortal = false;
		}
		else 
		{
			return;
		}
	}

	if (myIsDead)
		return;

	Entity::update();
	mFramesSinceLandPlayed++;

	if (mGravityHitTimer <= 0){
		mGravityDirection=1;
	} else {
		mGravityHitTimer--;
	}

	if (touchesDangerousTile())
	{
		die();
	}
	//checkEnemies();

	if (mSpawnPoint.x < -100 && mSpawnPoint.y < -100)
	{
		mSpawnPoint = getPosition();
	}

	float acceleration = mOnGround ? GROUND_ACCELERATION : AIR_ACCELERATION;
	
	if (Input::isHeld(Button_Left)) {
		mVelocity.x -= acceleration;
		mFacingDirection = Direction_Left;
	}

	if (Input::isHeld(Button_Right)) {
		mVelocity.x += acceleration;
		mFacingDirection = Direction_Right;
	}

	if(Input::isPressed(Button_Fire) && GameState::getInt(GameState::POWERUP_GRENADE) != 0){
		mWeaponSelected = Weapon_Gravity_Grenade;
		fireWeapon();
	}

	if(Input::isPressed(Button_ToggleWeapon) && GameState::getInt(GameState::POWERUP_GUN) != 0){
		mWeaponSelected = Weapon_Gun;
		fireWeapon();
	}

	mVelocity.x = clamp(mVelocity.x, -MAX_X_VELOCITY, MAX_X_VELOCITY);
	
	if (Input::isPressed(Button_Jump)) {
		mJumpPrepressed = true;
	}

	if (mOnGround && mJumpPrepressed) {
		Sound::playSample("data/sounds/jump.wav");
		mVelocity.y = GameState::getInt(GameState::POWERUP_HIJUMP) ? -HI_JUMP_VELOCITY : -JUMP_VELOCITY;
		mJumpHeld = true;
		mJumpPrepressed = false;
	}

	if (Input::isReleased(Button_Jump)) {
		if (mJumpHeld && mVelocity.y < 0) {
			mVelocity.y *= 0.5f;
		}

		mJumpHeld = false;
		mJumpPrepressed = false;
	}

	if (mVelocity.y >= 0) {
		mJumpHeld = false;
	}

	mMovementState = MovementState_Still;
	
	if (mOnGround) {
		if (abs(mVelocity.x) > GROUND_STOP_VELOCITY)
		{
			mMovementState = MovementState_Run;
		}
	}
	else
	{
		if (mVelocity.y < 0) {
			mMovementState = MovementState_Jump;
		} else {
			mMovementState = MovementState_Fall;
		}
	}
	
	if (mMovementState == MovementState_Still)
	{
		mVelocity.x = 0;
	}

	bool ground = moveOutOfSolidEntities();

	float2 usedVelocity(mVelocity.x, clamp(mVelocity.y, -MAX_Y_VELOCITY, MAX_Y_VELOCITY));
	unsigned int bumps = moveWithCollision(usedVelocity / Time::TicksPerSecond);
	
	if ((bumps & (Direction_Left | Direction_Right)) != 0) {
		mVelocity.x = 0;
	}

	if ((bumps & (Direction_Up | Direction_Down)) != 0) {
		mVelocity.y = 0;
	}

	float gravity = mJumpHeld ? JUMP_GRAVITY : GRAVITY;
	mVelocity.y += gravity * getGravityDirection();
	ground |= ((bumps & Direction_Down) != 0);
	if (ground && !mOnGround)
	{
		if (mFramesSinceLandPlayed > 6)
		{
			Sound::playSample("data/sounds/land.wav");
		}
		mFramesSinceLandPlayed = 0;
	}
	mOnGround = ground;

	float drag = mOnGround ? GROUND_DRAG : AIR_DRAG;
	mVelocity *= drag;

	mFrame ++;
	if (mBlinkingTicksLeft)
	{
		mBlinkingTicksLeft --;
	}
}
Exemplo n.º 8
0
void gameLoop(){
	while(1) {
		secsElapsed = (float)(clock() - startTime)/CLOCKS_PER_SEC;
		moveProjectiles();
		updateViewportWin();
		if((float)(clock() - timerStart)/CLOCKS_PER_SEC > 1){
			tryRandomEvent();
			timerStart=clock();
		}
		if((int)secsElapsed%10){
			zombieModifier++;
		}
		moveZombies();
		updateViewportWin();
		updateInfoWin();
		doupdate();
		int ch;
		ch = getch();
		switch(ch){
			case 'w':
			case 'W':{
				struct CollisionEvent collisionEvent = collisionDetect(allEntities[0].curYpos-1,allEntities[0].curXpos);
				if(!collisionEvent.collidedWithUnPassableChar && !collisionEvent.collidedWithBoundary){
					allEntities[0].prevXpos=allEntities[0].curXpos;
					allEntities[0].prevYpos=allEntities[0].curYpos;
					allEntities[0].curYpos--;
				};
				break;
			}
			case 's':	
			case 'S':{
				struct CollisionEvent collisionEvent = collisionDetect(allEntities[0].curYpos+1,allEntities[0].curXpos);
				if(!collisionEvent.collidedWithUnPassableChar && !collisionEvent.collidedWithBoundary){
					allEntities[0].prevXpos=allEntities[0].curXpos;
					allEntities[0].prevYpos=allEntities[0].curYpos;
					allEntities[0].curYpos++;
				};
				break;
			}
			case 'a':
			case 'A':{
				struct CollisionEvent collisionEvent = collisionDetect(allEntities[0].curYpos,allEntities[0].curXpos-1);
				if(!collisionEvent.collidedWithUnPassableChar && !collisionEvent.collidedWithBoundary){
					allEntities[0].prevYpos=allEntities[0].curYpos;
					allEntities[0].prevXpos=allEntities[0].curXpos;
					allEntities[0].curXpos--;
				};
				break;
			}
			case 'd':
			case 'D':{
				struct CollisionEvent collisionEvent = collisionDetect(allEntities[0].curYpos,allEntities[0].curXpos+1);
				if(!collisionEvent.collidedWithUnPassableChar && !collisionEvent.collidedWithBoundary){
					allEntities[0].prevYpos=allEntities[0].curYpos;
					allEntities[0].prevXpos=allEntities[0].curXpos;
					allEntities[0].curXpos++;
				};
				break;
			}
			case KEY_UP:{
				if(allEntities[0].weapons[allEntities[0].curWeapon].curCapacity>0 || allEntities[0].curWeapon == 0){
					fireWeapon(&allEntities[0].weapons[allEntities[0].curWeapon], "up");
				}
				break;
			}
			case KEY_LEFT:{
				if(allEntities[0].weapons[allEntities[0].curWeapon].curCapacity>0 || allEntities[0].curWeapon == 0){
					fireWeapon(&allEntities[0].weapons[allEntities[0].curWeapon], "left");
				}
				break;
			}
			case KEY_DOWN:{
				if(allEntities[0].weapons[allEntities[0].curWeapon].curCapacity>0 || allEntities[0].curWeapon == 0){
					fireWeapon(&allEntities[0].weapons[allEntities[0].curWeapon], "down");
				}
				break;
			}
			case KEY_RIGHT:{
				if(allEntities[0].weapons[allEntities[0].curWeapon].curCapacity>0 || allEntities[0].curWeapon == 0){
					fireWeapon(&allEntities[0].weapons[allEntities[0].curWeapon], "right");
				}
				break;
			}
			case 'r':
			case 'R':{
				if(allEntities[0].weapons[allEntities[0].curWeapon].curMags > 0 && allEntities[0].weapons[allEntities[0].curWeapon].curCapacity < allEntities[0].weapons[allEntities[0].curWeapon].maxCapacity ){
					reload(&allEntities[0].weapons[allEntities[0].curWeapon]);
				}
				break;
			}
			case '0':{
				allEntities[0].curWeapon=0;
				break;
			}
			case '1':{
				if(allEntities[0].weapons[1].isAlive){
					allEntities[0].curWeapon=1;
				}
				break;
			}
			case '2':{
				if(allEntities[0].weapons[2].isAlive){
					allEntities[0].curWeapon=2;
				}
				break;
			}
			case '3':{
				if(allEntities[0].weapons[3].isAlive){
					allEntities[0].curWeapon=3;
				}
				break;
			}
			case '4':{
				if(allEntities[0].weapons[4].isAlive){
					allEntities[0].curWeapon=4;
				}
				break;
			}
			default:
				allEntities[0].prevYpos=allEntities[0].curYpos;
				allEntities[0].prevXpos=allEntities[0].curXpos;
				break;
		}
		if(allEntities[0].weapons[allEntities[0].curWeapon].curCapacity==0 && allEntities[0].weapons[allEntities[0].curWeapon].curMags==0){
			allEntities[0].curWeapon=0;
		}
		updateViewportWin();
		checkPlayerCollision();
		updateViewportWin();
	}
}
Exemplo n.º 9
0
void updateGame(cbgame * game) {
    
    oofloat player1Speed = game->input->dt * 100.f;
    oofloat player2Speed = game->input->dt * 100.f;
    oofloat timeThreshold = game->input->dt * 10.f;
    
    ooint p1Direction = game->p1.direction;
    ooint p2Direction = game->p2.direction;
    //Get the direction
    if(game->time > game->p1.timeOfLastKeyPressed + timeThreshold && game->p1.alive)
    {
        if( game->input->keyboard['D'] || game->input->keyboard['d'] ) {
            
            p1Direction++;
            game->p1.timeOfLastKeyPressed = game->time;
        }
        if( game->input->keyboard['A'] || game->input->keyboard['a'] ) {
            
            p1Direction--;
            game->p1.timeOfLastKeyPressed = game->time;
        }
        if(game->input->keyboard['F'] || game->input->keyboard['f'])
        {
            player1Speed *=3;
        }
        else if(game->input->keyboard['G'] || game->input->keyboard['g'])
        {
            if(!game->p1.missile.isFiring)
            {
                fireWeapon(game,&game->p1);
            }
        }
    }
    if(game->time > game->p2.timeOfLastKeyPressed + timeThreshold && game->p2.alive)
    {
        if( game->input->keyboard['L'] || game->input->keyboard['l'] ) {
            
            p2Direction++;
            game->p2.timeOfLastKeyPressed = game->time;
        }
        if( game->input->keyboard['J'] || game->input->keyboard['j'] ) {
            
            p2Direction--;
            game->p2.timeOfLastKeyPressed = game->time;
        }
        if(game->input->keyboard['P'] || game->input->keyboard['p'])
        {
            player2Speed *=3;
        }
        else if(game->input->keyboard['['] || game->input->keyboard['{'])
        {
            if(!game->p2.missile.isFiring)
            {
                fireWeapon(game,&game->p2);
            }
        }
        
    }
    
    
    //Move based on direction.
    if(p1Direction<0)
    {
        p1Direction = PlayerDirection_NorthWest;
    }
    if(p1Direction >PlayerDirection_NorthWest)
    {
        p1Direction = 0;
    }
    if(p2Direction <0)
    {
        p2Direction = PlayerDirection_NorthWest;
    }
    if(p2Direction > PlayerDirection_NorthWest)
    {
        p2Direction = 0;
    }
    
    game->p1.direction = p1Direction;
    game->p2.direction = p2Direction;
    
    oofloat diagDiff = 0.75f;
    
    if((game->input->keyboard['W'] || game->input->keyboard['w']) && game->p1.alive)//Forwards
    {
        switch (game->p1.direction) {
            case PlayerDirection_North:
                if(playerInBounds(game, -1,game->p1.y - player1Speed,game->p1.playerIndex))
                {
                    game->p1.y -= player1Speed;
                }
                break;
            case PlayerDirection_NorthEast:
                if(playerInBounds(game, game->p1.x + _playerWidth+player1Speed,game->p1.y - player1Speed,game->p1.playerIndex))
                {
                    game->p1.y -= player1Speed * diagDiff;
                    game->p1.x += player1Speed * diagDiff;
                    
                }
                break;
            case PlayerDirection_East:
                if(playerInBounds(game,game->p1.x + _playerWidth + player1Speed,-1,game->p1.playerIndex)) //Right
                {
                    game->p1.x += player1Speed;
                }
                break;
            case PlayerDirection_SouthEast:
                if(playerInBounds(game, game->p1.x+_playerWidth+player1Speed, game->p1.y + _playerHeight + player1Speed,game->p1.playerIndex))
                {
                    game->p1.x += player1Speed * diagDiff;
                    game->p1.y += player1Speed * diagDiff;
                }
                break;
            case PlayerDirection_South:
                if(playerInBounds(game, -1, game->p1.y + _playerHeight + player1Speed,game->p1.playerIndex))
                {
                    game->p1.y += player1Speed;
                }
                break;
            case PlayerDirection_SouthWest:
                if(playerInBounds(game, game->p1.x - player1Speed, game->p1.y + _playerHeight + player1Speed,game->p1.playerIndex))
                {
                    game->p1.y += player1Speed * diagDiff;
                    game->p1.x -= player1Speed * diagDiff;
                }
                break;
            case PlayerDirection_West:
                if(playerInBounds(game, game->p1.x - player1Speed, -1,game->p1.playerIndex))
                {
                    game->p1.x -= player1Speed;
                }
                break;
            case PlayerDirection_NorthWest:
                if(playerInBounds(game, game->p1.x - player1Speed, game->p1.y - player1Speed,game->p1.playerIndex))
                {
                    game->p1.x -= player1Speed * diagDiff;
                    game->p1.y -= player1Speed * diagDiff;
                }
                break;
                
            default:
                break;
        }
    }
    
    if((game->input->keyboard['S'] || game->input->keyboard['s']) && game->p1.alive)//Backwards
    {
        switch (game->p1.direction) {
            case PlayerDirection_North:
                if(playerInBounds(game, -1,game->p1.y + player1Speed,game->p1.playerIndex))
                {
                    game->p1.y += player1Speed;
                }
                break;
            case PlayerDirection_NorthEast:
                if(playerInBounds(game, game->p1.x - _playerWidth-player1Speed,game->p1.y + player1Speed,game->p1.playerIndex))
                {
                    game->p1.y += player1Speed * diagDiff;
                    game->p1.x -= player1Speed * diagDiff;
                    
                }
                break;
            case PlayerDirection_East:
                if(playerInBounds(game,game->p1.x - _playerWidth - player1Speed,-1,game->p1.playerIndex)) //Right
                {
                    game->p1.x -= player1Speed;
                }
                break;
            case PlayerDirection_SouthEast:
                if(playerInBounds(game, game->p1.x-_playerWidth+player1Speed, game->p1.y - _playerHeight - player1Speed,game->p1.playerIndex))
                {
                    game->p1.x -= player1Speed * diagDiff;
                    game->p1.y -= player1Speed * diagDiff;
                }
                break;
            case PlayerDirection_South:
                if(playerInBounds(game, -1, game->p1.y - _playerHeight - player1Speed,game->p1.playerIndex))
                {
                    game->p1.y -= player1Speed;
                }
                break;
            case PlayerDirection_SouthWest:
                if(playerInBounds(game, game->p1.x + player1Speed, game->p1.y - _playerHeight - player1Speed,game->p1.playerIndex))
                {
                    game->p1.y -= player1Speed * diagDiff;
                    game->p1.x += player1Speed * diagDiff;
                }
                break;
            case PlayerDirection_West:
                if(playerInBounds(game, game->p1.x + player1Speed, -1,game->p1.playerIndex))
                {
                    game->p1.x += player1Speed;
                }
                break;
            case PlayerDirection_NorthWest:
                if(playerInBounds(game, game->p1.x + player1Speed, game->p1.y + player1Speed,game->p1.playerIndex))
                {
                    game->p1.x += player1Speed * diagDiff;
                    game->p1.y += player1Speed * diagDiff;
                }
                break;
                
            default:
                break;
        }
    }
    
    if((game->input->keyboard['I'] || game->input->keyboard['i']) && game->p2.alive)//Forwards
    {
        switch (game->p2.direction) {
            case PlayerDirection_North:
                if(playerInBounds(game, -1,game->p2.y - player2Speed,game->p2.playerIndex))
                {
                    game->p2.y -= player2Speed;
                }
                break;
            case PlayerDirection_NorthEast:
                if(playerInBounds(game, game->p2.x + _playerWidth+player2Speed,game->p2.y - player2Speed,game->p2.playerIndex))
                {
                    game->p2.y -= player2Speed * diagDiff;
                    game->p2.x += player2Speed * diagDiff;
                    
                }
                break;
            case PlayerDirection_East:
                if(playerInBounds(game,game->p2.x + _playerWidth + player2Speed,-1,game->p1.playerIndex)) //Right
                {
                    game->p2.x += player2Speed;
                }
                break;
            case PlayerDirection_SouthEast:
                if(playerInBounds(game, game->p2.x+_playerWidth+player2Speed, game->p2.y + _playerHeight + player2Speed,game->p2.playerIndex))
                {
                    game->p2.x += player2Speed * diagDiff;
                    game->p2.y += player2Speed * diagDiff;
                }
                break;
            case PlayerDirection_South:
                if(playerInBounds(game, -1, game->p2.y + _playerHeight + player2Speed,game->p2.playerIndex))
                {
                    game->p2.y += player2Speed;
                }
                break;
            case PlayerDirection_SouthWest:
                if(playerInBounds(game, game->p2.x - player2Speed, game->p2.y + _playerHeight + player2Speed,game->p2.playerIndex))
                {
                    game->p2.y += player2Speed * diagDiff;
                    game->p2.x -= player2Speed * diagDiff;
                }
                break;
            case PlayerDirection_West:
                if(playerInBounds(game, game->p2.x - player2Speed, -1,game->p2.playerIndex))
                {
                    game->p2.x -= player2Speed;
                }
                break;
            case PlayerDirection_NorthWest:
                if(playerInBounds(game, game->p2.x - player2Speed, game->p2.y - player2Speed,game->p2.playerIndex))
                {
                    game->p2.x -= player2Speed * diagDiff;
                    game->p2.y -= player2Speed * diagDiff;
                }
                break;
                
            default:
                break;
        }
    }
    
    if((game->input->keyboard['K'] || game->input->keyboard['k']) && game->p2.alive)//Backwards
    {
        switch (game->p2.direction) {
            case PlayerDirection_North:
                if(playerInBounds(game, -1,game->p2.y + player2Speed,game->p2.playerIndex))
                {
                    game->p2.y += player2Speed;
                }
                break;
            case PlayerDirection_NorthEast:
                if(playerInBounds(game, game->p2.x - _playerWidth-player2Speed,game->p2.y + player2Speed,game->p2.playerIndex))
                {
                    game->p2.y += player2Speed * diagDiff;
                    game->p2.x -= player2Speed * diagDiff;
                    
                }
                break;
            case PlayerDirection_East:
                if(playerInBounds(game,game->p2.x - _playerWidth - player2Speed,-1,game->p2.playerIndex)) //Right
                {
                    game->p2.x -= player2Speed;
                }
                break;
            case PlayerDirection_SouthEast:
                if(playerInBounds(game, game->p2.x-_playerWidth+player2Speed, game->p2.y - _playerHeight - player2Speed,game->p2.playerIndex))
                {
                    game->p2.x -= player2Speed * diagDiff;
                    game->p2.y -= player2Speed * diagDiff;
                }
                break;
            case PlayerDirection_South:
                if(playerInBounds(game, -1, game->p2.y - _playerHeight - player2Speed,game->p2.playerIndex))
                {
                    game->p2.y -= player2Speed;
                }
                break;
            case PlayerDirection_SouthWest:
                if(playerInBounds(game, game->p2.x + player2Speed, game->p2.y - _playerHeight - player2Speed,game->p2.playerIndex))
                {
                    game->p2.y -= player2Speed * diagDiff;
                    game->p2.x += player2Speed * diagDiff;
                }
                break;
            case PlayerDirection_West:
                if(playerInBounds(game, game->p2.x + player2Speed, -1,game->p2.playerIndex))
                {
                    game->p2.x += player2Speed;
                }
                break;
            case PlayerDirection_NorthWest:
                if(playerInBounds(game, game->p2.x + player2Speed, game->p2.y + player2Speed,game->p2.playerIndex))
                {
                    game->p2.x += player2Speed * diagDiff;
                    game->p2.y += player2Speed * diagDiff;
                }
                break;
                
            default:
                break;
        }
    }
}
Exemplo n.º 10
0
void inputHandler() {
    while (isRunning()) {
        try {
            if(SDL_PollEvent(&event)) {
                switch (event.type) {
                case SDL_QUIT:
                    setRunning(false);
                    break;
                case SDL_MOUSEBUTTONDOWN:
                    println("Mouse button pressed");
                    switch (event.button.button) {
                        case SDL_BUTTON_WHEELDOWN:
                            setCurrentWeapon(((((getCurrentWeapon() - 1) > 9001) && ((getCurrentWeapon() - 1) < 9007)) ? (getCurrentWeapon() - 1) :
                                #if mouseWheelWeaponChangeScrollLoop
                                    9006
                                #else
                                    getCurrentWeapon()
                                #endif
                            ));
                            break;
                        case SDL_BUTTON_WHEELUP:
                            setCurrentWeapon(((((getCurrentWeapon() + 1) > 9001) && ((getCurrentWeapon() + 1) < 9007)) ? (getCurrentWeapon() + 1) :
                                #if mouseWheelWeaponChangeScrollLoop
                                    9006
                                #else
                                    getCurrentWeapon()
                                #endif
                            ));
                            break;
                        case SDL_BUTTON_LEFT:
                        case SDL_BUTTON_RIGHT:
                            fireWeapon();
                    }
                    break;
                case SDL_MOUSEBUTTONUP:
                    println("Mouse button released");
                    setFiring(false);
                    break;
                case SDL_MOUSEMOTION:
                    SDL_GetMouseState(&mouse_x,&mouse_y);
                    #if debugMouseMovement
                        printf("Mouse movement detected. X: %d Y: %d\n",mouse_x,mouse_y);
                    #endif
                    break;
                case SDL_KEYDOWN:
                    SDLKey keyPressed = event.key.keysym.sym;
                    switch (keyPressed) {
                        case SDLK_ESCAPE:
                            println("Escape key pressed.");
                        case SDLK_F12: //in case escape doesn't get detected, we can also use F12.
                            setRunning(false);
                            break;
                        case SDLK_F1:
                            setCurrentWeapon(RIFLE);
                            break;
                        case SDLK_F2:
                            setCurrentWeapon(MACHINE_GUN);
                            break;
                        case SDLK_F3:
                            setCurrentWeapon(SHOTGUN);
                            break;
                        case SDLK_F4:
                            setCurrentWeapon(MACHINE_SHOTGUN);
                            break;
                        case SDLK_F5:
                            setCurrentWeapon(FLAMETHROWER);
                            break;
                        case SDLK_HOME:
                            toggleAlphaVisible();
                            println("Home key pressed. Toggling alpha test visibility.");
                            break;
                        case SDLK_DELETE:
                            println("Delete key pressed. Removing all damage, and resetting the game");
                            resetGame();
                            break;
                        case SDLK_F11:
                            println("F11 pressed. Toggling fullscreen...");
                            toggleFullscreen();
                            break;
                        default:
                            printf("An unhandled key was pressed: ");
                            displayKey(&event.key);
                        }
                    break;
                }
            }
        } catch(...) {
            println("Exception occurred handling input...");
        }
    }
}