ulfben icon

Asteroids player control (Android)

ulfben | PRO | 03/21/17 10:39:31 AM UTC | 0 ⭐ | 981 👁️ | Never ⏰ | []
Java |

810 B

|

None

|

0 👍

/

0 👎

@Override
public void update(float dt) {
    mRotation -= mEngine.mControl.mHorizontalFactor * (mMaxRotationSpeed * dt);
    //float accel = mEngine.mControl.mVerticalFactor * mThrust;
    float accel = 0f;
    if(mEngine.mControl.mJump) { //accelerator button, instead of joystick input
        accel = mThrust;
        float angle = (mRotation+90) * TO_RADIANS; //note, +90 deg!
        float ax = (float) Math.cos(angle) * accel;
        float ay = (float) Math.sin(angle) * accel;
        mVelX += ax*dt;
        mVelY += ay*dt;
        mVelX = Utils.clamp(mVelX, -mMaxVelocity, mMaxVelocity);
        mVelY = Utils.clamp(mVelY, -mMaxVelocity, mMaxVelocity);
    }else{
        mVelX *= mFriction; //break when there's no input
        mVelY *= mFriction;
    }
    mPos.x += mVelX;
    mPos.y += mVelY;
}

Comments

  • Gyqizv icon
    04/02/26 05:59:35 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best t33n active cpx link daily updates!
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
     Remove the @ 
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎