Exemple #1
0
void Elf::ElfUpdate(float deltaTime)
{
	_timeLeftUp -= deltaTime;
	if(_timeLeftUp <= 0.0f)
	{
		if (_isUp)
			GetDown(); // start moving the elf downwards
		else
		{
			if (_position.y < _startingYPos)
				// when the elf is back in his hole stop updating
				_isAlive = false;
		}
	}
}
Exemple #2
0
void FreeCamera::Update(const tt::GameContext& context)
{
	auto pInputService = MyServiceLocator::GetInstance()->GetService<IInputService>();
	auto pTransform = GetComponent<TransformComponent>();
	
	if(pInputService->IsActionTriggered(InputActionId::CameraMoveForward))
		pTransform->Translate(pTransform->GetForward() * m_MovementSpeed, true);
	
	if(pInputService->IsActionTriggered(InputActionId::CameraMoveBack))
		pTransform->Translate(pTransform->GetBackward() * m_MovementSpeed, true);
	
	if(pInputService->IsActionTriggered(InputActionId::CameraMoveLeft))
		pTransform->Translate(pTransform->GetLeft() * m_MovementSpeed, true);
	
	if(pInputService->IsActionTriggered(InputActionId::CameraMoveRight))
		pTransform->Translate(pTransform->GetRight() * m_MovementSpeed, true);

	if(pInputService->IsActionTriggered(InputActionId::CameraMoveUp))
		pTransform->Translate(pTransform->GetUp() * m_MovementSpeed, true);
	
	if(pInputService->IsActionTriggered(InputActionId::CameraMoveDown))
		pTransform->Translate(pTransform->GetDown() * m_MovementSpeed, true);

	if(!pInputService->IsActionTriggered(InputActionId::CameraUnlockRotation))
		return;

	auto mouseMovement = pInputService->GetMouseMovement();
	mouseMovement *= m_RotationSpeed * context.GameTimer.GetElapsedSeconds();
	m_Yaw += mouseMovement.x;
	m_Pitch += mouseMovement.y;

	tt::Quaternion yawQuat(tt::Vector3::j, m_Yaw);
	tt::Vector3 rotatedRight = tt::Vector3::i.TransformPoint(yawQuat);
	tt::Quaternion pitchQuat(rotatedRight, m_Pitch);

	pTransform->Rotate(yawQuat * pitchQuat);
}
Exemple #3
0
void menu(void)
{
    struct Solid cursor;
	char selection = 0;
	displayMenu(&cursor);
    StartTimer(0, 200);
    StartTimer(1, 200);


	for (;;)
	{
		if (CheckTimer(0))
		{
            if (GetUp())
            {
            	if (selection > 0)
            	{
            		solid_moveLocation(&cursor, cursor.x - 22, cursor.y);
            		selection--;
            		StartTimer(0, 200);
            	}
            }
            else if (GetDown())
            {
            	if (selection < 7)
            	{
               	   solid_moveLocation(&cursor, cursor.x + 22, cursor.y);
                   selection++;
                   StartTimer(0, 200);
            	}

            }
		}
		if (CheckTimer(1))
		{
			if (GetTopLeft())
			{
				if (selection == 0)
				{
					StarBattle();
					displayMenu(&cursor);
					selection = 0;
				}
				else if (selection == 1)
				{
				    BrickBreaker();
				    displayMenu(&cursor);
				    selection = 0;
				}
				else if (selection == 2)
				{
                    Debris();
                    displayMenu(&cursor);
                    selection = 0;
				}
				else if (selection == 3)
				{
				    Pong();
                    displayMenu(&cursor);
                    selection = 0;
				}
				else if (selection == 4)
				{
				    Draw();
				    displayMenu(&cursor);
				    selection = 0;
				}
				StartTimer(1, 200);
			}
		}

	}


}
Exemple #4
0
void Pong(void)
{
   int i;
   int closest_index = -1;
   int closest_value = 500;
   int wall_bounce = 0;
   unsigned int computerScore = 0;
   unsigned int playerScore = 0;
   unsigned int ball_speed = PONG_BALL_SPEED;

   struct Solid userPaddle;
   struct Solid computerPaddle;
   struct Solid balls[NUM_PONGBALLS];

   //By default, all pong balls are disabled.
   for (i = 0; i < NUM_PONGBALLS; i++)
   {
       balls[i].health = 0;
   }
   ILI9340_setBgColor(COLOR_YELLOW);
   printf_setFont_properties(2, 0, COLOR_BLUE, COLOR_YELLOW);
   printf_setFont_location(10, 300);
   _printf("Player %u", playerScore);
   printf_setFont_location(10, 150);
   _printf("Computer %u", computerScore);

   build_solid(&userPaddle, 100, 290, 30, 4, COLOR_BLUE);
   build_solid(&computerPaddle, 100, 30, 30, 4, COLOR_RED);
   build_moving_solid(&balls[0], 100, 100, 7, 7, COLOR_GREEN, SOLID_AUTOUP | SOLID_AUTOLEFT, 0x0f, 27, 4);
   build_moving_solid(&balls[1], 100, 200, 7, 7, COLOR_BLUE, SOLID_AUTODOWN | SOLID_AUTORIGHT, 0x0f, 27, 4);
   build_moving_solid(&balls[2], 150, 200, 7, 7, COLOR_RED, SOLID_AUTOUP | SOLID_AUTORIGHT, 0x0f, 27, 4);
   build_moving_solid(&balls[3], 200, 200, 7, 7, COLOR_CYAN, SOLID_AUTODOWN | SOLID_AUTOLEFT, 0x0f, 27, 4);
   StartTimer(0, PONG_PADDLE_SPEED);
   StartTimer(1, ball_speed);
   StartTimer(2, CHECK_PONG_PAUSE);

   for (;;)
   {
       if (CheckTimer(0))
       {
           if (GetUp())
           {
               solid_fastMoveUp(&userPaddle, GetJoystickYMag() + 5, 0);
           }
           else if (GetDown())
           {
               solid_fastMoveDown(&userPaddle, GetJoystickYMag() + 5, 0);
           }
           StartTimer(0, PONG_PADDLE_SPEED);
       }
       if (CheckTimer(1))
       {
           //By default we support multiple pong balls
           for (i = 0; i < NUM_PONGBALLS; i++)
           {
              if (solid_checkIntersectionPongPaddle(&balls[i], &userPaddle) || solid_checkIntersectionPongPaddle(&balls[i], &computerPaddle))
              {
                  playSound(0);
                  if (ball_speed > 20)
                  {
                      ball_speed--;
                  }
              }

              wall_bounce = solid_autoMove(&balls[i]);
              //Hit the left of the screen
              if (wall_bounce == 3)
              {
                  display_solid(&balls[i], 1);
                  printf_setFont_location(10, 44);
                  computerScore++;
                  _printf("%u", computerScore);
                  build_moving_solid(&balls[i], userPaddle.x + 4, 280, 7, 7, balls[i].color, SOLID_AUTOUP | SOLID_AUTORIGHT, 0x0f, 27, 4);

              }
              else if (wall_bounce == 4)
              {
                  display_solid(&balls[i], 1);
                  printf_setFont_location(10, 217);
                  playerScore++;
                  _printf("%u", playerScore);
                  build_moving_solid(&balls[i], computerPaddle.x + 4, 40, 7, 7, balls[i].color, SOLID_AUTOUP | SOLID_AUTOLEFT, 0x0f, 27, 4);
              }
              if (wall_bounce != 0)
              {
                  playSound(0);
              }
              if (balls[i].health > 0 && ((balls[i].autoMove & SOLID_AUTORIGHT) || (balls[i].autoMove & SOLID_FASTRIGHT)))
              {
                  if (balls[i].y < closest_value && balls[i].y > 22)
                  {
                      closest_index = i;
                      closest_value = balls[i].y;
                  }
              }
           }
           if (closest_index != -1)
           {
               solid_aiMovePaddle(&computerPaddle, &balls[closest_index]);
           }
           closest_index = -1;
           closest_value = 500;
           StartTimer(1, ball_speed);
       }
       if (CheckTimer(2))
       {
           if (GetJoystickBtn())
           {
               if (Pause() == 1)
               {
                   break;
               }
           }
           StartTimer(2, CHECK_PONG_PAUSE);
       }
   }






}
bool    wxSpeedButton::GetValue(void) {

    return GetDown();
}
Exemple #6
0
/******************************************************
* PONG
* DESCRIPTION: JConsole2 Portable implementation of pong
* Created: 8/28/2013
******************************************************/
void Pong(char autoAi)
{
   char hit = 0;
   char pong_ball_start = 0;
   unsigned int userScore = 0;
   unsigned int compScore = 0;
   unsigned int highScore = EEProm_Read_16(pongHighScore);
   unsigned int ballSpeed = PONG_INITIALBALLSPEED;
   struct Paddle playerPaddle;
   struct Paddle aiPaddle;
   struct Solid ball;
   LcdClear();

   //Construct game objects
   constructPaddle2(&aiPaddle, 74, 1, 10);
   constructPaddle2(&playerPaddle, 7, 1, 10);
   displayPaddle(&playerPaddle, 0);
   displayPaddle(&aiPaddle, 0);
   displayPongScore(&userScore, &compScore);
   reset(&ball, 15, 1, 3, 3, 1);

   //Start timers
   StartTimer(0, PONG_PLAYERMOVETIME);  //Move player timer
   StartTimer(1, ballSpeed);  //Move player timer

   for (;;)
   {
	  if (CheckTimer(0))
	  {
		  if (GetDown())
		  {
		     paddle_moveDown(&playerPaddle);
		  }
		  else if (GetUp())
		  {
			  paddle_moveUp(&playerPaddle);
		  }
		  else if (GetEnterButton()) //Pause
		  {
			 if (Pause(showPongScore, userScore,  compScore, highScore) == 1)
			 {
			     return;
			 }
			 displayPaddle(&playerPaddle, 0);
			 displayPaddle(&aiPaddle, 0);
			 displaySolid(&ball, 0);
			 displayPongScore(&userScore, &compScore);
		  }
		  StartTimer(0, PONG_PLAYERMOVETIME);  //Move player timer
	  }
      if (CheckTimer(1))
      {
         //If ball moves and hits a wall, make a sound
         if (autoMoveSolid(&ball) > 1)
         {
        	 SendData(SOUND_BLOCK_DESTROYED);
         }
         aiMove(&aiPaddle, &ball); //Move computer players paddle
         if (autoAi == 1)
         {
            aiMove(&playerPaddle, &ball);
         }
         hit = checkForHit(&aiPaddle, &ball) + checkForHit(&playerPaddle, &ball);   //Check to see if ball hit either paddle
         if (hit != 0)
         {
        	 SendData(SOUND_BLOCK_DESTROYED);
        	displayPongScore(&userScore, &compScore);
        	if (ballSpeed > 10)
        	{
        	   ballSpeed = ballSpeed - 1;
        	}
         }
         //Ball hit on players side
         if (ball.xLocation == 1)
         {
            compScore++;
            displayPongScore(&userScore, &compScore);
            displayPaddle(&playerPaddle, 0);
            displayPaddle(&aiPaddle, 0);
            randomBallStart(&ball, &pong_ball_start);
         }
         //Ball hit on computers side
         else if (ball.xLocation == 76)
         {
            userScore++;
            displayPongScore(&userScore, &compScore);
            displayPaddle(&playerPaddle, 0);
            displayPaddle(&aiPaddle, 0);
            randomBallStart(&ball, &pong_ball_start);
            if (userScore > highScore)
            {
               highScore = userScore;
               EEProm_Write_16(highScore, pongHighScore);
            }
         }
         StartTimer(1, ballSpeed);  //Move player timer
      }
   }

}
Exemple #7
0
/**********************************************************
* DEBRIS GAME
* DESCRIPTION: This is a game where you need to shoot blocks
**********************************************************/
void Debris(void)
{
   char xMoveStart = 1;
   char fireIndex = 0;
   char moveYStart = 0;
   char yPosStart = 1;
   char index = 0;
   char index2 = 0;
   char jetHitCheck = 1;
   char lastCheck = 0;
   char numShots = 0;
   char yStart = 1;
   unsigned int ballSpeed = DEBRIS_DEBRISMOVERATE;
   unsigned int health = 47;
   unsigned int ballsDestroyed = 0;
   unsigned int highScore = EEProm_Read_16(debrisHighScore_Addr);
   struct Solid balls[DEBRIS_MAXDEBRIS];
   struct Fire ammo[DEBRIS_MAXPROJECTILES];
   struct Jet jet;

   if (health == 0)
   {
      health = 47;
   }

   //Assign pointers to allocated objects
   for (index = 0; index < DEBRIS_MAXDEBRIS; index++)
   {
      balls[index].enabled = 0; //Balls start disabled
   }
   LcdClear();

   //Initialize game objects
   constructJet(&jet, 15, 2);

   //Initialize balls
   reset(&balls[0], 80, 4, 1, 1, 1);
   reset(&balls[1], 60, 0, 3, 2, 1);
   reset(&balls[2], 70, 3, 1, 1, 1);
   reset(&balls[3], 60, 2, 3, 2, 1);
   reset(&balls[4], 80, 1, 1, 1, 1);
   display_jet(&jet, 0);
   DisplayHealth(health, 0);

   //Start Timers
   StartTimer(0, DEBRIS_USERMOVERATE_MS);     //Move player timer
   StartTimer(1, DEBRIS_RATEOFFIRE_MS);       //Fire timer
   StartTimer(2, DEBRIS_PROJECTILESPEED_MS);  //Fire move timer
   StartTimer(3, ballSpeed);                  //Move balls

   //Enter game loop
   for (;;)
   {
	  //Check user move button
	  if (CheckTimer(0))
	  {
		  if (GetEnterButton()) //User wants to pause the game
		  {
			  if (Pause(showJetScore, ballsDestroyed,  health, highScore) == 1)
			  {
				  return;
			  }
			  display_jet(&jet, 0);
			  DisplayHealth(health, 0);
		  }
		  else if (GetLeft()) //Left button is being pressed
		  {
			  jet_moveLeft(&jet, 0);
		  }
		  else if (GetRight())
		  {
			  jet_moveRight(&jet, 0);
		  }
		  if (GetUp())
		  {
			  jet_moveUp(&jet);
		  }
		  else if (GetDown())
		  {
			  jet_moveDown(&jet);
		  }
		  StartTimer(0, DEBRIS_USERMOVERATE_MS); //Reset this timer
	  }
      //Check fire buttons
      if (CheckTimer(1)) //Now we can fire
      {
    	  if (GetFire()) //User took the chance to fire
    	  {
             if (fireIndex == DEBRIS_MAXPROJECTILES){fireIndex = 0;}
             numShots++;
             startFire(&ammo[fireIndex], &jet, 0);
             StartTimer(1, DEBRIS_RATEOFFIRE_MS); //Restart the fire timer.
             fireIndex++;
             SendData(SOUND_FIRE_PROJECTILE); //Fire sound
    	  }
    	  else if (GetSecFire()) //Shockwave cannon
    	  {
    		 if (fireIndex == DEBRIS_MAXPROJECTILES){fireIndex = 0;}
    	     startFire(&ammo[fireIndex], &jet, 2);
    		 StartTimer(1, DEBRIS_RATEOFFIRE_MS + 300); //Restart the fire timer.
    		 numShots++;
    		 fireIndex++;
    		 SendData(SOUND_FIRE_PROJECTILE); //Fire sound
    	  }
    	  else if (GetRightFire()) //Fire Reverse
    	  {
    		 if (fireIndex == DEBRIS_MAXPROJECTILES){fireIndex = 0;}
    		 startFire(&ammo[fireIndex], &jet, 1);
    	     StartTimer(1, DEBRIS_RATEOFFIRE_MS); //Restart the fire timer.
    	     numShots++;
    	     fireIndex++;
    	     SendData(SOUND_FIRE_PROJECTILE); //Fire sound
    	  }
    	  else if (GetRightSecFire()) //Reverse Shockwave cannon
    	  {
    		  if (fireIndex == DEBRIS_MAXPROJECTILES){fireIndex = 0;}
    		  startFire(&ammo[fireIndex], &jet, 3);
    	      StartTimer(1, DEBRIS_RATEOFFIRE_MS + 300);
    	      numShots++;
    	      fireIndex++;
    	      SendData(SOUND_FIRE_PROJECTILE); //Fire sound
    	  }
      }
      //Moves the weapons fire
      if (CheckTimer(2))
      {
          //Check each ammo value to see if it hit a ball
          for (index = 0; index < DEBRIS_MAXPROJECTILES; index++)
          {
             if (ammo[index].enabled == 1) //This gives the game a performance boost but can cause inconsistant ball speeds
             {
                if (autoMove(&ammo[index]) == 1)
                {

                }
                if (lastCheck == 0)
                {
             	  lastCheck = 1;
                   //Check each bullet to see if it hit a ball
                   for (index2 = 0; index2 < DEBRIS_MAXDEBRIS; index2++)
                   {
                      //If a ball is hit, reset it so it starts over again.
             	     if (fire_checkHit(&ammo[index], &balls[index2]) == 1)//ammo[index].fireOutput == 1)
                      {
             	    	SendData(SOUND_BLOCK_DESTROYED); //Block hit sound
             	        balls[index2].enabled = 0;
             	        displaySolid(&balls[index2], 1);
                         if (ammo[index].weapon != 2 && ammo[index].weapon != 3)
                         {
                 	       ammo[index].enabled = 0;
                 	       displayFire(&ammo[index], 1);
                         }
                         //Ball speed increases every time 3 balls are dispatched
                         if (ballsDestroyed % 3 == 0 && ballSpeed > 15)
                         {
                         	ballSpeed--;
                         }
                         changeBallStart(&balls[index2], &moveYStart, &yPosStart, &xMoveStart, &yStart);
                         ballsDestroyed++;
                         if (ballsDestroyed > highScore)
                         {
                         	highScore = ballsDestroyed;
                         	EEProm_Write_16(debrisHighScore_Addr, highScore);
                         }
                      }
                   }
                }
                else
                {
             	   lastCheck = 0;
                }
             }
          }
         StartTimer(2, DEBRIS_PROJECTILESPEED_MS);
      }
      //Move the balls
      if (CheckTimer(3))
      {
          for (index = 0; index < DEBRIS_MAXDEBRIS; index++)
          {
         	if (balls[index].enabled == 1) //Gives a small performance boost at the cost of ball speed consistancy
         	{
         	   autoMoveSolid(&balls[index]);
         	   if (jetHitCheck == 0)
         	   {
                   //Ball hits the jet
         		  jetHitCheck = 1;
                   if (jet_checkHit(&jet, &balls[index]) != 0x00)
                   {
                	  SendData(SOUND_BLOCK_DESTROYED); //Block hit sound
                      balls[index].enabled = 0;
                      displaySolid(&balls[index], 1);
                      display_jet(&jet, 0);
         	          health--;
         	         DisplayHealth(health, 0);
         	         //Jet was destroyed
         	         if (health == 0)
         	         {
         	        	display_jet(&jet, 1);
         	    	    constructJet(&jet, 15, 2);
         	    	    health = 47;
         	    	    ballsDestroyed = 0;
         	    	    display_jet(&jet, 0);
         	         }
         	         changeBallStart(&balls[index], &moveYStart, &yPosStart, &xMoveStart, &yStart);
                  }
         	   }
         	   else
         	   {
         		   jetHitCheck = 0;
         	   }
             }
         }
         StartTimer(3, ballSpeed);
      }
   }
}