mirror of https://github.com/flutter/pinball.git
commit
a270cdd5f9
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 63 KiB |
After Width: | Height: | Size: 64 KiB |
@ -0,0 +1,29 @@
|
|||||||
|
import 'dart:math' as math;
|
||||||
|
|
||||||
|
import 'package:flame/extensions.dart';
|
||||||
|
|
||||||
|
/// {@template board_dimensions}
|
||||||
|
/// Contains various board properties and dimensions for global use.
|
||||||
|
/// {@endtemplate}
|
||||||
|
// TODO(allisonryan0002): consider alternatives for global dimensions.
|
||||||
|
class BoardDimensions {
|
||||||
|
/// Width and height of the board.
|
||||||
|
static final size = Vector2(101.6, 143.8);
|
||||||
|
|
||||||
|
/// [Rect] for easier access to board boundaries.
|
||||||
|
static final bounds = Rect.fromCenter(
|
||||||
|
center: Offset.zero,
|
||||||
|
width: size.x,
|
||||||
|
height: -size.y,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// 3D perspective angle of the board in radians.
|
||||||
|
static final perspectiveAngle = -math.atan(18.6 / bounds.height);
|
||||||
|
|
||||||
|
/// Factor the board shrinks by from the closest point to the farthest.
|
||||||
|
static const perspectiveShrinkFactor = 0.63;
|
||||||
|
|
||||||
|
/// Board height based on the [perspectiveShrinkFactor].
|
||||||
|
static final shrinkAdjustedHeight =
|
||||||
|
(1 / (1 - perspectiveShrinkFactor)) * size.y;
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
import 'package:dashbook/dashbook.dart';
|
||||||
|
import 'package:flame/game.dart';
|
||||||
|
import 'package:sandbox/common/common.dart';
|
||||||
|
import 'package:sandbox/stories/baseboard/basic.dart';
|
||||||
|
|
||||||
|
void addBaseboardStories(Dashbook dashbook) {
|
||||||
|
dashbook.storiesOf('Baseboard').add(
|
||||||
|
'Basic',
|
||||||
|
(context) => GameWidget(
|
||||||
|
game: BasicBaseboardGame(),
|
||||||
|
),
|
||||||
|
codeLink: buildSourceLink('baseboard/basic.dart'),
|
||||||
|
info: BasicBaseboardGame.info,
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:sandbox/common/common.dart';
|
||||||
|
|
||||||
|
class BasicBaseboardGame extends BasicGame {
|
||||||
|
static const info = '''
|
||||||
|
Basic example of how a Baseboard works.
|
||||||
|
''';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
|
||||||
|
final center = screenToWorld(camera.viewport.canvasSize! / 2);
|
||||||
|
|
||||||
|
final leftBaseboard = Baseboard(side: BoardSide.left)
|
||||||
|
..initialPosition = center - Vector2(25, 0);
|
||||||
|
final rightBaseboard = Baseboard(side: BoardSide.right)
|
||||||
|
..initialPosition = center + Vector2(25, 0);
|
||||||
|
|
||||||
|
await addAll([
|
||||||
|
leftBaseboard,
|
||||||
|
rightBaseboard,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
export 'ball/ball.dart';
|
export 'ball/ball.dart';
|
||||||
|
export 'baseboard/baseboard.dart';
|
||||||
|
export 'effects/effects.dart';
|
||||||
export 'flipper/flipper.dart';
|
export 'flipper/flipper.dart';
|
||||||
export 'layer/layer.dart';
|
export 'layer/layer.dart';
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
import 'package:flame/extensions.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('BoardDimensions', () {
|
||||||
|
test('has size', () {
|
||||||
|
expect(BoardDimensions.size, equals(Vector2(101.6, 143.8)));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('has bounds', () {
|
||||||
|
expect(BoardDimensions.bounds, isNotNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('has perspectiveAngle', () {
|
||||||
|
expect(BoardDimensions.perspectiveAngle, isNotNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('has perspectiveShrinkFactor', () {
|
||||||
|
expect(BoardDimensions.perspectiveShrinkFactor, equals(0.63));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('has shrinkAdjustedHeight', () {
|
||||||
|
expect(BoardDimensions.shrinkAdjustedHeight, isNotNull);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in new issue