1 16 package com.buchuki.ensmer.input; 17 18 import java.util.*; 19 20 30 public class Accelerator { 31 32 39 public void startAcceleration(boolean accel) { 40 if (task != null) { 41 resetAcceleration(); 42 return; 43 } 44 float accelvalue = accel ? 1.4f : 0.6f; 45 task = new AccelerationTask(accelvalue); 46 scheduler.schedule(task, 1000, 500); 47 } 48 49 52 public void stopAcceleration() { 53 if (task != null) { 54 task.cancel(); 55 task = null; 56 } 57 } 58 59 62 public void resetAcceleration() { 63 stopAcceleration(); 64 acceleration = 1.0f; 65 } 66 67 72 public float getAcceleration() { 73 return acceleration; 74 } 75 76 79 private float acceleration = 1.0f; 80 81 84 private Timer scheduler = new Timer(true); 85 86 89 private AccelerationTask task; 90 91 97 private class AccelerationTask extends TimerTask { 98 105 AccelerationTask(float increment) { 106 this.increment = increment; 107 } 108 109 112 public void run() { 113 acceleration *= increment; 114 } 115 116 119 private float increment; 120 } 121 } 122 123 | Popular Tags |