daily pastebin goal
52%
SHARE
TWEET

Asteroids player control (Android)

ulfben Mar 21st, 2017 27 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Override
  2. public void update(float dt) {
  3.     mRotation -= mEngine.mControl.mHorizontalFactor * (mMaxRotationSpeed * dt);
  4.     //float accel = mEngine.mControl.mVerticalFactor * mThrust;
  5.     float accel = 0f;
  6.     if(mEngine.mControl.mJump) { //accelerator button, instead of joystick input
  7.         accel = mThrust;
  8.         float angle = (mRotation+90) * TO_RADIANS; //note, +90 deg!
  9.         float ax = (float) Math.cos(angle) * accel;
  10.         float ay = (float) Math.sin(angle) * accel;
  11.         mVelX += ax*dt;
  12.         mVelY += ay*dt;
  13.         mVelX = Utils.clamp(mVelX, -mMaxVelocity, mMaxVelocity);
  14.         mVelY = Utils.clamp(mVelY, -mMaxVelocity, mMaxVelocity);
  15.     }else{
  16.         mVelX *= mFriction; //break when there's no input
  17.         mVelY *= mFriction;
  18.     }
  19.     mPos.x += mVelX;
  20.     mPos.y += mVelY;
  21. }
RAW Paste Data
Top