| OLD | NEW |
| 1 part of game; | 1 part of game; |
| 2 | 2 |
| 3 const double _steeringThreshold = 0.0; | 3 const double _steeringThreshold = 0.0; |
| 4 const double _steeringMax = 150.0; | 4 const double _steeringMax = 150.0; |
| 5 | 5 |
| 6 class GameDemoBox extends SpriteBox { | 6 class GameDemoBox extends SpriteBox { |
| 7 | 7 |
| 8 GameDemoBox(GameDemoWorld game) : super(game, SpriteBoxTransformMode.letterbox
); | 8 GameDemoBox(GameDemoWorld game) : super(game, SpriteBoxTransformMode.letterbox
); |
| 9 | 9 |
| 10 GameDemoWorld get _gameWorld => this.rootNode; | 10 GameDemoWorld get _gameWorld => this.rootNode; |
| 11 | 11 |
| 12 // Handle pointers | 12 // Handle pointers |
| 13 int _firstPointer = -1; | 13 int _firstPointer = -1; |
| 14 int _secondPointer = -1; | 14 int _secondPointer = -1; |
| 15 Point _firstPointerDownPos; | 15 Point _firstPointerDownPos; |
| 16 | 16 |
| 17 void handleEvent(Event event, BoxHitTestEntry entry) { | 17 // void handleEvent(Event event, BoxHitTestEntry entry) { |
| 18 if (event is PointerEvent) { | 18 // if (event is PointerEvent) { |
| 19 Point pointerPos = new Point(event.x, event.y); | 19 // Point pointerPos = new Point(event.x, event.y); |
| 20 int pointer = event.pointer; | 20 // int pointer = event.pointer; |
| 21 | 21 // |
| 22 switch (event.type) { | 22 // switch (event.type) { |
| 23 case 'pointerdown': | 23 // case 'pointerdown': |
| 24 if (_firstPointer == -1) { | 24 // if (_firstPointer == -1) { |
| 25 // Assign the first pointer | 25 // // Assign the first pointer |
| 26 _firstPointer = pointer; | 26 // _firstPointer = pointer; |
| 27 _firstPointerDownPos = pointerPos; | 27 // _firstPointerDownPos = pointerPos; |
| 28 } | 28 // } |
| 29 else if (_secondPointer == -1) { | 29 // else if (_secondPointer == -1) { |
| 30 // Assign second pointer | 30 // // Assign second pointer |
| 31 _secondPointer = pointer; | 31 // _secondPointer = pointer; |
| 32 _gameWorld.controlFire(); | 32 // _gameWorld.controlFire(); |
| 33 } | 33 // } |
| 34 else { | 34 // else { |
| 35 // There is a pointer used for steering, let's fire instead | 35 // // There is a pointer used for steering, let's fire instead |
| 36 _gameWorld.controlFire(); | 36 // _gameWorld.controlFire(); |
| 37 } | 37 // } |
| 38 break; | 38 // break; |
| 39 case 'pointermove': | 39 // case 'pointermove': |
| 40 if (pointer == _firstPointer) { | 40 // if (pointer == _firstPointer) { |
| 41 // Handle turning control | 41 // // Handle turning control |
| 42 double joystickX = 0.0; | 42 // double joystickX = 0.0; |
| 43 double deltaX = pointerPos.x - _firstPointerDownPos.x; | 43 // double deltaX = pointerPos.x - _firstPointerDownPos.x; |
| 44 if (deltaX > _steeringThreshold || deltaX < -_steeringThreshold) { | 44 // if (deltaX > _steeringThreshold || deltaX < -_steeringThreshold) { |
| 45 joystickX = (deltaX - _steeringThreshold)/(_steeringMax - _steerin
gThreshold); | 45 // joystickX = (deltaX - _steeringThreshold)/(_steeringMax - _steer
ingThreshold); |
| 46 if (joystickX > 1.0) joystickX = 1.0; | 46 // if (joystickX > 1.0) joystickX = 1.0; |
| 47 if (joystickX < -1.0) joystickX = -1.0; | 47 // if (joystickX < -1.0) joystickX = -1.0; |
| 48 } | 48 // } |
| 49 | 49 // |
| 50 double joystickY = 0.0; | 50 // double joystickY = 0.0; |
| 51 double deltaY = pointerPos.y - _firstPointerDownPos.y; | 51 // double deltaY = pointerPos.y - _firstPointerDownPos.y; |
| 52 if (deltaY > _steeringThreshold || deltaY < -_steeringThreshold) { | 52 // if (deltaY > _steeringThreshold || deltaY < -_steeringThreshold) { |
| 53 joystickY = (deltaY - _steeringThreshold)/(_steeringMax - _steerin
gThreshold); | 53 // joystickY = (deltaY - _steeringThreshold)/(_steeringMax - _steer
ingThreshold); |
| 54 if (joystickY > 1.0) joystickY = 1.0; | 54 // if (joystickY > 1.0) joystickY = 1.0; |
| 55 if (joystickY < -1.0) joystickY = -1.0; | 55 // if (joystickY < -1.0) joystickY = -1.0; |
| 56 } | 56 // } |
| 57 | 57 // |
| 58 _gameWorld.controlSteering(joystickX, joystickY); | 58 // _gameWorld.controlSteering(joystickX, joystickY); |
| 59 } | 59 // } |
| 60 break; | 60 // break; |
| 61 case 'pointerup': | 61 // case 'pointerup': |
| 62 case 'pointercancel': | 62 // case 'pointercancel': |
| 63 if (pointer == _firstPointer) { | 63 // if (pointer == _firstPointer) { |
| 64 // Un-assign the first pointer | 64 // // Un-assign the first pointer |
| 65 _firstPointer = -1; | 65 // _firstPointer = -1; |
| 66 _firstPointerDownPos = null; | 66 // _firstPointerDownPos = null; |
| 67 _gameWorld.controlSteering(0.0, 0.0); | 67 // _gameWorld.controlSteering(0.0, 0.0); |
| 68 } | 68 // } |
| 69 else if (pointer == _secondPointer) { | 69 // else if (pointer == _secondPointer) { |
| 70 _secondPointer = -1; | 70 // _secondPointer = -1; |
| 71 } | 71 // } |
| 72 break; | 72 // break; |
| 73 default: | 73 // default: |
| 74 break; | 74 // break; |
| 75 } | 75 // } |
| 76 } | 76 // } |
| 77 } | 77 // } |
| 78 | 78 |
| 79 } | 79 } |
| OLD | NEW |