void ATP_TwinStickPawn::Tick(float DeltaSeconds)
{
	// Find movement direction
	const float ForwardValue = GetInputAxisValue(MoveForwardBinding);
	const float RightValue = GetInputAxisValue(MoveRightBinding);

	// Clamp max size so that (X=1, Y=1) doesn't cause faster movement in diagonal directions
	const FVector MoveDirection = FVector(ForwardValue, RightValue, 0.f).GetClampedToMaxSize(1.0f);

	// Calculate  movement
	const FVector Movement = MoveDirection * MoveSpeed * DeltaSeconds;

	// If non-zero size, move this actor
	if (Movement.SizeSquared() > 0.0f)
	{
		const FRotator NewRotation = Movement.Rotation();
		FHitResult Hit(1.f);
		RootComponent->MoveComponent(Movement, NewRotation, true, &Hit);
		
		if (Hit.IsValidBlockingHit())
		{
			const FVector Normal2D = Hit.Normal.GetSafeNormal2D();
			const FVector Deflection = FVector::VectorPlaneProject(Movement, Normal2D) * (1.f - Hit.Time);
			RootComponent->MoveComponent(Deflection, NewRotation, true);
		}
	}
	
	// Create fire direction vector
	const float FireForwardValue = GetInputAxisValue(FireForwardBinding);
	const float FireRightValue = GetInputAxisValue(FireRightBinding);
	const FVector FireDirection = FVector(FireForwardValue, FireRightValue, 0.f);

	// Try and fire a shot
	FireShot(FireDirection);
}
Example #2
0
void Player::FireButtonPressed(void)
{
	if (m_Active && !m_Hit)
	{
		FireShot();
	}
}
Example #3
0
void MouseButtonHandler (int iButton, int iState, int iX, int iY) // mouse button handler
{
	iLastMouseY = iY ;
	iLastMouseX = iX ;
	if (iButton == GLUT_RIGHT_BUTTON)
	{

		if (iState == GLUT_DOWN) 
		{
			bRightMouseDown = true ;
		}
		else 
		{
			bRightMouseDown = false ;
		}
	} else if (iButton == GLUT_LEFT_BUTTON)
	{
		if (iState == GLUT_DOWN) 
		{
			bLeftMouseDown = true ;
			if (!bExplode && !bPause) FireShot(&Player, pPlayerShots) ;
		}
		else 
		{
			bLeftMouseDown = false ;	
		}
	}
}
Example #4
0
void SmallUFO::DoesUFOShot(void)
{
	if (m_TimerFireShot < al_get_time())
	{
		ResetShotTimer(0);

		if (Random(0, 100) < 80)
			FireShot(Random(0, 600) * 0.01);
		else
			AimAtPlayer();
	}
}
void Angreifer::Update(Number * elapsed)
{
	Enemy::Update(elapsed);

	if (DoesMovementChange())
	{
		m_Acceleration = VectorChange();
	}

	if (TimeToFire())
	{
		FireShot(m_Position, pScene);
	}
}
Example #6
0
void AKappaPawn::Tick(float DeltaSeconds)
{
    GEngine->AddOnScreenDebugMessage(0, 5.f, FColor::Yellow, FString::FromInt(Score));

    // Find movement direction
    const float ForwardValue = GetInputAxisValue(MoveForwardBinding);
    const float RightValue = GetInputAxisValue(MoveRightBinding);

    // Clamp max size so that (X=1, Y=1) doesn't cause faster movement in diagonal directions
    const FVector MoveDirection = FVector(ForwardValue, RightValue, 0.f).GetClampedToMaxSize(1.0f);

    // Calculate  movement
    const FVector Movement = MoveDirection * MoveSpeed * DeltaSeconds;

    // If non-zero size, move this actor
    if (Movement.SizeSquared() > 0.0f)
    {
        const FRotator NewRotation = Movement.Rotation();
        FHitResult Hit(1.f);
        RootComponent->MoveComponent(Movement, NewRotation, true, &Hit);

        if (Hit.IsValidBlockingHit())
        {
            const FVector Normal2D = Hit.Normal.GetSafeNormal2D();
            const FVector Deflection = FVector::VectorPlaneProject(Movement, Normal2D) * (1.f - Hit.Time);
            RootComponent->MoveComponent(Deflection, NewRotation, true);
        }
    }

    // Create fire direction vector
    /*const float FireForwardValue = GetInputAxisValue(FireForwardBinding);
    const float FireRightValue = GetInputAxisValue(FireRightBinding);
    const FVector FireDirection = FVector(FireForwardValue, FireRightValue, 0.f);*/
    FVector WorldPosition, WorldDirection;
    APlayerController* MyController = Cast<APlayerController>(GetController());
    MyController->DeprojectMousePositionToWorld(WorldPosition, WorldDirection);

    const FVector FireDirection = FVector(WorldDirection.Component(0), WorldDirection.Component(1), 0.f);
    // Try and fire a shot
    FireShot(FireDirection);
}
Example #7
0
void KeyboardHandler (unsigned char cKey, int iX, int iY) // keyboard input handling function
{
	switch (cKey)
	{
	case 'p' :
	case 'P' :
		bPause = !bPause ;
	break ;
#ifdef _DEBUG
	case 'm' : // toggle filling
	case 'M' :
		ToggleFilling(!bFilling) ;
	break ;

	case 'n' : // toggle lighting
	case 'N' :
		ToggleLighting(!bLighting) ;
	break ;
#endif

	case 'i' : 
	case 'I' :
		InitCamera(10) ;
	break ;

	case 'a' :
	case 'A' :
		bAutofire = !bAutofire ;
	break ;

	case ' ' :
		if (!bExplode && !bPause) FireShot(&Player, pPlayerShots) ;
	break ;
	case 'w' :
	case 'W' :
		fCameraAngle[0] += 10 ;
	break ;
	case 'x' :
	case 'X' :
		fCameraAngle[0] -= 10 ;
	break ;
	case 's' :
    case 'S' :
		fCameraAngle[2] += 10 ;
	break ;
	case 'd' :
	case 'D' :
		fCameraAngle[2] -= 10 ;
	break ;

	case 'r' :
	case 'R' :
		iScore = 0 ;
		bExplode = !bExplode ;
		iCount = 0 ;
	break ;

	case 'c' :
	case 'C' :
		bRotate = !bRotate ;
	break ;

	case 'q' : // quit program
	case 'Q' :
		ClearEntitys(pPlayerShots) ;
		ClearEntitys(pEnemyShots) ;
		ClearEntitys(pStars) ;
		ClearEntitys(pPlanets) ;

		Particles.Clear(true) ;
		exit(0) ;
	break ;
	}
}
Example #8
0
void DisplayHandler () // display callback function
{
	if (bRotate) 
	{
		fCameraAngle[0] += 1.0 ;
		fCameraAngle[2] += 1.0 ;
	}
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
	glLoadIdentity() ;

	SetCamera() ;

	if (!bPause)
	{
		GLfloat fTempX = GLfloat(iLastMouseX) / GLfloat(iWinWidth) ;
		GLfloat fTempY = GLfloat(iLastMouseY) / GLfloat(iWinHeight) ;
		GLfloat fFixedX = (Player.ptLocation.dX - 8.65) / -17.3 ;
		GLfloat fFixedZ = (Player.ptLocation.dZ - 8.65) / -17.3 ;
		if (bRightMouseDown)
		{
			if (!(fFixedX + 0.02 > fTempX && fFixedX - 0.02 < fTempX))
			{
				if (fFixedX > fTempX)
				{
					Player.ptLocation.dX += 0.1 ;
					if (Player.ptAngle.dZ > -20) 
						Player.ptAngle.dZ -= 5.0 ;
				} else
				{
					Player.ptLocation.dX -= 0.1 ;
					if (Player.ptAngle.dZ < 20) 
						Player.ptAngle.dZ += 5.0 ;
				}
			} else
			{
				if (Player.ptAngle.dZ < 0) Player.ptAngle.dZ += 5.0 ;
				else if (Player.ptAngle.dZ > 0)	Player.ptAngle.dZ -= 5.0 ;
			}
			if (!(fFixedZ + 0.1 > fTempY && fFixedZ - 0.02 < fTempY))
			{
				if (fFixedZ > fTempY)
				{
					Player.ptLocation.dZ += 0.1 ;
				} else 
				{
					Player.ptLocation.dZ -= 0.1 ;
				}
			}
		} else Player.ptAngle.dZ = 0 ;

		if (randp() > 0.98) AddPlanet() ;
		AddStar() ;
		AddStar() ;
		AddStar() ;
		AddStar() ;
		AddStar() ;
		AddStar() ;

		if (/*!bExplode && */iCount % 15 == 0) SpawnEnemy() ;

		if (!bExplode && bAutofire && iCount % 4 == 0) FireShot(&Player, pPlayerShots) ;

		iCount ++ ;

	}
	
	DisplayStars() ;
	DisplayPlanets() ;
	DisplayEnemies() ;

	DisplayShots(pPlayerShots) ;
	DisplayShots(pEnemyShots) ;

	if (bExplode && !bPause)
	{
		if (iCount == 0) 
		{
			printf("Game over\n") ;
			MakeExplosion(Player.ptLocation, 1000) ;
		}
	} else 
	{
		if (iCount % 4)
		{
			Particle *pNew = new Particle ;
			pNew->ptLocation.dX = Player.ptLocation.dX + randp() * 0.5 - 0.25;
			pNew->ptLocation.dY = Player.ptLocation.dY + 0.3 * randp() ;
			pNew->ptLocation.dZ = Player.ptLocation.dZ - 1.5 + 0.2 * randp() ;
			pNew->ptVelocity.dX = 0 ;
			pNew->ptVelocity.dY = 0 ;
			pNew->ptVelocity.dZ = -0.2 ;
			pNew->ptColor.dX = 0.98 ;
			pNew->ptColor.dY = 0.59 + 0.3 * randp() - 0.15 ;
			pNew->ptColor.dZ = 0.01 ;
			pNew->dAlpha = 0.7 ;
			pNew->dMass = 1 ;
			pNew->dLife = 7 * randp() + 3 ;
			pNew->ptAcceleration = 0 ;
			Particles.AddBack(pNew) ;
		}

		Player.Display() ;
	}

	LinkedListNode<Particle> *pTravParticles = Particles.pHead ;
	LinkedListNode<Particle> *pTempParticle ;
	
	while (pTravParticles != 0)
	{
		pTravParticles->pValue->dLife -- ;
		if (pTravParticles->pValue->dLife <= 0)
		{
			pTempParticle = pTravParticles ;
			pTravParticles = pTravParticles->pNext ;
			Particles.Remove(pTempParticle, true) ;
		} else
		{
			pTravParticles->pValue->Apply(0.9) ;
			
			DisplayParticle(pTravParticles->pValue) ;
			
			pTravParticles = pTravParticles->pNext ;
		}
	}
	
		
	glFinish() ;
	glutSwapBuffers() ;
	glutPostRedisplay() ;
}
Example #9
0
void DisplayEnemies()
{
	Entity *pTrav = pEnemys ;
	Entity *pTravShots ;
	Entity *pTemp ;
	bool bShot ;
	Point ptBBModelUFL, ptBBModelLBR, ptBBShotUFL, ptBBShotLBR ;
	while (pTrav != 0)
	{
		if (pTrav->ptLocation.dZ > -100)
		{
			ptBBModelUFL = pTrav->ptLocation + pTrav->pModel->ptBBUpperFrontLeft ;
			ptBBModelLBR = pTrav->ptLocation + pTrav->pModel->ptBBLowerBackRight ;

			bShot = false ;
			pTravShots = pPlayerShots ;
			while (pTravShots != 0)
			{
				ptBBShotUFL = pTravShots->ptLocation + pTravShots->pModel->ptBBUpperFrontLeft ;
				ptBBShotLBR = pTravShots->ptLocation + pTravShots->pModel->ptBBLowerBackRight ;

				if ((ptBBModelUFL < ptBBShotUFL && ptBBModelLBR > ptBBShotUFL) || 
					(ptBBModelUFL < ptBBShotLBR && ptBBModelLBR > ptBBShotLBR))
				{
					bShot = true ;

					MakeExplosion(pTrav->ptLocation, 500) ;

					if (!bExplode)
					{
						iScore += 100 ;
						printf ("Score: %i\n", iScore) ;
					}

					pTemp = pTrav ;
					pTrav = pTrav->pNext ;
					pTemp->pModel = 0 ;
					RemoveEntity(pEnemys, pTemp) ;
					pTravShots->pModel = 0 ;
					RemoveEntity(pPlayerShots, pTravShots) ;
					break ;
				}
				pTravShots = pTravShots->pNext ;
			}

			if (!bShot)
			{
				ptBBShotUFL = Player.ptLocation + Player.pModel->ptBBUpperFrontLeft ;
				ptBBShotLBR = Player.ptLocation + Player.pModel->ptBBLowerBackRight ;

				if (!bExplode && ((ptBBModelUFL < ptBBShotUFL && ptBBModelLBR > ptBBShotUFL) || 
									(ptBBModelUFL < ptBBShotLBR && ptBBModelLBR > ptBBShotLBR)))
				{
					bExplode = true ;
					iCount = 0 ; 

					MakeExplosion(pTrav->ptLocation, 500) ;
					pTemp = pTrav ;
					pTrav = pTrav->pNext ;
					pTemp->pModel = 0 ;
					RemoveEntity(pEnemys, pTemp) ;
				} else
				{
//					if (randp() > 0.99)
					if (!bExplode && randp() > 0.99)
						FireShot(pTrav, pEnemyShots) ;
					pTrav->Display() ;
					if (!bPause) pTrav->ptLocation = pTrav->ptLocation + pTrav->ptDirection ;
					pTrav = pTrav->pNext ;
				}
			}
		} else 
		{
			pTemp = pTrav ;
			pTrav = pTrav->pNext ;
			pTemp->pModel = 0 ;
			RemoveEntity(pEnemys, pTemp) ;
		}
	}
}
Example #10
0
void SmallUFO::AimAtPlayer(void)
{
	FireShot(atan2(m_PlayerY - m_Y, m_PlayerX - m_X));
}
Example #11
0
void UFO::Update(Number * elapsed)
{
	Location::Update(elapsed);

	m_ShipMesh->setPosition(m_Position);

	if (m_Position.x > m_WindowWidth || m_Position.x < -m_WindowWidth)
	{
		m_Done = true;
	}

	CheckForEdge();

	if (p_Player->m_Active && !p_Player->m_Hit)
	{
		if (CirclesIntersect(p_Player->m_Position, p_Player->m_Radius))
		{
			if (p_Player->m_ShieldOn)
			{
				CollisionResult *vsShield = &p_Scene->testCollision(m_ShipMesh, p_Player->m_ShieldMesh);

				if (vsShield->collided)
				{
					if (!m_ShieldHit)
					{
						p_Player->ShieldHit(m_Velocity * 3, false);
						m_ShieldHit = true;
					}
				}
				else
					m_ShieldHit = false;
			}
			else
			{
				CollisionResult *vsPlayer = &p_Scene->testCollision(m_ShipMesh, p_Player->m_ShipMesh);

				if (vsPlayer->collided)
				{
					ExplodeSound();
					p_Player->Hit();
					p_Player->GotPoints(m_Points);
					m_Hit = true;
				}
			}
		}
	}

	for (int i = 0; i < 4; i++)
	{
		if (p_Player->p_Shots[i]->m_Active)
		{
			if (CirclesIntersect(p_Player->p_Shots[i]->m_Position, p_Player->p_Shots[i]->m_Radius))
			{
				CollisionResult *rockVsPlayerShot = &p_Scene->testCollision(m_ShipMesh, p_Player->p_Shots[i]->m_ShotMesh);

				if (rockVsPlayerShot->collided)
				{
					ExplodeSound();
					p_Player->DeactivateShot(i);
					p_Player->GotPoints(m_Points);
					m_Hit = true;
					break;
				}
			}
		}
	}

	if (p_FireTimer->getElapsedf() > m_FireTimerAmount)
	{
		FireShot();
	}

	if (p_VectorTimer->getElapsedf() > m_VectorTimerAmount)
	{
		ChangeVector();
	}

	if (p_Player->m_GameOver)
	{
		if (p_EngineLargeSound != NULL)
		{
			if (p_EngineLargeSound->isPlaying());
				p_EngineLargeSound->Stop();
		}

		if (p_EngineSmallSound != NULL)
		{
			if (p_EngineSmallSound->isPlaying());
				p_EngineSmallSound->Stop();
		}
	}
}