void drawClock(int hours, int minutes, int seconds) { //get current cursor positon uint32_t prev_xPos = GetXPos(); uint32_t prev_yPos = GetYPos(); //move the curser to the top left GotoXY(0,0); //show hours if (hours <= 9) { DisplayInteger(0); } DisplayInteger(hours); DisplayChar(':'); //show minutes if (minutes <= 9) { DisplayInteger(0); } DisplayInteger(minutes); DisplayChar(':'); //show seconds if (seconds <= 9) { DisplayInteger(0); } DisplayInteger(seconds); //reset the cursor to it's previous position GotoXY(prev_xPos, prev_yPos); }
//----------------------------------------------------------------------------- // Purpose: Set whether the ship is exploding //----------------------------------------------------------------------------- void CShip::SetExploding( bool bExploding ) { // If we are already in the specified state, no need to do the below work if ( m_bExploding == bExploding ) return; Steamworks_TestSecret(); // Track that we are exploding, and disable collision detection m_bExploding = bExploding; SetCollisionDetectionDisabled( m_bExploding ); if ( bExploding ) { for( int i = 0; i < SHIP_DEBRIS_PIECES; ++i ) { CShipDebris * pDebris = new CShipDebris( m_pGameEngine, GetXPos(), GetYPos(), m_dwShipColor ); m_ListDebris.push_back( pDebris ); } } else { std::list<CShipDebris *>::iterator iter; for( iter = m_ListDebris.begin(); iter != m_ListDebris.end(); ++iter ) delete *iter; m_ListDebris.clear(); } }
void AllegroTextBox::Draw() { int bbx; int bby; int bbw; int bbh; QString display = m_value; if (m_passwordMode) display.fill('*'); al_get_text_dimensions(m_boxFont, display.toStdString().c_str(), &bbx, &bby, &bbw, &bbh); int x1 = GetXPos(); int y1 = GetYPos(); int x2 = x1 + GetWidth(); int y2 = y1 + GetHeight(); al_draw_filled_rectangle(x1, y1, x2, y2, m_backgroundColor); al_draw_rectangle(x1, y1, x2, y2, GetFocus() ? m_focusedBorder : m_defaultBorder, 1); bool Overflow = (bbw > GetWidth() - m_sidePadding * 2); al_set_clipping_rectangle((m_xPos+m_sidePadding), m_yPos, (GetWidth()-m_sidePadding*2), GetHeight()); al_draw_text(m_boxFont, m_textColor, Overflow ? (m_xPos+GetWidth()-m_sidePadding) : (m_xPos+m_sidePadding), (m_yPos + (GetHeight() / 2) - bbh/2), Overflow ? ALLEGRO_ALIGN_RIGHT : ALLEGRO_ALIGN_LEFT, display.toStdString().c_str()); al_reset_clipping_rectangle(); }
void CCEtoODBView::getLayerViewData(CNamedView& namedView) { namedView.setScaleNum(ScaleNum); namedView.setScaleDenom(ScaleDenom); namedView.setScrollX(GetXPos()); namedView.setScrollY(GetYPos()); GetDocument()->getLayerViewData(namedView); }
void KinectPlayer::Render() { // if (!mPlayerPresent) { // return; // } std::vector<UserData> users; mUserTracking.GetUsers(users); if (users.empty()) { return; } al_set_target_bitmap(mBitmap); al_clear_to_color(al_map_rgb(0x00, 0x00, 0x00)); al_convert_mask_to_alpha(mBitmap, al_map_rgb(0x00, 0x00, 0x00)); xn::SceneMetaData scene_meta; mUserTracking.GetUserPixels(users[0], scene_meta); const XnRGB24Pixel* pRgbBuf = mKinect.GetImageData(); const XnLabel* pLabelBuf = scene_meta.Data(); ALLEGRO_LOCKED_REGION* lock = al_lock_bitmap(mBitmap, al_get_bitmap_format(mBitmap), ALLEGRO_LOCK_WRITEONLY); al_set_target_bitmap(mBitmap); for (int y = 0; y < mBitmapHeight; y++) { for (int x = 0; x < mBitmapWidth; x++, pLabelBuf++, pRgbBuf++) { if (*pLabelBuf == users[0].GetId()) { al_put_pixel(x, y, al_map_rgb(pRgbBuf->nRed, pRgbBuf->nGreen, pRgbBuf->nBlue)); } } } al_unlock_bitmap(mBitmap); const int screen_x_res = al_get_display_width(al_get_current_display()); const int screen_y_res = al_get_display_height(al_get_current_display()); al_set_target_bitmap(al_get_backbuffer(al_get_current_display())); al_draw_scaled_bitmap(mBitmap, 0, 0, mBitmapWidth, mBitmapHeight, GetXPos(), GetYPos(), GetWidth(), GetHeight(), 0); }
//Goto Coordinates - Goes to coordinates specified by input //Input: coordinates in x,y format (int) //Output: None int stepperDriver::GotoPos(int x, int y) { int temp = 0; //Calculate X difference and travel X coordinates int current = GetXPos(); x = x - current; temp = MoveX(x); //Calculate Y difference and travel Y coordinates current = GetYPos(); y = y - current; temp = MoveY(y); return 0; }
void nuiScrollView::OnSmoothScrolling(const nuiEvent& rEvent) { if (!mTimerOn) return; if (!mLeftClick) { float XOffset = mpHorizontal->GetRange().GetValue(); float YOffset = mpVertical->GetRange().GetValue(); float xdiff = XOffset - mXOffset; float ydiff = YOffset - mYOffset; if (xdiff > 2 || xdiff < -2) mXOffset += xdiff * NUI_SMOOTH_SCROLL_RATIO; else mXOffset = XOffset; if (ydiff > 2 || ydiff < -2) mYOffset += ydiff * NUI_SMOOTH_SCROLL_RATIO; else mYOffset = YOffset; if (mXOffset == XOffset && mYOffset == YOffset) { mTimerOn = false; } if (mSpeedX != 0) { SetXPos(GetXPos() + mSpeedX); //mXOffset = GetXPos(); mSpeedX *= 0.7; } if (mSpeedY != 0) { SetYPos(GetYPos() + mSpeedY); //mYOffset = GetYPos(); mSpeedY *= 0.7; } } UpdateLayout(); OffsetsChanged(); }
//----------------------------------------------------------------------------- // Purpose: Build the update data to send from server to clients //----------------------------------------------------------------------------- void CShip::BuildServerUpdate( ServerShipUpdateData_t *pUpdateData ) { pUpdateData->SetDisabled( BIsDisabled() ); pUpdateData->SetExploding( BIsExploding() ); pUpdateData->SetXAcceleration( GetXAccelerationLastFrame() ); pUpdateData->SetYAcceleration( GetYAccelerationLastFrame() ); pUpdateData->SetXPosition( GetXPos()/(float)m_pGameEngine->GetViewportWidth() ); pUpdateData->SetYPosition( GetYPos()/(float)m_pGameEngine->GetViewportHeight() ); pUpdateData->SetXVelocity( GetXVelocity() ); pUpdateData->SetYVelocity( GetYVelocity() ); pUpdateData->SetRotation( GetAccumulatedRotation() ); pUpdateData->SetRotationDeltaLastFrame( GetRotationDeltaLastFrame() ); pUpdateData->SetForwardThrustersActive( m_bForwardThrustersActive ); pUpdateData->SetReverseThrustersActive( m_bReverseThrustersActive ); BuildServerPhotonBeamUpdate( pUpdateData ); }
/** \param TileNum The tilenumber to use from the used tileset (see Sprite for more details). \param name The name of the Actor. \param XPos The x-coordinate at which the actor will be created. \param YPos the y-coordinate at which the actor will be created. */ void Actor::CreateActor(char TileNum, const std::string & name, long XPos, long YPos) { Create(TileNum, name, XPos, YPos); SetSpeed(7); // For most humans, the feet can be placed at the bottom-middle of the sprite. SetFootXYPos(GetXPos() + GetWidth()/2, GetYPos() + GetHeight()); }
//----------------------------------------------------------------------------- // Purpose: Run a frame for the ship //----------------------------------------------------------------------------- void CShip::RunFrame() { if ( m_bDisabled ) return; const uint64 ulCurrentTickCount = m_pGameEngine->GetGameTickCount(); // Look for expired photon beams int nNextAvailablePhotonBeamSlot = -1; // Track next available slot for use spawning new beams below for( int i=0; i < MAX_PHOTON_BEAMS_PER_SHIP; ++i ) { if ( m_rgPhotonBeams[i] ) { if ( m_rgPhotonBeams[i]->BIsBeamExpired() ) { delete m_rgPhotonBeams[i]; m_rgPhotonBeams[i] = NULL; } } if ( !m_rgPhotonBeams[i] && nNextAvailablePhotonBeamSlot == -1 ) nNextAvailablePhotonBeamSlot = i; } // run all the photon beams we have outstanding for( int i=0; i < MAX_PHOTON_BEAMS_PER_SHIP; ++i ) { if ( m_rgPhotonBeams[i] ) m_rgPhotonBeams[i]->RunFrame(); } // run all the space debris { std::list<CShipDebris *>::iterator iter; for( iter = m_ListDebris.begin(); iter != m_ListDebris.end(); ++iter ) (*iter)->RunFrame(); } if ( m_bIsLocalPlayer ) { m_SpaceWarClientUpdateData.SetTurnLeftPressed( false ); m_SpaceWarClientUpdateData.SetTurnRightPressed( false ); if ( m_pGameEngine->BIsKeyDown( m_dwVKLeft ) ) { m_SpaceWarClientUpdateData.SetTurnLeftPressed( true ); } if ( m_pGameEngine->BIsKeyDown( m_dwVKRight ) ) { m_SpaceWarClientUpdateData.SetTurnRightPressed( true ); } } else if ( m_bIsServerInstance ) { // Server side float flRotationDelta = 0.0f; if ( m_SpaceWarClientUpdateData.GetTurnLeftPressed() ) { flRotationDelta += (PI_VALUE/2.0f) * -1.0f * (float)m_pGameEngine->GetGameTicksFrameDelta()/400.0f; } if ( m_SpaceWarClientUpdateData.GetTurnRightPressed() ) { flRotationDelta += (PI_VALUE/2.0f) * (float)m_pGameEngine->GetGameTicksFrameDelta()/400.0f; } SetRotationDeltaNextFrame( flRotationDelta ); } // Compute acceleration if ( m_bIsLocalPlayer ) { // client side m_SpaceWarClientUpdateData.SetReverseThrustersPressed( false ); m_SpaceWarClientUpdateData.SetForwardThrustersPressed( false ); if ( m_pGameEngine->BIsKeyDown( m_dwVKForwardThrusters ) || m_pGameEngine->BIsKeyDown( m_dwVKReverseThrusters ) ) { if ( m_pGameEngine->BIsKeyDown( m_dwVKReverseThrusters ) ) { m_SpaceWarClientUpdateData.SetReverseThrustersPressed( true ); } else { m_SpaceWarClientUpdateData.SetForwardThrustersPressed( true ); } } } else if ( m_bIsServerInstance ) { // Server side float xThrust = 0; float yThrust = 0; m_bReverseThrustersActive = false; m_bForwardThrustersActive = false; if ( m_SpaceWarClientUpdateData.GetReverseThrustersPressed() || m_SpaceWarClientUpdateData.GetForwardThrustersPressed() ) { float flSign = 1.0f; if ( m_SpaceWarClientUpdateData.GetReverseThrustersPressed() ) { m_bReverseThrustersActive = true; flSign = -1.0f; } else { m_bForwardThrustersActive = true; } if ( m_ulLastThrustStartedTickCount == 0 ) m_ulLastThrustStartedTickCount = ulCurrentTickCount; // You have to hold the key for a second to reach maximum thrust float factor = MIN( ((float)(ulCurrentTickCount - m_ulLastThrustStartedTickCount) / 500.0f) + 0.2f, 1.0f ); xThrust = flSign * (float)(MAXIMUM_SHIP_THRUST * factor * sin( GetAccumulatedRotation() ) ); yThrust = flSign * -1.0f * (float)(MAXIMUM_SHIP_THRUST * factor * cos( GetAccumulatedRotation() ) ); } else { m_ulLastThrustStartedTickCount = 0; } SetAcceleration( xThrust, yThrust ); } // We'll use these values in a few places below to compute positions of child objects // appropriately given our rotation float sinvalue = (float)sin( GetAccumulatedRotation() ); float cosvalue = (float)cos( GetAccumulatedRotation() ); if ( m_bIsLocalPlayer ) { // client side if ( m_pGameEngine->BIsKeyDown( m_dwVKFire ) ) { m_SpaceWarClientUpdateData.SetFirePressed( true ); } } else if ( m_bIsServerInstance ) { // server side if ( nNextAvailablePhotonBeamSlot != -1 && !m_bExploding && m_SpaceWarClientUpdateData.GetFirePressed() && ulCurrentTickCount - PHOTON_BEAM_FIRE_INTERVAL_TICKS > m_ulLastPhotonTickCount ) { m_ulLastPhotonTickCount = ulCurrentTickCount; float xVelocity = GetXVelocity() + ( sinvalue * 275 ); float yVelocity = GetYVelocity() - ( cosvalue * 275 ); // Offset 12 points up from the center of the ship, compensating for rotation float xPos = GetXPos() - sinvalue*-12.0f; float yPos = GetYPos() + cosvalue*-12.0f; m_rgPhotonBeams[nNextAvailablePhotonBeamSlot] = new CPhotonBeam( m_pGameEngine, xPos, yPos, m_dwShipColor, GetAccumulatedRotation(), xVelocity, yVelocity ); } } CSpaceWarEntity::RunFrame(); // Finally, update the thrusters ( we do this after the base class call as they rely on our data being fully up-to-date) m_ForwardThrusters.RunFrame(); m_ReverseThrusters.RunFrame(); }