mirror of https://github.com/flutter/pinball.git
feat: dynamic ball size (#113)
* feat: scale ball and add ball asset * refactor: increase plunger properties * test: board dimensions * refactor: store adjusted height * chore: add todopull/133/head
parent
930c7fa001
commit
83e6cb892b
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 3.1 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,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