Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Update the player
- *
- * @param elapsedTime
- * Elapsed time information
- * @param moveLeft
- * True if the move left control is active
- * @param moveRight
- * True if the move right control is active
- * @param jumpUp
- * True if the jump up control is active
- * @param platforms
- * Array of platforms in the world
- */
- public void update(ElapsedTime elapsedTime, boolean moveLeft,
- boolean moveRight, boolean jumpLeft, boolean jumpRight, boolean weaponSelect,
- Terrain TerrainObj) {
- // Depending upon the left and right movement touch controls
- // set an appropriate x-acceleration. If the user does not
- // want to move left or right, then the x-acceleration is zero
- // and the velocity decays towards zero.
- if (moveLeft && !moveRight) {
- acceleration.x = -RUN_ACCELERATION;
- this.mFrameHandler.setFullImage(mGameScreen.getGame().getAssetManager().getBitmap("PlayerWalk"));
- if(mFrameHandler != null && this.mFrameHandler.getRows() > 1){
- this.mFrameHandler.nextFrameVertical();
- }
- } else if (moveRight && !moveLeft) {
- acceleration.x = RUN_ACCELERATION;
- Matrix matrix = new Matrix();
- matrix.preScale(-1, 1);
- Bitmap bitmap = mGameScreen.getGame().getAssetManager().getBitmap("PlayerWalk");
- this.mFrameHandler.setFullImage(Bitmap.createBitmap(bitmap, 0,
- 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false));
- if(mFrameHandler != null && this.mFrameHandler.getRows() > 1){
- this.mFrameHandler.nextFrameVertical();
- }
- } else {
- acceleration.x = 0.0f;
- acceleration.y = 0.0f;
- velocity.x *= RUN_DECAY;
- }
- // If the user wants to jump up then providing an immediate
- // boost to the y velocity.
- if (jumpLeft && velocity.y == 0.0f) {
- velocity.y = JUMP_VELOCITY;
- velocity.x = -JUMP_VELOCITY;
- }else if (jumpRight && velocity.y == 0.0f) {
- velocity.y = JUMP_VELOCITY;
- velocity.x = -JUMP_VELOCITY;
- }
- else {
- velocity.y = GRAVITY;
- }
- // Call the sprite's update method to apply the defined
- // accelerations and velocities to provide a new position
- // and orientation.
- super.update(elapsedTime,TerrainObj);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement