void CharacterJump::Update(float fSeconds) { // Update sprite mSprite.Update(fSeconds); // Update physics const float kSpeed = 500.0f; SVector2 vel(mpOwner->GetVelocity()); if (Input_IsKeyDown(Keys::RIGHT)) { vel.x = kSpeed * fSeconds; mpOwner->SetFacingLeft(false); } else if (Input_IsKeyDown(Keys::LEFT)) { vel.x = -kSpeed * fSeconds; mpOwner->SetFacingLeft(true); } else { vel.x = 0.0f; } mpOwner->SetVelocity(vel); // State transitions if (vel.y >= 0.0f) { mpOwner->ChangeState(AS_Fall); } }
void Character::Update(float deltaTime) { const float kSpeed = 500.0f; SVector2 displacement(0.0f, 0.0f); // Check horizontal movement if(Input_IsKeyDown(Keys::RIGHT)) { displacement.x = kSpeed * deltaTime; } else if(Input_IsKeyDown(Keys::LEFT)) { displacement.x = -kSpeed * deltaTime; } else { displacement.x = 0.0f; } // Check vertical movement if(Input_IsKeyDown(Keys::DOWN)) { displacement.y = kSpeed * deltaTime; } else if(Input_IsKeyDown(Keys::UP)) { displacement.y = -kSpeed * deltaTime; } else { displacement.y = 0.0f; } mPosition += displacement; }
void SilverbackInput::pushKeyEvent(int key, int rawchar, bool down) { gcn::KeyInput i; //Console_Printf("Got input: %d %d %s\n", key, rawchar, down ? "down" : "up"); if(rawchar || key < 200) { if(rawchar > 32 && rawchar < 127) i.setKey(gcn::Key(rawchar)); #ifndef _WIN32 else if(rawchar>=127 || (rawchar == key && key <= 32)) i.setKey(convertKey(key)); else if(key > 32 && key < 127) i.setKey(gcn::Key(key)); #else else i.setKey(convertKey(key)); #endif i.setType(down ? gcn::KeyInput::PRESSED : gcn::KeyInput::RELEASED); i.setShiftPressed(Input_IsKeyDown(KEY_SHIFT)); i.setControlPressed(Input_IsKeyDown(KEY_CTRL)); i.setAltPressed(Input_IsKeyDown(KEY_ALT)); i.setNumericPad(key >= KEY_KEYPAD_0 && key <= KEY_KEYPAD_ENTER); mKeyInputQueue.push(i); } else if ((key >= KEY_MOUSEFIRSTBUTTON && key <= KEY_MOUSELASTBUTTON) || key == KEY_XBUTTON1 || key == KEY_XBUTTON2) { pushMouseEvent(key, down); } }
void NPC::Render(SVector2 offset) { sOffset = offset; SVector2 newPos = (mNPCData.mPosition + offset); mSprite.SetPosition(newPos); mSprite.Render(); mFont.Print(mNPCData.mName, mNPCData.mPosition.x + offset.x, mNPCData.mPosition.y + offset.y - 15); #if _DEBUG int size = mPath.size() - 1; if(Input_IsKeyDown(Keys::TAB)) { for(int a = 0; a < size; ++a) { SVector2 newPosA = (mPath[a] + offset); SVector2 newPosB = (mPath[a + 1] + offset); Graphics_DebugLine(newPosA, newPosB, 0XFF0000); } } #endif }
bool CharacterCombat::Update(float fSeconds) { // Update sprite mSprite.Update(fSeconds); // Switch to walk state if arrow keys are pressed if (Input_IsKeyDown(Keys::RIGHT) || Input_IsKeyDown(Keys::LEFT) || Input_IsKeyDown(Keys::UP) || Input_IsKeyDown(Keys::DOWN)) { mpOwner->ChangeState(AS_Walk); } // Switch to action state if control is pressed if (Input_IsKeyPressed(Keys::LCONTROL) && !mAnimation.GetIsAnimating()) { //mpOwner->ChangeState(AS_Action); } Graphics_DebugText("Current State: Combat", 0, 150, 0xFFFFFF); return false; }
void Fighter::Update(float deltaTime) { //Movement if(Input_IsKeyDown(Keys::RIGHT)) { mPosition.x += mSpeed * deltaTime; } else if(Input_IsKeyDown(Keys::LEFT)) { mPosition.x -= mSpeed * deltaTime; } if(Input_IsKeyDown(Keys::UP)) { mPosition.y -= mSpeed * deltaTime; } else if(Input_IsKeyDown(Keys::DOWN)) { mPosition.y += mSpeed * deltaTime; } }
void Fighter::Update(float deltaTime) { const float kSpeed = 100.0f; if (Input_IsKeyDown(Keys::RIGHT)) { mPosition.x += kSpeed * deltaTime; } if (Input_IsKeyDown(Keys::LEFT)) { mPosition.x -= kSpeed * deltaTime; } if (Input_IsKeyDown(Keys::UP)) { mPosition.y -= kSpeed * deltaTime; } if (Input_IsKeyDown(Keys::DOWN)) { mPosition.y += kSpeed * deltaTime; } }
void Character::Update(float deltaTime, const Map& map) { const float kSpeed = 500.0f; //Check horizontal movement if (Input_IsKeyDown(Keys::RIGHT)) { mVelocity.x = kSpeed * deltaTime; } else if (Input_IsKeyDown(Keys::LEFT)) { mVelocity.x = -kSpeed * deltaTime; } else { mVelocity.x = 0.0f; } // Check collision SRect bb = GetBoundingBox(); SRect newbb = bb + SVector2(mVelocity.x, 0.0f); SRect rightbb = map.GetBoundingBoxFromSegment(newbb.GetRightSegment()); SRect leftbb = map.GetBoundingBoxFromSegment(newbb.GetLeftSegment()); // Right collision if (mVelocity.x > 0.0f && rightbb.IsValid()) { mPosition.x += (int)(rightbb.min.x - bb.max.x) - 1.0f; } // Left collision else if (mVelocity.x < 0.0f && leftbb.IsValid()) { mPosition.x += (int)(leftbb.max.x - bb.min.x) + 1.0f; } else { mPosition.x += (int)mVelocity.x; } //Check vertical movement //if (Input_IsKeyDown(Keys::DOWN)) //{ // mVelocity.y = kSpeed * deltaTime; //} //else if (Input_IsKeyDown(Keys::UP)) //{ // mVelocity.y = -kSpeed * deltaTime; //} //else //{ // mVelocity.y = 0.0f; //} if(!mJumping && Input_IsKeyPressed(Keys::UP)) { mVelocity.y = -30.0f; mJumping = true; } else { mVelocity.y += 100.0f * deltaTime; } mVelocity.y = Min(mVelocity.y, 30.0f); // Check collision newbb = bb + SVector2(0.0f, mVelocity.y); SRect bottombb = map.GetBoundingBoxFromSegment(newbb.GetBottomSegment()); SRect topbb = map.GetBoundingBoxFromSegment(newbb.GetTopSegment()); // Bottom collision if(mVelocity.y > 0.0f && bottombb.IsValid()) { mPosition.y += (int)(bottombb.min.y - bb.max.y) - 1.0f; mVelocity.y = 0.0f; mJumping = false; } // Top collision else if(mVelocity.y < 0.0f && topbb.IsValid()) { mPosition.y += (int)(topbb.max.y - bb.min.y) + 1.0f; mVelocity.y = 0.0f; } else { mPosition.y += (int)mVelocity.y; } }
void Player_Update( float timeStep ) { if( player ) { TVec3 vAxis = Vec3_Set( 0.0f, 1.0f, 0.0f ); // get correct vectors for moving TVec3 look = Entity_GetLookVector( player->pivot ); TVec3 right = Entity_GetRightVector( player->pivot ); TVec3 listenerPosition = Entity_GetGlobalPosition( player->cameraPivot ); Lightprobe_LightEntity( player->weapon->model ); player->onGround = false; for( int i = 0; i < player->body.contactCount; i++ ) { TContact * contact = &player->body.contacts[i]; // check angle between contact normal and vertical axis, it must be less than 60 degrees if( Vec3_Angle( vAxis, contact->normal ) < M_PI / 3.0 ) { player->onGround = true; } } // ==================== // moving player->destVelocity = Vec3_Zero(); player->move = false; if( Input_IsKeyDown( KEY_W )) { player->destVelocity = Vec3_Add( player->destVelocity, look ); player->move = true; } if( Input_IsKeyDown( KEY_S )) { player->destVelocity = Vec3_Sub( player->destVelocity, look ); player->move = true; } if( Input_IsKeyDown( KEY_A )) { player->destVelocity = Vec3_Add( player->destVelocity, right ); player->move = true; } if( Input_IsKeyDown( KEY_D )) { player->destVelocity = Vec3_Sub( player->destVelocity, right ); player->move = true; } if( Input_IsKeyDown( KEY_C ) ) { player->crouch = true; if( player->body.shape->sphereRadius > player->crouchRadius ) { player->body.shape->sphereRadius -= 0.05f; } else { player->body.shape->sphereRadius = player->crouchRadius; } } else { player->crouch = false; char standUp = 1; // before stand up, we must trace ray up on player's head, to ensure, that // there enough space to stand up. TVec3 end = Vec3_Set( player->body.position.x, player->body.position.y + 1.0f, player->body.position.z ); TRay headRay = Ray_Set( player->body.position, end ); TRayTraceResult out; Ray_TraceWorldStatic( &headRay, &out ); if( out.body ) { float maxRadius = player->shape.sphereRadius + 0.4f; if( Vec3_SqrDistance( out.position, player->body.position ) < maxRadius * maxRadius ) { standUp = 0; player->crouch = true; } } if( standUp ) { if( player->body.shape->sphereRadius < player->standRadius ) { player->body.shape->sphereRadius += 0.04f; } else { player->body.shape->sphereRadius = player->standRadius; } } } // sync step sound position with player position for( int i = 0; i < player->stepSoundGroup->count; i++ ) { SoundSource_SetPosition( &player->stepSoundGroup->sounds[i], &listenerPosition ); if( player->crouch ) { SoundSource_SetVolume( &player->stepSoundGroup->sounds[i], 0.5f ); } else { SoundSource_SetVolume( &player->stepSoundGroup->sounds[i], 1.0f ); } } // emit step sound only if got contact with the ground if( player->body.contactCount > 0 ) { TContact * lowestContact = &player->body.contacts[0]; for( int i = 0; i < player->body.contactCount; i++ ) { if( player->body.contacts[i].position.y < lowestContact->position.y ) { lowestContact = &player->body.contacts[i]; } } // select emittable sounds if( lowestContact->triangle ) { // iterate over all possible step sound groups for( int i = 0; i < STEP_GROUP_COUNT; i++ ) { // iterate over each material in group for( int j = 0; j < player->stepSounds[i].materialCount; j++ ) { if( lowestContact->triangle->material == player->stepSounds[i].material[j] ) { player->stepSoundGroup = &player->stepSounds[i]; } } } } if( player->pathLength > 15 * player->speed ) { int randomSound = rand() % player->stepSoundGroup->count; if( randomSound >= 4 ) { randomSound = 3; } SoundSource_Play( &player->stepSoundGroup->sounds[ randomSound ] ); player->pathLength = 0.0f; } } float realSpeed = player->speed; player->run = false; if( Input_IsKeyDown( KEY_LeftShift ) && !player->crouch ) { realSpeed *= player->speedMultiplier; player->run = true; } if( player->crouch ) { realSpeed *= 0.65f; } if( player->move ) { // prevent divide by zero player->destVelocity = Vec3_Normalize( player->destVelocity ); player->pathLength += realSpeed * 0.5f; } float interpCoeff = 0.25f; if( !player->onGround ) { interpCoeff = 0.0035f; } player->destVelocity.x *= realSpeed; player->destVelocity.z *= realSpeed; player->velocity.x += ( player->destVelocity.x - player->velocity.x ) * interpCoeff; player->velocity.z += ( player->destVelocity.z - player->velocity.z ) * interpCoeff; // do not overwrite gravity component (y), apply only x and z player->body.linearVelocity.x = player->velocity.x * timeStep; player->body.linearVelocity.z = player->velocity.z * timeStep; // ==================== // jump if( Input_IsKeyHit( KEY_Space ) ) { if( player->onGround ) { player->body.linearVelocity.y += player->jumpStrength; } } // sync pivot's position with physical body player->pivot->localPosition = player->body.position; // ==================== // mouse look player->yaw -= Input_GetMouseXSpeed() * player->mouseSensivity * timeStep; player->pitch += Input_GetMouseYSpeed() * player->mouseSensivity * timeStep; // clamp pitch if( player->pitch > player->maxPitch ) { player->pitch = player->maxPitch; } if( player->pitch < -player->maxPitch ) { player->pitch = -player->maxPitch; } right = Vec3_Set( 1, 0, 0 ); vAxis = Vec3_Set( 0, 1, 0 ); player->pivot->localRotation = Quaternion_SetAxisAngle( vAxis, player->yaw ); player->cameraPivot->localRotation = Quaternion_SetAxisAngle( right, player->pitch ); // sound TVec3 up = Entity_GetUpVector( player->cameraPivot ); SoundListener_SetPosition( &listenerPosition ); SoundListener_SetOrientation( &look, &up ); // weapon Weapon_Update( player->weapon ); if( Input_IsMouseDown( MB_Left )) { Weapon_Shoot( player->weapon ); } player->weapon->moveSpeed = player->body.linearVelocity; Player_CameraShake( ); } }
void InputBox::Update(float deltaTime) { mSprite.Update(deltaTime); // Update caret info mCaret += deltaTime; if (mCaret > CARET_BLINK_RATE_SECONDS) { mCaret -= CARET_BLINK_RATE_SECONDS; } SVector2 mouse((float) Input_GetMouseScreenX(), (float) Input_GetMouseScreenY()); // If a mouse click is detected this box is no longer selected. Below it checks if it is the one being clicked on if(Input_IsMousePressed(Mouse::LBUTTON)) { mActive = mouse.x > (mPosition.x - 25) && mouse.x < mPosition.x + mWidth && mouse.y > (mPosition.y - 25) && mouse.y < mPosition.y + mHeight; } // If Active Capture Text if(mActive) { // Dont go over max length if(mTextPosition < mMaxLength) { if (Input_IsKeyDown(Keys::LSHIFT) || Input_IsKeyDown(Keys::RSHIFT) ) { if(Input_IsKeyPressed(Keys::A)) { mText[mTextPosition++] = 'A'; } if(Input_IsKeyPressed(Keys::B)) { mText[mTextPosition++] = 'B'; } if(Input_IsKeyPressed(Keys::C)) { mText[mTextPosition++] = 'C'; } if(Input_IsKeyPressed(Keys::D)) { mText[mTextPosition++] = 'D'; } if(Input_IsKeyPressed(Keys::E)) { mText[mTextPosition++] = 'E'; } if(Input_IsKeyPressed(Keys::F)) { mText[mTextPosition++] = 'F'; } if(Input_IsKeyPressed(Keys::G)) { mText[mTextPosition++] = 'G'; } if(Input_IsKeyPressed(Keys::H)) { mText[mTextPosition++] = 'H'; } if(Input_IsKeyPressed(Keys::I)) { mText[mTextPosition++] = 'I'; } if(Input_IsKeyPressed(Keys::J)) { mText[mTextPosition++] = 'J'; } if(Input_IsKeyPressed(Keys::K)) { mText[mTextPosition++] = 'K'; } if(Input_IsKeyPressed(Keys::L)) { mText[mTextPosition++] = 'L'; } if(Input_IsKeyPressed(Keys::M)) { mText[mTextPosition++] = 'M'; } if(Input_IsKeyPressed(Keys::N)) { mText[mTextPosition++] = 'N'; } if(Input_IsKeyPressed(Keys::O)) { mText[mTextPosition++] = 'O'; } if(Input_IsKeyPressed(Keys::P)) { mText[mTextPosition++] = 'P'; } if(Input_IsKeyPressed(Keys::Q)) { mText[mTextPosition++] = 'Q'; } if(Input_IsKeyPressed(Keys::R)) { mText[mTextPosition++] = 'R'; } if(Input_IsKeyPressed(Keys::S)) { mText[mTextPosition++] = 'S'; } if(Input_IsKeyPressed(Keys::T)) { mText[mTextPosition++] = 'T'; } if(Input_IsKeyPressed(Keys::U)) { mText[mTextPosition++] = 'U'; } if(Input_IsKeyPressed(Keys::V)) { mText[mTextPosition++] = 'V'; } if(Input_IsKeyPressed(Keys::W)) { mText[mTextPosition++] = 'W'; } if(Input_IsKeyPressed(Keys::X)) { mText[mTextPosition++] = 'X'; } if(Input_IsKeyPressed(Keys::Y)) { mText[mTextPosition++] = 'Y'; } if(Input_IsKeyPressed(Keys::Z)) { mText[mTextPosition++] = 'Z'; } if(Input_IsKeyPressed(Keys::SEMICOLON)) { mText[mTextPosition++] = ':'; } if(Input_IsKeyPressed(Keys::ONE)) { mText[mTextPosition++] = '!'; } if(Input_IsKeyPressed(Keys::TWO)) { mText[mTextPosition++] = '@'; } if(Input_IsKeyPressed(Keys::THREE)) { mText[mTextPosition++] = '#'; } if(Input_IsKeyPressed(Keys::FOUR)) { mText[mTextPosition++] = '$'; } if(Input_IsKeyPressed(Keys::FIVE)) { mText[mTextPosition++] = '%'; } if(Input_IsKeyPressed(Keys::SIX)) { mText[mTextPosition++] = '^'; } if(Input_IsKeyPressed(Keys::SEVEN)) { mText[mTextPosition++] = '&'; } if(Input_IsKeyPressed(Keys::EIGHT)) { mText[mTextPosition++] = '*'; } if(Input_IsKeyPressed(Keys::NINE)) { mText[mTextPosition++] = '('; } if(Input_IsKeyPressed(Keys::ZERO)) { mText[mTextPosition++] = ')'; } if(Input_IsKeyPressed(Keys::SLASH)) { mText[mTextPosition++] = '?'; } if(Input_IsKeyPressed(Keys::PERIOD)) { mText[mTextPosition++] = '>'; } if(Input_IsKeyPressed(Keys::COMMA)) { mText[mTextPosition++] = '<'; } if(Input_IsKeyPressed(Keys::APOSTROPHE)) { mText[mTextPosition++] = '"'; } if(Input_IsKeyPressed(Keys::GRAVE)) { mText[mTextPosition++] = '~'; } if(Input_IsKeyPressed(Keys::LBRACKET)) { mText[mTextPosition++] = '{'; } if(Input_IsKeyPressed(Keys::RBRACKET)) { mText[mTextPosition++] = '}'; } } else { if(Input_IsKeyPressed(Keys::A)) { mText[mTextPosition++] = 'a'; } if(Input_IsKeyPressed(Keys::B)) { mText[mTextPosition++] = 'b'; } if(Input_IsKeyPressed(Keys::C)) { mText[mTextPosition++] = 'c'; } if(Input_IsKeyPressed(Keys::D)) { mText[mTextPosition++] = 'd'; } if(Input_IsKeyPressed(Keys::E)) { mText[mTextPosition++] = 'e'; } if(Input_IsKeyPressed(Keys::F)) { mText[mTextPosition++] = 'f'; } if(Input_IsKeyPressed(Keys::G)) { mText[mTextPosition++] = 'g'; } if(Input_IsKeyPressed(Keys::H)) { mText[mTextPosition++] = 'h'; } if(Input_IsKeyPressed(Keys::I)) { mText[mTextPosition++] = 'i'; } if(Input_IsKeyPressed(Keys::J)) { mText[mTextPosition++] = 'j'; } if(Input_IsKeyPressed(Keys::K)) { mText[mTextPosition++] = 'k'; } if(Input_IsKeyPressed(Keys::L)) { mText[mTextPosition++] = 'l'; } if(Input_IsKeyPressed(Keys::M)) { mText[mTextPosition++] = 'm'; } if(Input_IsKeyPressed(Keys::N)) { mText[mTextPosition++] = 'n'; } if(Input_IsKeyPressed(Keys::O)) { mText[mTextPosition++] = 'o'; } if(Input_IsKeyPressed(Keys::P)) { mText[mTextPosition++] = 'p'; } if(Input_IsKeyPressed(Keys::Q)) { mText[mTextPosition++] = 'q'; } if(Input_IsKeyPressed(Keys::R)) { mText[mTextPosition++] = 'r'; } if(Input_IsKeyPressed(Keys::S)) { mText[mTextPosition++] = 's'; } if(Input_IsKeyPressed(Keys::T)) { mText[mTextPosition++] = 't'; } if(Input_IsKeyPressed(Keys::U)) { mText[mTextPosition++] = 'u'; } if(Input_IsKeyPressed(Keys::V)) { mText[mTextPosition++] = 'v'; } if(Input_IsKeyPressed(Keys::W)) { mText[mTextPosition++] = 'w'; } if(Input_IsKeyPressed(Keys::X)) { mText[mTextPosition++] = 'x'; } if(Input_IsKeyPressed(Keys::Y)) { mText[mTextPosition++] = 'y'; } if(Input_IsKeyPressed(Keys::Z)) { mText[mTextPosition++] = 'z'; } if(Input_IsKeyPressed(Keys::ZERO)) { mText[mTextPosition++] = '0'; } if(Input_IsKeyPressed(Keys::ONE)) { mText[mTextPosition++] = '1'; } if(Input_IsKeyPressed(Keys::TWO)) { mText[mTextPosition++] = '2'; } if(Input_IsKeyPressed(Keys::THREE)) { mText[mTextPosition++] = '3'; } if(Input_IsKeyPressed(Keys::FOUR)) { mText[mTextPosition++] = '4'; } if(Input_IsKeyPressed(Keys::FIVE)) { mText[mTextPosition++] = '5'; } if(Input_IsKeyPressed(Keys::SIX)) { mText[mTextPosition++] = '6'; } if(Input_IsKeyPressed(Keys::SEVEN)) { mText[mTextPosition++] = '7'; } if(Input_IsKeyPressed(Keys::EIGHT)) { mText[mTextPosition++] = '8'; } if(Input_IsKeyPressed(Keys::NINE)) { mText[mTextPosition++] = '9'; } if(Input_IsKeyPressed(Keys::SLASH)) { mText[mTextPosition++] = '/'; } if(Input_IsKeyPressed(Keys::PERIOD)) { mText[mTextPosition++] = '.'; } if(Input_IsKeyPressed(Keys::APOSTROPHE)) { mText[mTextPosition++] = '\''; } if(Input_IsKeyPressed(Keys::COMMA)) { mText[mTextPosition++] = ','; } if(Input_IsKeyPressed(Keys::MINUS)) { mText[mTextPosition++] = '-'; } if(Input_IsKeyPressed(Keys::EQUALS)) { mText[mTextPosition++] = '='; } if(Input_IsKeyPressed(Keys::SEMICOLON)) { mText[mTextPosition++] = ';'; } if(Input_IsKeyPressed(Keys::GRAVE)) { mText[mTextPosition++] = '`'; } if(Input_IsKeyPressed(Keys::LBRACKET)) { mText[mTextPosition++] = '['; } if(Input_IsKeyPressed(Keys::RBRACKET)) { mText[mTextPosition++] = ']'; } } if(Input_IsKeyPressed(Keys::SPACE)) { mText[mTextPosition++] = ' '; } } // Backspace if(mTextPosition > 0 && Input_IsKeyPressed(Keys::BACKSPACE)) { mText[--mTextPosition] = '\0'; } } }
void Character::Update(float deltaTime, const Map& map, const SVector2& renderOffset) { const float kSpeed = 256.0f; // Check horizontal movement if(Input_IsKeyDown(Keys::RIGHT)) { mVelocity.x = kSpeed * deltaTime; mSprite.SetRotation(1.575f); } else if(Input_IsKeyDown(Keys::LEFT)) { mVelocity.x = -kSpeed * deltaTime; mSprite.SetRotation(-1.575f); } else { mVelocity.x = 0.0f; } // Check collision SRect bb = GetBoundingBox(renderOffset); SRect newbb = bb + SVector2(mVelocity.x, 0.0f); SLineSegment tempRightLS(newbb.GetRightSegment().from.x - renderOffset.x, newbb.GetRightSegment().from.y - renderOffset.y, newbb.GetRightSegment().to.x - renderOffset.x, newbb.GetRightSegment().to.y - renderOffset.y); SLineSegment tempLeftLS(newbb.GetLeftSegment().from.x - renderOffset.x, newbb.GetLeftSegment().from.y - renderOffset.y, newbb.GetLeftSegment().to.x - renderOffset.x, newbb.GetLeftSegment().to.y - renderOffset.y); SRect rightbb = map.GetBoudingBoxFromSegment(tempRightLS); SRect leftbb = map.GetBoudingBoxFromSegment(tempLeftLS); Graphics_DebugRect(bb, 0xF04BC3); Graphics_DebugRect(newbb, 0x004BC3); Graphics_DebugRect(rightbb, 0xF04B00); Graphics_DebugRect(leftbb, 0xF000C3); // Right Collision if(mVelocity.x > 0.0f && rightbb.IsValid()) { mPosition.x += static_cast<int>(rightbb.min.x - bb.max.x) - 1.0f; } // Left Collision else if(mVelocity.x < 0.0f && leftbb.IsValid()) { mPosition.x += static_cast<int>(leftbb.max.x - bb.min.x) + 1.0f; } else { mPosition.x += static_cast<int>(mVelocity.x); } // Check vertical movement if(Input_IsKeyDown(Keys::DOWN)) { mVelocity.y = kSpeed * deltaTime; mSprite.SetRotation(3.15f); } else if(Input_IsKeyDown(Keys::UP)) { mVelocity.y = -kSpeed * deltaTime; mSprite.SetRotation(0.0f); } else { mVelocity.y = 0.0f; } // Check collision newbb = bb + SVector2(0.0f, mVelocity.y); SRect topbb = map.GetBoudingBoxFromSegment(newbb.GetTopSegment()); SRect bottombb = map.GetBoudingBoxFromSegment(newbb.GetBottomSegment()); // Top Collision if(mVelocity.y < 0.0f && topbb.IsValid()) { mPosition.y += static_cast<int>(topbb.max.y - bb.min.y) + 1.0f; } // Bottom Collision else if(mVelocity.y > 0.0f && bottombb.IsValid()) { mPosition.y += static_cast<int>(bottombb.min.y - bb.max.y) - 1.0f; } else { mPosition.y += static_cast<int>(mVelocity.y); } mPosition += mVelocity; }