Пример #1
0
int main()
{
    SysTick_Config(SystemCoreClock/100);
	magazyn = malloc(sizeof(Element)*1200);
    Timer3Conf();
	Joystick_Initialize();
	Buttons_Initialize();
	initDisplay();
	lcdClean();
	Timer3Disable();
    Timer1Conf();

	lcdMenu();
    while(1)
    {
		while(tickCounter<10);
		tickCounter=0;
		switch(Buttons_GetState())
		{
			case BUTTON_INT0:
            //lcdClean();
            initSnake();
            game = 1;
            while(game == 1)
            {
                //while(tickCounter<10);
                //tickCounter=0;
                inputControl = 0;
                switch(Joystick_GetState())
                {
                    case JOYSTICK_UP:
                        inputControl = 1;
                        break;
                    case JOYSTICK_LEFT:
                        inputControl = 2;
                        break;
                    case JOYSTICK_DOWN:
                        inputControl = 4;
                        break;
                    case JOYSTICK_RIGHT:
                        inputControl = 8;
                                break;
                            default:
                                inputControl = oldControl;
                        }
                        if(inputControl == forbidden)
                            inputControl = oldControl;

                        if(reactCount > 0) {
                            game = react(inputControl);
                            --reactCount;
                        }
                    }
                    lcdString(250, 150, "Koniec gry");
                    while(1);
			break;
			case BUTTON_KEY1:
				lcdString(250, 150, "Opcja 2");
                while(1);
			break;
			case BUTTON_KEY2:
			    lcdString(250, 150, "Opcja 3");
			    while(1);
			break;
		}

	}
	return 0;
}
Пример #2
0
void AppMenu()
{
	offset_y = (1*24)+(3*8);
	BackgroundColor = GLCD_COLOR_WHITE;
	ForegroundColor = GLCD_COLOR_BLACK;
	
	joyMsk = Joystick_GetState();         
	if (joy ^ joyMsk)                		
	{
		joy = joyMsk;
	}
	
	if(joy & JOYSTICK_RIGHT)
	{
		switch(selection)
		{
			case 0:
				menuChoice = InitPong;
				break;
			case 1:
				menuChoice = InitShooter;
				break;
		}
	}

	if(joy & JOYSTICK_UP)
	{				
		if(selection > 0)
		{
			selection--;
		}		
	}
	if(joy & JOYSTICK_DOWN)
	{
		if(selection < (numberOfApps-1))
		{
			selection++;
		}		
	}

	GLCD_SetBackgroundColor (BackgroundColor);
  GLCD_SetForegroundColor (ForegroundColor);
  
	GLCD_DrawRectangle(24, 3, 180, offset_y);
					
	GLCD_SetFont            (&GLCD_Font_16x24);
	GLCD_DrawString         (32, (0*24)+(1*8), "Menu");
	GLCD_SetFont            (&GLCD_Font_6x8);
  GLCD_DrawString         (32, (1*24)+(1*8), "UP/DOWN to select a game");
  GLCD_DrawString         (32, (1*24)+(2*8), "RIGHT to confirm your choice");
	
	GLCD_DrawRectangle(210,3,105,233); //Draw border for preview
	//-------------------------------------------
	GLCD_SetFont            (&GLCD_Font_16x24);
	GLCD_SetForegroundColor (ForegroundColor);
	GLCD_DrawString         (32, (((float) (GLCD_HEIGHT - offset_y)/(float)(numberOfApps+1))*1) + offset_y - 12, "PONG");
		
	if(selection == 0)
	{
		GLCD_SetForegroundColor (ForegroundColor); //Draw if selected		
	}
	else
	{
		GLCD_SetForegroundColor (BackgroundColor); //Don't draw if not selected (will be drawn but in the same color as the background, hence invisible)
	}
	GLCD_DrawRectangle(24, (((float) (GLCD_HEIGHT - offset_y)/(float)(numberOfApps+1))*1) + offset_y - 24, 180, (((float) (GLCD_HEIGHT - offset_y)/(float)(numberOfApps+1))*1)-20);
	DrawPongPreview();	
	
	//-------------------------------------------
	
	//-------------------------------------------
	GLCD_SetForegroundColor (ForegroundColor);
	GLCD_DrawString         (32, (((float) (GLCD_HEIGHT - offset_y)/(float)(numberOfApps+1))*2) + offset_y - 12, "SHOOTER");
		
	if(selection == 1)
	{
		GLCD_SetForegroundColor (ForegroundColor);		
	}
	else
	{
		GLCD_SetForegroundColor (BackgroundColor);	
	}
	GLCD_DrawRectangle(24, (((float) (GLCD_HEIGHT - offset_y)/(float)(numberOfApps+1))*2) + offset_y - 24, 180, (((float) (GLCD_HEIGHT - offset_y)/(float)(numberOfApps+1))*1)-20);
	DrawShooterPreview();
	 
	 //-------------------------------------------

	
	select_y_start = (((float) (GLCD_HEIGHT - offset_y)/(float)(numberOfApps+1))*1) + offset_y - 12;
	select_y_end = select_y_start + 32;	

}
Пример #3
0
void AppPong()
{					
	switch(appPongState)
	{
		case Normal:			

			// Increment ball's position
			new_ball_X += ballVelocityX;
			new_ball_Y += ballVelocityY;
			// Check if the ball is colliding with the left paddle
			if (new_ball_X < (new_paddle0_X + paddleW) )
			{
				// Check if ball is within paddle's height
				if ((new_ball_Y > new_paddle0_Y) && (new_ball_Y < new_paddle0_Y + paddleH))
				{
					new_ball_X += ball_rad;  // Move ball over one to the right
					ballVelocityX = -ballVelocityX; // Change velocity
					Beep();
				}
			}
			// Check if the ball hit the right paddle
			if (new_ball_X + ball_rad > new_paddle1_X)
			{
				// Check if ball is within paddle's height
				if ((new_ball_Y > new_paddle1_Y) && (new_ball_Y < new_paddle1_Y + paddleH))
				{
					new_ball_X -= ball_rad;  // Move ball over one to the left
					ballVelocityX = -ballVelocityX; // change velocity
					Beep();
				}
			}
			// Check if the ball hit the top or bottom
			if ((new_ball_Y <= borderWidth) || (new_ball_Y >= (GLCD_HEIGHT - ball_rad - 1)))
			{
				// Change up/down velocity direction
				ballVelocityY = -ballVelocityY;
				Beep();
			}

			if(AUTOMATIC_CONTROL)
			{
				//Automatic Control
				new_paddle0_Y = new_ball_Y-paddleH/2; // Invincible paddle0					
			}
			else
			{
				//Controlled by potentiometer
				ADC_StartConversion();
				new_paddle0_Y = map(ADC_GetValue(),0,4096,0,GLCD_HEIGHT);
			}
			
			// Automatic control
			new_paddle1_Y = new_ball_Y-paddleH/2; // Invincible paddle1		

			// Check if paddle0 is not out of the frame
			if(new_paddle0_Y  < borderWidth) { // Top Frame
				new_paddle0_Y = borderWidth;
			}
			if(new_paddle0_Y + paddleH > GLCD_HEIGHT - borderWidth) { // Bottom Frame
				new_paddle0_Y = GLCD_HEIGHT - borderWidth - paddleH;
			}
			
			// Check if paddle1 is not out of the frame
			if(new_paddle1_Y  < borderWidth) { // Top Frame
				new_paddle1_Y = borderWidth;
			}
			if(new_paddle1_Y + paddleH > GLCD_HEIGHT - borderWidth) { // Bottom Frame
				new_paddle1_Y = GLCD_HEIGHT - borderWidth - paddleH;
			}

			joyMsk = Joystick_GetState();   // Show joystick arrows               
				if (joy ^ joyMsk)                
					{
						joy = joyMsk;

						if(joy & JOYSTICK_LEFT)
						{
							if(ballVelocityX > 0)
							{
								ballVelocityX--;
							}
							else
							{
								ballVelocityX++;
							}
							
							if(ballVelocityY > 0)
							{
								ballVelocityY--;
							}
							else
							{
								ballVelocityY++;
							}
						}
						if(joy & JOYSTICK_RIGHT)
						{
							if(ballVelocityX > 0)
							{
								ballVelocityX++;
							}
							else
							{
								ballVelocityX--;
							}
							
							if(ballVelocityY > 0)
							{
								ballVelocityY++;
							}
							else
							{
								ballVelocityY--;
							}
						}
						if(joy & JOYSTICK_CENTER)
						{
							
						}
						if(joy & JOYSTICK_UP)
						{						
							GLCD_SetForegroundColor(BackgroundColor);
							GLCD_DrawRectangle(old_ball_X, old_ball_Y, ball_rad, ball_rad);
							GLCD_SetForegroundColor(BallForegroundColor);
							ball_rad++;
						}
						if(joy & JOYSTICK_DOWN)
						{
							GLCD_SetForegroundColor(BackgroundColor);
							GLCD_DrawRectangle(old_ball_X, old_ball_Y, ball_rad, ball_rad);
							GLCD_SetForegroundColor(BallForegroundColor);
							ball_rad--;
						}	
				}
				
			if(new_ball_X > GLCD_WIDTH)
			{
				score0++;
				appPongState = Lose;
			}		
			
			if(new_ball_X < 0)
			{
				score1++;
				appPongState = Lose;
			}
			
			// Draw the Pong Field					
			
			//STATIC OBJECTS
			// Draw an outline of the screen:
			GLCD_SetForegroundColor(ForegroundColor);
			GLCD_DrawRectangle(0, 0, GLCD_WIDTH - 1, GLCD_HEIGHT - 1);
			// Draw the center line
			GLCD_DrawRectangle(GLCD_WIDTH/2 - 1, 0, borderWidth, GLCD_HEIGHT);	
			
			//MOVING OBJECTS		
			GLCD_SetForegroundColor(BackgroundColor);
			// Erase the Paddles:
			GLCD_DrawRectangle(old_paddle0_X, old_paddle0_Y, paddleW, paddleH);
			GLCD_DrawRectangle(old_paddle1_X, old_paddle1_Y, paddleW, paddleH);
			// Erase the ball:
			GLCD_DrawRectangle(old_ball_X, old_ball_Y, ball_rad, ball_rad);
			
			old_paddle0_X = new_paddle0_X;
			old_paddle0_Y = new_paddle0_Y;
			old_paddle1_X = new_paddle1_X;
			old_paddle1_Y = new_paddle1_Y;
			old_ball_X = new_ball_X;
			old_ball_Y = new_ball_Y;
			
			// Draw the Paddles:
			GLCD_SetForegroundColor(LeftPaddleForegroundColor);
			GLCD_DrawRectangle(new_paddle0_X, new_paddle0_Y, paddleW, paddleH);
			
			GLCD_SetForegroundColor(RightPaddleForegroundColor);					
			GLCD_DrawRectangle(new_paddle1_X, new_paddle1_Y, paddleW, paddleH);
			// Draw the ball:
			GLCD_SetForegroundColor(BallForegroundColor);	
			GLCD_DrawRectangle(new_ball_X, new_ball_Y, ball_rad, ball_rad);
			
			sprintf (str_score0, "%1u", score0); //takes the numeric value and convert it to a char with the %1u format (1 unit unsigned)
			sprintf (str_score1, "%1u", score1);
			str_score0[sizeof(str_score0)-1] = '\0'; //indicate end of string
			str_score1[sizeof(str_score1)-1] = '\0';
			GLCD_SetForegroundColor(LeftPaddleForegroundColor);
			GLCD_DrawString(5, 5, str_score0);
			GLCD_SetForegroundColor(RightPaddleForegroundColor);
			GLCD_DrawString((GLCD_WIDTH/2)+5, 5,  str_score1);
		
			break;
			
		case Lose:
			if(score0 >= SCORE_MAX_PONG || score1 >= SCORE_MAX_PONG)
			{
				appPongState = GameOver;
				break;
			}

			InitializeAppPong();
			break;
			
		case GameOver:
			GLCD_SetFont            (&GLCD_Font_16x24);
			if(score0 > score1)
			{
				GLCD_SetForegroundColor(GLCD_COLOR_BLUE);
				GLCD_DrawString((((GLCD_WIDTH/2)-(16*6))/2), GLCD_HEIGHT/2, "WIN !");
				GLCD_SetForegroundColor(GLCD_COLOR_GREEN);
				GLCD_DrawString((((GLCD_WIDTH/2)-(16*6))/2) + (GLCD_WIDTH/2), GLCD_HEIGHT/2, "LOSE !");
			}
			else
			{
				GLCD_SetForegroundColor(GLCD_COLOR_GREEN);
				GLCD_DrawString((((GLCD_WIDTH/2)-(16*6))/2) + (GLCD_WIDTH/2), GLCD_HEIGHT/2, "WIN !");
				GLCD_SetForegroundColor(GLCD_COLOR_BLUE);
				GLCD_DrawString((((GLCD_WIDTH/2)-(16*6))/2), GLCD_HEIGHT/2,  "LOSE !");
			}			
			
			score0 = 0;
			score1 = 0;
			osDelay(2000);
			menuChoice = InitMenu;

			osThreadTerminate (idThreadBeep);
			break;
	}	
			
}
Пример #4
0
void AppShooter()
{
	  while (!stopShooter) {

		joyMsk = Joystick_GetState();
		btnMsk = Buttons_GetState();

		if (timerTick_01 > 2)
		{
			if (ballTimer != 0) { ballTimer--; }
			if ( ((btnMsk & 1) != 0) && (ballTimer == 0) )
			{
				ballTimer = 8;
				newBall = true;
			}
			
			if (joyMsk != 0)
			{
				osMutexWait(planeVar_mutex_id, osWaitForever);
				// RIGHT
				if ((plane_x < GLCD_WIDTH - 10) && ((joyMsk & 2) != 0))
				{
					plane_x += 10;
				}
				// LEFT
				if ((plane_x > 0) && ((joyMsk & 1) != 0))
				{
					plane_x -= 10;
				}
				// UP
				if ((plane_y > 20) && ((joyMsk & 8) != 0))
				{
					plane_y -= 10;
				}
				// DOWN
				if ((plane_y < GLCD_HEIGHT - 10) && ((joyMsk & 16) != 0))
				{
					plane_y += 10;
				}
				osMutexRelease(planeVar_mutex_id);
			}
			timerTick_01 = 0;
			S_MoveBall(newBall);
			newBall = false;
		}	
		
		if ( timerTick_02 > 12 )
		{
			S_MoveObjects ();
			timerTick_02 = 0;
			
		}
  }

	osThreadTerminate (idThreadPlane);
	osDelay(500);
	
	if (playerScore > machineScore) {
		GLCD_SetForegroundColor (GLCD_COLOR_GREEN);
		GLCD_DrawString ((GLCD_WIDTH-16*9)/2, GLCD_HEIGHT/2-16, "YOU WIN !");
	} else {
		GLCD_SetForegroundColor (GLCD_COLOR_RED);
		GLCD_DrawString ((GLCD_WIDTH-16*11)/2, GLCD_HEIGHT/2-16, "YOU LOSE !");
	}
	osDelay(2000);
	
}