ulfben

Asteroids player control (Android)

Mar 21st, 2017
998
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  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. }
Comments
  • Gyqizv
    193 days
    # text 0.21 KB | 0 0
    1. Best t33n active cpx link daily updates!
    2.  
    3. Copy and paste the link in a new browser tab and then hit enter!
    4.  
    5. https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
    6.  
    7. Remove the @
  • Comment was deleted
Add Comment
Please, Sign In to add comment