Esempio n. 1
0
void MainLoop::key_pressed(int key)
{
    if ( state == COUNTDOWN )
    {
        switch (key)
        {
        case ALLEGRO_KEY_RIGHT:
            if(!done_selecting)
                color_selector.select_color_right();
            break;
        case ALLEGRO_KEY_LEFT:
            if(!done_selecting)
                color_selector.select_color_left();
            break;
        
        case ALLEGRO_KEY_ENTER:
            done_selecting = true;
            break;
        case ALLEGRO_KEY_SPACE:
            done_selecting = true;
            break;
        }
    }
    if ( state == SPLASH_SCREEN )
    {
        switch (key)
        {
        case ALLEGRO_KEY_ENTER:
            state = INSTRUCTIONS;
            start_countdown(2);
            break;
        }
    }
    if ( state == GAME_OVER )
    {
        switch (key)
        {
        case ALLEGRO_KEY_ENTER:
            state = LEVEL_NAME;
            level = Level();
            level.next_level();
            done_selecting = false;
            start_countdown(2);
            break;
        }
    }
}
Esempio n. 2
0
// *************************************************************************************************
// @fn          wakeup_event
// @brief       Process external / internal wakeup events.
// @param       none
// @return      none
// *************************************************************************************************
void wakeup_event(void)
{
	// Enable idle timeout
	sys.flag.idle_timeout_enabled = 1;

	// If buttons are locked, only display "buttons are locked" message
	if (button.all_flags && sys.flag.lock_buttons)
	{
		// Show "buttons are locked" message synchronously with next second tick
		if (!(BUTTON_NUM_IS_PRESSED && BUTTON_DOWN_IS_PRESSED))
		{
			message.flag.prepare     = 1;
			message.flag.type_locked = 1;
		}
		
		// Clear buttons
		button.all_flags = 0;	
	}
	// Process long button press event (while button is held)
	else if (button.flag.up_long)
	{
		// Clear button event
		button.flag.up_long = 0;

		// Call sub menu function
		//ptrMenu_L1->mx_function(LINE1);

		// Set display update flag
		//display.flag.full_update = 1;
	}
	else if (button.flag.down_long)
	{
		// Clear button event
		button.flag.down_long = 0;

		// Call sub menu function
		//ptrMenu_L2->mx_function(LINE2);

		// Stop Countdown and Countup
		stop_countdown();
		stop_countup();

		// Reset Countdown and Countup
		reset_countdown();
		reset_countup();

		// Set display update flag
		display.flag.full_update = 1;	
	}
	// Process single button press event (after button was released)
	else if (button.all_flags)
	{
		// M1 button event ---------------------------------------------------------------------
		// (Short) Advance to next menu item
		if(button.flag.star) 
		{
			/*
			// SW1 IS NOW LOCATED IN PORTS.C FOR IMPROVED RESPONSE
			*/

			// Clean up display before activating next menu item 
			//fptr_lcd_function_line1(LINE1, DISPLAY_LINE_CLEAR);
			
			// Go to next menu entry
			//ptrMenu_L1 = ptrMenu_L1->next;
				
			// Assign new display function
			//fptr_lcd_function_line1 = ptrMenu_L1->display_function;

			// Set Line1 display update flag
			//display.flag.line1_full_update = 1;

			// Clear button flag
			button.flag.star = 0;
		}
		// NUM button event ---------------------------------------------------------------------
		// (Short) Advance to next menu item
		else if(button.flag.num || button.flag.num_long)
		{
			// SW2
			// Enable buzzer
			sCountdown.buzzer = 1;

			// Clean up display before activating next menu item 
			//fptr_lcd_function_line2(LINE2, DISPLAY_LINE_CLEAR);

			// Go to next menu entry
			//ptrMenu_L2 = ptrMenu_L2->next;

			// Assign new display function
			//fptr_lcd_function_line2 = ptrMenu_L2->display_function;

			// Set Line2 display update flag
			//display.flag.line2_full_update = 1;

			// Clear button flag
			button.flag.num_long = 0;
			button.flag.num = 0;
		}	
		// UP button event ---------------------------------------------------------------------
		// Activate user function for Line1 menu item
		else if(button.flag.up) 	
		{
			// Call direct function
			//ptrMenu_L1->sx_function(LINE1);

			// UP BUTTON
			// Start / pause / reset Countdown and Countup
			if (sCountdown.mode == COUNTDOWN_MODE_OFF || sCountdown.mode == COUNTDOWN_MODE_RESET)
			{
				if (sCountdown.minute == 0 && sCountdown.second == 0 || sCountup.minute == 10 && sCountup.second == 0)
				{
					reset_countdown();
					reset_countup();
					display.flag.full_update = 1;
				}
				else {
					// Start Countdown and Countup
					start_countdown();
					start_countup();
				}
			}
			else
			{
				// Stop Countdown and Countup
				stop_countdown();
				//stop_countup();
			}


			// Set Line1 display update flag
			//display.flag.line1_full_update = 1;
	
			// Clear button flag	
			button.flag.up = 0;
		}			
		// DOWN button event ---------------------------------------------------------------------
		// Activate user function for Line2 menu item
		else if(button.flag.down) 	
		{
			// Call direct function
			//ptrMenu_L2->sx_function(LINE2);

			// DOWN BUTTON
			// Enable power saving using drawFlag
			sCountdown.drawFlag = 1;

			// When in COUNTDOWN_MODE_RESET state, allow alteration of Countdown start point
			if (sCountdown.mode == COUNTDOWN_MODE_RESET)
			{
				// Decrement minutes
				sCountdown.minute--;

				// Stop decrements at 0 or below
				if (sCountdown.minute == 0)
				{
					sCountdown.minute = 10;
				}

				sCountdown.drawFlag = 2;
				display.flag.update_countdown = 1;
			}

			// Set Line1 display update flag
			//display.flag.line2_full_update = 1;
	
			// Clear button flag	
			button.flag.down = 0;
		}			
	}
	
	// Process internal events
	if (sys.all_flags)
	{
		// Idle timeout ---------------------------------------------------------------------
		if (sys.flag.idle_timeout)
		{
			// Clear timeout flag	
			sys.flag.idle_timeout = 0;	
			
			// Clear display
			clear_display();	

			// Set display update flags
			display.flag.full_update = 1;
		}
	}
	
	// Disable idle timeout
	sys.flag.idle_timeout_enabled = 0;
}
Esempio n. 3
0
bool MainLoop::tick()
{
    switch(state) {
    case SPLASH_SCREEN:
        break;
    case INSTRUCTIONS:
        if (countdown_value-- < 0)
        {
            state = LEVEL_NAME;
            level.next_level();
            start_countdown(1);
        }
        break;
    case LEVEL_NAME:
        if (countdown_value-- < 0)
        {
            state = COUNTDOWN;
            start_countdown(10);

            color_selector.set_num_colors(level.get_num_colors());
            done_selecting=false;
        }
        break;
    case COUNTDOWN:
        strongest_color = level.strongest_color();

        if (done_selecting)
        {
            state = REMOVE_BLOCKS;
            break;
        }
        if (countdown_value <= 0)
        {
            state = REMOVE_BLOCKS;
            break;
        }

        countdown_value--;
        alpha = (countdown_value%60) > 30 ? 255 : (countdown_value%60)*(255/30);
        switch (countdown_value/60)
        {
        case 9: countdown_text[0] = ' '; break;
        case 8: countdown_text[0] = ' '; break;
        case 7: countdown_text[0] = ' '; break;
        case 6: countdown_text[0] = ' '; break;
        case 5: countdown_text[0] = ' '; break;
        case 4: countdown_text[0] = '5'; break;
        case 3: countdown_text[0] = '4'; break;
        case 2: countdown_text[0] = '3'; break;
        case 1: countdown_text[0] = '2'; break;
        default: countdown_text[0] = '1'; break;
        }
        
        if (countdown_value/60 > 0 && countdown_value/60 < 6 && (countdown_value % 60) == 0)
        {
            al_play_sample(alert, 1, 0, 1, ALLEGRO_PLAYMODE_ONCE,NULL);
        }
        
        break;
    case REMOVE_BLOCKS:
    {
        bool removed = level.remove_blocks();
        int c = color_selector.get_selected_color();
        if (!removed && strongest_color == c)
        {
            state = NEXT_LEVEL;
            al_play_sample(win, 1, 0, 1, ALLEGRO_PLAYMODE_ONCE,NULL);
        }
        else if (!removed)
        {
            state = GAME_OVER;      
        }
        break;
    }
    case GAME_OVER:
    {
        break;
    }

    case NEXT_LEVEL:
    {

        state = LEVEL_NAME;
        level.next_level();
        start_countdown(2);

        break;
    }
    
    }
    return false;
}