コード例 #1
0
ファイル: Game.c プロジェクト: volpi3000/U23-Library
void Update(uint32_t delta)
{
	snes_button_state_t state = GetControllerState();
	myframe++;
	if (state.buttons.Up)
		ChangeState(TheGame, &RedState);
}
コード例 #2
0
void g2Slider::Render(int pX, int pY)
{
    // Center on the vertical the user's slider controller
    int SliderWidth, SliderHeight;
    int ControllerHeight;
    GetTheme()->GetComponentSize(g2Theme_SliderButton, &SliderWidth, &SliderHeight);
    GetTheme()->GetComponentSize(g2Theme_Slider, NULL, &ControllerHeight);
    
    // Which is the total height? We may need to shift the slider's background
    // since some slider buttons are taller than the bg
    int TotalHeight = SliderHeight;
    if(ControllerHeight > TotalHeight)
        TotalHeight = ControllerHeight;
    
    // Render the centered background
    DrawComponentStretch(g2Theme_Slider, pX, pY + TotalHeight / 2 - ControllerHeight / 2, Width);
    
    // Draw slider button
    g2ThemeElement ButtonStyle = g2Theme_SliderButton;
    if(GetDisabled())
        ButtonStyle = g2Theme_SliderButton_Disabled;
    else if(IsDragging || GetControllerState() == g2ControllerState_Pressed)
        ButtonStyle = g2Theme_SliderButton_Pressed;
    
    // Computer offsets
    float ProgressRatio = Progress / fabs(MaxBound - MinBound);
    int OffsetX = g2Slider_SidePixelBuffer + int(float(Width - 2 * g2Slider_SidePixelBuffer) * ProgressRatio) - SliderWidth / 2;
    
    // Draw the slider button itself
    DrawComponent(ButtonStyle, pX + OffsetX, pY + TotalHeight / 2 - SliderHeight / 2);
}
コード例 #3
0
ファイル: g2RadioGroup.cpp プロジェクト: blast007/glui2
void g2RadioGroup::MouseClick(g2MouseButton button, g2MouseClick state, int x, int y)
{
    // If we had a full key-press event within our collision box, change the active index as needed
    if(InController(x, y) && ((GetControllerState() & g2ControllerState_Clicked) == g2ControllerState_Clicked))
    {
        // Get the size of a radio button
        int RadioHeight;
        GetTheme()->GetComponentSize(g2Theme_RadioButton, NULL, &RadioHeight);
        
        // For each radio button..
        for(int i = 0; i < OptionCount; i++)
        {
            // What is the y pos of this row?
            int BottomRow = i * (RadioHeight + 1) + RadioHeight;
            if(y < BottomRow)
            {
                ActiveIndex = i;
                break;
            }
        }
        
        // Update the live index
        if(LiveIndex !=  NULL)
            *LiveIndex = ActiveIndex;
    }
    
}
コード例 #4
0
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool IsControllerConnected( const int controllerNumber )
{
	XINPUT_STATE xboxControllerState;
	DWORD errorStatus = GetControllerState( controllerNumber, xboxControllerState );

	if( errorStatus == ERROR_DEVICE_NOT_CONNECTED )
		return false;
	return true;
}
コード例 #5
0
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool IsRBButtonDown( const int controllerNumber )
{
	XINPUT_STATE xboxControllerState;
	DWORD errorStatus = GetControllerState( controllerNumber, xboxControllerState );

	if( errorStatus == ERROR_SUCCESS )
	{
		return BIT_RB_BUTTON & xboxControllerState.Gamepad.wButtons;
	}
	return false;
}
コード例 #6
0
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool IsDpadSouthWestButtonDown( const int controllerNumber )
{
	XINPUT_STATE xboxControllerState;
	DWORD errorStatus = GetControllerState( controllerNumber, xboxControllerState );

	if( errorStatus == ERROR_SUCCESS )
	{
		return BIT_DPAD_SOUTHWEST_BUTTON & xboxControllerState.Gamepad.wButtons;
	}
	return false;
}
コード例 #7
0
ファイル: g2Spinner.cpp プロジェクト: blast007/glui2
void g2Spinner::Update(float dT)
{
    // Get controller state
    ControllerState = GetControllerState();
    
    // If we are being pressed, update the timer
    if((ControllerState & g2ControllerState_Pressed) == g2ControllerState_Pressed)
        PressedTime += dT;
    // Else, we aren't pressing, so ignore
    else
        PressedTime = 0.0f;
}
コード例 #8
0
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
float GetNormalizedLeftTriggerInput( const int controllerNumber )
{
	XINPUT_STATE xboxControllerState;
	DWORD errorStatus = GetControllerState( controllerNumber, xboxControllerState );

	float triggerInput = 0.0f;
	if( errorStatus == ERROR_SUCCESS )
	{
		triggerInput = (float) xboxControllerState.Gamepad.bLeftTrigger;

		triggerInput = RangeMap( triggerInput, TRIGGER_MIN_VALUE, TRIGGER_MAX_VALUE, 0.0f, 1.0f );
	}

	return triggerInput;
}
コード例 #9
0
void g2Controller::__MouseClick(g2MouseButton button, g2MouseClick state, int x, int y)
{
    // Ignore if not visible
    if(!GetVisibility())
        return;
    
    // Update mouse to localized positions
    x -= pX;
    y -= pY;
    
    // Are we in this object's volume and do we have a full left-click?
    if(InController(x, y) && button == g2MouseButton_Left && state == g2MouseClick_Down)
        ControllerState = g2ControllerState_Pressed;
    
    // Else, if there is a mouse release AND we are coming from a pressed state....
    else if(InController(x, y) && button == g2MouseButton_Left && state == g2MouseClick_Up && ControllerState == g2ControllerState_Pressed)
        ControllerState = g2ControllerState_Clicked;
    
    // Else, reset to either hover or none...
    else if(InController(x, y))
        ControllerState = g2ControllerState_Hover;
    
    // Else, no hovering, just nothing
    else
        ControllerState = g2ControllerState_None;
    
    // Update mouse click
    MouseClick(button, state, x, y);
    
    // Update all children
    int QueueSize = (int)ChildObjects.size();
    for(int i = 0; i < QueueSize; i++)
    {
        // Get child
        g2Controller* Child = ChildObjects.front();
        ChildObjects.pop();
        
        // Update child window event
        Child->__MouseClick(button, state, x, y);
        
        // Put back
        ChildObjects.push(Child);
    }
    
    // Execute callback
    if(!GetDisabled() && GetControllerState() == g2ControllerState_Clicked && PressedCallback != 0)
        PressedCallback(this);
}
コード例 #10
0
ファイル: game.c プロジェクト: yxrkt/DigiPen
//**************//
// Title Update //
//**************//
int GSTitleProc()
{
    static int trans = FALSE;
    
    if (trans)
    {
        int done = FadeBG();
        trans = (done) ? FALSE : TRUE;
        return done;
    }
    
    else
    {
        // get controller state
        struct ControllerState controller = GetControllerState();
        
        // begin fading transition if start is pressed
        trans = (controller.start) ? TRUE : FALSE;
        
        return 0;
    }
}
コード例 #11
0
ファイル: Main.c プロジェクト: G33KatWork/U23-Library
int main()
{
	RCC_ClocksTypeDef RCC_Clocks;
	RCC_GetClocksFreq(&RCC_Clocks);

	SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);

	InitializeLEDs();
	MyUSART_Init();

	setvbuf(stdout, 0, _IONBF, 0);
	printf("Hello!\r\n");

	InitializeSnesController();

	while(1)
	{
		snes_button_state_t btn = GetControllerState();
		printf("SNES: %02X\r\n", btn.raw);
		printf(
			"%s %s %s %s %s %s %s %s %s %s %s %s\r\n",
			btn.buttons.A ? "A" : "",
			btn.buttons.B ? "B" : "",
			btn.buttons.X ? "X" : "",
			btn.buttons.Y ? "Y" : "",
			btn.buttons.L ? "L" : "",
			btn.buttons.R ? "R" : "",
			btn.buttons.Start ? "Start" : "",
			btn.buttons.Select ? "Select" : "",
			btn.buttons.Left ? "Left" : "",
			btn.buttons.Up ? "Up" : "",
			btn.buttons.Down ? "Down" : "",
			btn.buttons.Right ? "Right" : ""
		);

		SetLEDs(btn.buttons.A << 3 | btn.buttons.B << 2 | btn.buttons.X << 1 | btn.buttons.Y);
	}
}
コード例 #12
0
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
const Vector2 GetNormalizedRightStickInput( const int controllerNumber )
{
	XINPUT_STATE xboxControllerState;
	DWORD errorStatus = GetControllerState( controllerNumber, xboxControllerState );

	Vector2 stickInput( 0.0f, 0.0f );
	if( errorStatus == ERROR_SUCCESS )
	{
		float stickInputX = (float) xboxControllerState.Gamepad.sThumbRX;
		float stickInputY = (float) xboxControllerState.Gamepad.sThumbRY;

		stickInputX = RangeMap( stickInputX, STICK_MIN_VALUE, STICK_MAX_VALUE, -1.0f, 1.0f );
		stickInputY = RangeMap( stickInputY, STICK_MIN_VALUE, STICK_MAX_VALUE, -1.0f, 1.0f );

		stickInput.SetXY( stickInputX, stickInputY );

		if( stickInput.CalcLength() < STICK_DEADZONE_THRESHOLD )
			stickInput.SetXY( 0.0f, 0.0f );

	}

	return stickInput;
}
コード例 #13
0
ファイル: game.c プロジェクト: yxrkt/DigiPen
//******************//
// Helper Functions //
//******************//
void Move()
{
    struct ControllerState cont = GetControllerState();
    bool moving = FALSE;
    
    // move player
    if ( cont.left  )
    {
        if ( g_cam_x > 0 && ((g_hippy.x + g_hippy.w / 2) == (SCREEN_WIDTH / 2)) )
            HScroll(-WALK_SPEED);
        else if ( g_hippy.x > 0 )
            g_hippy.x -= WALK_SPEED;

        g_hippy.baseFrame = FACE_SIDE;
        ham_SetObjHFlip(g_hippy.sprite, FALSE);
        moving = TRUE;
    }
    if ( cont.right  )
    {
        if ( g_cam_x < (MAP_WIDTH - SCREEN_WIDTH - 1) && ((g_hippy.x + g_hippy.w / 2) == (SCREEN_WIDTH / 2)) )
            HScroll(WALK_SPEED);
        else if ( g_hippy.x < (SCREEN_WIDTH - g_hippy.w) )
            g_hippy.x += WALK_SPEED;

        if ( !moving )
        {
            g_hippy.baseFrame = FACE_SIDE;
            ham_SetObjHFlip(g_hippy.sprite, TRUE);
            moving = TRUE;
        }
    }
    if ( cont.up  )
    {
        if ( g_cam_y > 0 && ((g_hippy.y + g_hippy.h / 2) == (SCREEN_HEIGHT / 2)) )
            VScroll(-WALK_SPEED);
        else if ( g_hippy.y > 0 )
            g_hippy.y -= WALK_SPEED;

        if ( !moving )
        {
            g_hippy.baseFrame = FACE_UP;
            moving = TRUE;
        }
    }
    if ( cont.down  )
    {
        if ( g_cam_y < (MAP_HEIGHT - SCREEN_HEIGHT - 1) && ((g_hippy.y + g_hippy.h / 2) == (SCREEN_HEIGHT / 2)) )
            VScroll(WALK_SPEED);
        else if ( g_hippy.y < (SCREEN_HEIGHT - g_hippy.h) )
            g_hippy.y += WALK_SPEED;

        if ( !moving )
        {
            g_hippy.baseFrame = FACE_DOWN;
            moving = TRUE;
        }
    }

    // move player
    ham_SetBgXY(0, g_cam_x, g_cam_y);
    ham_SetObjXY(g_hippy.sprite, g_hippy.x, g_hippy.y);
    
    // move shroom
    ham_SetObjXY(g_shroom.sprite, g_shroom.x, g_shroom.y);
    
    // move key
    ham_SetObjXY(g_key.sprite, g_key.x, g_key.y);
    
    // set hippy frame
    int animIndex = g_hippy.w * g_hippy.h * (g_hippy.baseFrame + g_hippy.frameDif);
    ham_UpdateObjGfx(g_hippy.sprite, (void *)&hippy_bitmap[animIndex]);
    
    g_count++;
    if ( moving && ((g_count % HIPPY_TPF) == 0) )
        g_hippy.frameDif =(g_hippy.frameDif + 1) % HIPPY_FRAMES;
}