Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Unified Diff: sky/examples/game/lib/game_box.dart

Issue 1179333002: Playable demo game and bug fixes in sprites (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sky/examples/game/lib/game_box.dart
diff --git a/sky/examples/game/lib/game_box.dart b/sky/examples/game/lib/game_box.dart
deleted file mode 100644
index f3849ba73825c03a45a4e2570b3dcd8c39d9df8c..0000000000000000000000000000000000000000
--- a/sky/examples/game/lib/game_box.dart
+++ /dev/null
@@ -1,71 +0,0 @@
-part of game;
-
-const double _steeringThreshold = 20.0;
-const double _steeringMax = 50.0;
-
-class GameBox extends SpriteBox {
-
- GameBox(GameWorld game) : super(game, SpriteBoxTransformMode.letterbox);
-
- GameWorld get _gameWorld => this.rootNode;
-
- // Handle pointers
- int _firstPointer = -1;
- int _secondPointer = -1;
- Vector2 _firstPointerDownPos;
-
- void handleEvent(Event event, BoxHitTestEntry entry) {
- if (event is PointerEvent) {
- Vector2 pointerPos = new Vector2(event.x, event.y);
- int pointer = event.pointer;
-
- switch (event.type) {
- case 'pointerdown':
- if (_firstPointer == -1) {
- // Assign the first pointer
- _firstPointer = pointer;
- _firstPointerDownPos = pointerPos;
- }
- else if (_secondPointer == -1) {
- // Assign second pointer
- _secondPointer = pointer;
- _gameWorld.controlThrust(1.0);
- }
- else {
- // There is a pointer used for steering, let's fire instead
- _gameWorld.controlFire();
- }
- break;
- case 'pointermove':
- if (pointer == _firstPointer) {
- // Handle turning control
- double deltaX = pointerPos[0] - _firstPointerDownPos[0];
- if (deltaX > _steeringThreshold || deltaX < -_steeringThreshold) {
- double turnForce = (deltaX - _steeringThreshold)/(_steeringMax - _steeringThreshold);
- if (turnForce > 1.0) turnForce = 1.0;
- if (turnForce < -1.0) turnForce = -1.0;
- _gameWorld.controlSteering(turnForce);
- print("steering: $turnForce");
- }
- }
- break;
- case 'pointerup':
- case 'pointercancel':
- if (pointer == _firstPointer) {
- // Un-assign the first pointer
- _firstPointer = -1;
- _firstPointerDownPos = null;
- _gameWorld.controlSteering(null);
- }
- else if (pointer == _secondPointer) {
- _secondPointer = -1;
- _gameWorld.controlThrust(null);
- }
- break;
- default:
- break;
- }
- }
- }
-
-}

Powered by Google App Engine
This is Rietveld 408576698