Exemple #1
0
static int key_press_event(XKeyEvent *event)
{
	if (event->keycode == mmkeys.raise_volume) {
		mixer_set_volume_rel(config.scrollstep);
		if (!osd_mapped())
			map_osd();
		if (osd_mapped())
			update_osd(mixer_get_volume(), false);
		ui_update();
		return 1;
	}
	if (event->keycode == mmkeys.lower_volume) {
		mixer_set_volume_rel(-config.scrollstep);
		if (!osd_mapped())
			map_osd();
		if (osd_mapped())
			update_osd(mixer_get_volume(), false);
		ui_update();
		return 1;
	}
	if (event->keycode == mmkeys.mute) {
		mixer_toggle_mute();
		ui_update();
		return 1;
	}

	/* Ignore other keys */
	return 0;
}
Exemple #2
0
static void motion_event(XMotionEvent *event)
{
    int x = event->x;
    int y = event->y;
    int region;

    if ((x == mouse_drag_home_x) && (y == mouse_drag_home_y))
	return;

    region = check_region(x, y);

    if (button_pressed) {
	if (y != mouse_drag_home_y) {
	    float delta;

	    set_cursor(NULL_CURSOR);

	    delta = (float)(mouse_drag_home_y - y) / display_height;
	    knob_turn(delta);
	    if (!osd_mapped())
		map_osd();
	    if (osd_mapped())
		update_osd(mixer_get_volume(), false);
	}
	XWarpPointer(display, None, event->window, x, y, 0, 0,
			mouse_drag_home_x, mouse_drag_home_y);
	return;
    }

    if (slider_pressed) {
	if (x != mouse_drag_home_x) {
	    float delta;

	    set_cursor(NULL_CURSOR);

	    delta = (float)(x - mouse_drag_home_x) / display_width;
	    slider_move(delta);
	}
	XWarpPointer(display, None, event->window, x, y, 0, 0,
			mouse_drag_home_x, mouse_drag_home_y);
	return;
    }

    if (region == 1)
	set_cursor(HAND_CURSOR);
    else if (region == 2)
	set_cursor(BAR_CURSOR);
    else
	set_cursor(NORMAL_CURSOR);
}
Exemple #3
0
static void signal_catch(int sig)
{
    switch (sig) {
	case SIGUSR1:
	    mixer_set_volume_rel(config.scrollstep);
	    if (!osd_mapped())
		map_osd();
	    if (osd_mapped())
		update_osd(mixer_get_volume(), false);
	    ui_update();
	    idle_loop = 0;
	    break;
	case SIGUSR2:
	    mixer_set_volume_rel(-config.scrollstep);
	    if (!osd_mapped())
		map_osd();
	    if (osd_mapped())
		update_osd(mixer_get_volume(), false);
	    ui_update();
	    idle_loop = 0;
	    break;
    }
}
Exemple #4
0
static void button_press_event(XButtonEvent *event)
{
    double button_press_time = get_current_time();
    int x = event->x;
    int y = event->y;
    bool double_click = false;

    /* handle wheel scrolling to adjust volume */
    if (config.mousewheel) {
	if (event->button == config.wheel_button_up) {
	    mixer_set_volume_rel(config.scrollstep);
	    if (!osd_mapped())
		map_osd();
	    if (osd_mapped())
		update_osd(mixer_get_volume(), false);
	    ui_update();
	    return;
	}
	if (event->button == config.wheel_button_down) {
	    mixer_set_volume_rel(-config.scrollstep);
	    if (!osd_mapped())
		map_osd();
	    if (osd_mapped())
		update_osd(mixer_get_volume(), false);
	    ui_update();
	    return;
	}
    }

    if ((button_press_time - prev_button_press_time) <= 0.5) {
	double_click = true;
	prev_button_press_time = 0.0;
    } else
	prev_button_press_time = button_press_time;

    switch (check_region(x, y)) {
	case 1:			/* on knob */
	    button_pressed = true;
	    slider_pressed = false;
	    mouse_drag_home_x = x;
	    mouse_drag_home_y = y;
	    if (double_click) {
		mixer_toggle_mute();
		ui_update();
	    }
	    break;
	case 2:			/* on slider */
	    button_pressed = false;
	    slider_pressed = true;
	    mouse_drag_home_x = x;
	    mouse_drag_home_y = y;
	    if (double_click) {
		mixer_set_balance(0.0);
		ui_update();
	    }
	    break;
	case 3:			/* previous channel */
	    mixer_set_channel_rel(-1);
	    blit_string(config.scrolltext ? mixer_get_channel_name() : mixer_get_short_name());
	    scroll_text(3, 4, 57, true);
	    unmap_osd();
	    map_osd();
	    ui_update();
	    break;
	case 4:			/* next channel */
	    mixer_set_channel_rel(1);
	    blit_string(config.scrolltext ? mixer_get_channel_name() : mixer_get_short_name());
	    scroll_text(3, 4, 57, true);
	    unmap_osd();
	    map_osd();
	    ui_update();
	    break;
	case 5:			/* toggle mute */
	    mixer_toggle_mute();
	    ui_update();
	    break;
	case 6:			/* toggle rec */
	    mixer_toggle_rec();
	    ui_update();
	    break;
	case 10:
	    scroll_text(3, 4, 57, true);
	    break;
	default:
	    printf("unknown region pressed\n");
	    break;
    }
}
Exemple #5
0
/*
--------------------------------------------------------------------------------
                                  UPDATE MAIN
--------------------------------------------------------------------------------
 *  This function updates stuff on the main screen (during gameplay).
*/
void update_main( void )
{
    /*  Warp speed update */
    if( warp )
        warp_update();

    /*  Tail update */
    if( tail.is_active() || tail.is_fading() )
    {
        tail.update();
    }

    /*  Add a few enemies */
    if( enemyDelay >= 120 )
    {
        /*
         *  Every tick (60 per second by default), there is a one in
         *  (15 * warpSpeed) chance that the program will 'consider' spawning
         *  an enemy.
         */
        for( int i = 0; i < ( rand() % ( 15 * warpSpeed ) ) + 1; ++i )
        {
            /*  If the player is is not powered, 1/80 chance of an enemy */
            if( ! player.is_powered() )
            {
                if( rand() % 80 == 0 )
                    load_enemy();
            }

            /*  If they are powered, 1/40 chance (more enemies) */
            else
            {
                if( rand() % 40 == 0 )
                    load_enemy();
            }
        }
    }

    /*  Tilt the player's ship according to movement */
    player.tilt();

    /*  Get the player's general area/position */
    SDL_Rect pRect = player.get_rect();

    /*  Update the enemies */
    if( enemies.size() > 0 )
    {
        /*  Create the enemies vector iterator */
        std::vector<Enemy>::iterator enemy;

        /*  Update the enemies */
        for( enemy = enemies.begin(); enemy != enemies.end(); )
        {
            /*  Update the enemy (movement, etc.) */
            enemy->update();

            /*  Get the enemy's general rectangle */
            SDL_Rect eRect = enemy->get_rect();      //  lololol erect

            /*  If the player and enemy are in very close proximity */
            if( check_collision_box( pRect, eRect ) )
            {
                /*  If the player honks at the asteroid */
                if( player.is_honking() )
                    enemy->kiss();

                /*  Grab the player's colliders vector */
                std::vector<Collider> pCollider = player.get_pixel_collider(
                        player.get_current_frame() );
                
                /*  Grab this enemy's colliders vector */
                std::vector<Collider> eCollider = enemy->get_pixel_collider(
                        enemy->get_current_frame() );


                /*  Check for collision between the sets of colliders */
                if( check_collision_colliders( pCollider, eCollider ) )
                {
                    /*  If the player is powered up, destroy the enemy */
                    if( player.is_powered() )
                        enemy->kill();

                    //  Otherwise, under normal circumstances, kill the player
                    else if( player.is_alive() &&
                            enemy->is_alive() &&
                            ! player.is_invulnerable() )
                    {
                        player.kill();
                    }
                }
            }

            /*  If the enemy has gone beyond the visible play area, erase it */
            if( enemy->get_pos_y() > BHEIGHT )
                enemies.erase( enemy );

            /*  If the enemy is dead and gone, erase it */
            else if( ! enemy->is_alive() && ! enemy->is_exploding() )
                enemies.erase( enemy );

            /*  Otherwise, move on to the next enemy in the vector */
            else
                ++enemy;
        }
    }


    /*  If the player is alive and doesn't have respawn invuln */
    if( player.is_alive() && 
            ( player.is_powered() || ! player.is_invulnerable() ) )
    {
        /*  Update the main score */
        if( currentScore < 1e10 )   //  Max score:  999,999,999
            ++currentScore;

        /*  Update the other score trackers */
        if( ! player.is_powered() && chargeScore < 1e10 )
            ++chargeScore;
        if( extraLifeScore < 1e10 )
            ++extraLifeScore;

        /*  Update the player's charge meter */
        if( chargeScore >= 1000 )
        {
            player.increment_charge();
            chargeScore -= 1000;
        }

        /*  If the player has enough points, increase life */
        if( extraLifeScore >= 20000 )
        {
            player.increment_lives();
            extraLifeScore -= 20000;
        }
    }

    /*  If applicable, update player power status */
    if( player.is_powered() )
        player.power_update();

    /*  Update score string and texture */
    snprintf( currentScoreString, 9, "%06d", currentScore );
    scoreText->create_texture_from_string( gFontTiny, currentScoreString,
            colors[ COLOR_WHITE ] );

    /*  Wait a couple of seconds before spawning enemies */
    if( enemyDelay < 121 )
        ++enemyDelay;

    /*  Update the starfield */
    starfield->update();

    /*  The player update function - just controls the honk, really */
    player.update();

    /*  Create an iterator for the 'atari' explosions vector */
    std::vector<AtariExplosion>::iterator a;

    /*  Iterate through the vector */
    for( a = aExplosions.begin(); a != aExplosions.end(); )
    {
        /*  Erase the ones that are dead */
        if( a->is_done() )
            aExplosions.erase( a );

        /*  Update the ones that aren't, then move on */
        else
        {
            a->update( player.get_special_color() );
            ++a;
        }
    }

    /*  We do this here so that the pause menu will display the correct text */
    if( gamePaused )
        gamePaused = false;

    /*  If the OSD isn't null, update it */
    update_osd();

    /*  Update the kissKills object */
    kissKills.update();

}