Commit a78370fe authored by Viktor Lidholt's avatar Viktor Lidholt

New game demo, initial version

parent 1393b4c6
library game; library game;
import 'dart:async';
import 'dart:sky' as sky; import 'dart:sky' as sky;
import 'dart:math' as Math; import 'dart:math' as Math;
import 'sprites.dart'; import 'sprites.dart';
...@@ -10,4 +11,4 @@ import 'package:sky/widgets/navigator.dart'; ...@@ -10,4 +11,4 @@ import 'package:sky/widgets/navigator.dart';
import 'package:sky/animation/curves.dart'; import 'package:sky/animation/curves.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
part 'game_demo_world.dart'; part 'game_demo_node.dart';
This diff is collapsed.
This diff is collapsed.
...@@ -77,10 +77,19 @@ main() async { ...@@ -77,10 +77,19 @@ main() async {
class GameDemoApp extends App { class GameDemoApp extends App {
NavigationState _navigationState; NavigationState _navigationState;
GameDemoWorld _game; NodeWithSize _game;
int _lastScore = 0; int _lastScore = 0;
void initState() { void initState() {
// _game = new GameDemoNode(
// _imageMap,
// _spriteSheet,
// _spriteSheetUI,
// _sounds,
// (lastScore) {
// setState(() {_lastScore = lastScore;});
// });
_navigationState = new NavigationState([ _navigationState = new NavigationState([
new Route( new Route(
name: '/', name: '/',
...@@ -112,24 +121,23 @@ class GameDemoApp extends App { ...@@ -112,24 +121,23 @@ class GameDemoApp extends App {
} }
Widget _buildGameScene(navigator, route) { Widget _buildGameScene(navigator, route) {
return new SpriteWidget(_game); return new SpriteWidget(_game, SpriteBoxTransformMode.fixedWidth);
} }
Widget _buildMainScene(navigator, route) { Widget _buildMainScene(navigator, route) {
return new Stack([ return new Stack([
new SpriteWidget(new MainScreenBackground()), new SpriteWidget(new MainScreenBackground(), SpriteBoxTransformMode.fixedWidth),
new Flex([ new Flex([
new TextureButton( new TextureButton(
onPressed: () { onPressed: () {
_game = new GameDemoWorld( _game = new GameDemoNode(
_app,
navigator,
_imageMap, _imageMap,
_spriteSheet, _spriteSheet,
_spriteSheetUI, _spriteSheetUI,
_sounds, _sounds,
(lastScore) { (lastScore) {
setState(() {_lastScore = lastScore;}); setState(() {_lastScore = lastScore;});
navigator.pop();
} }
); );
navigator.pushNamed('/game'); navigator.pushNamed('/game');
...@@ -243,14 +251,19 @@ class _TextureButtonToken { ...@@ -243,14 +251,19 @@ class _TextureButtonToken {
} }
class MainScreenBackground extends NodeWithSize { class MainScreenBackground extends NodeWithSize {
MainScreenBackground() : super(new Size(1024.0, 1024.0)) { MainScreenBackground() : super(new Size(320.0, 320.0)) {
Sprite sprtBackground = new Sprite.fromImage(_imageMap['assets/starfield.png']); // Sprite sprtBackground = new Sprite.fromImage(_imageMap['assets/starfield.png']);
sprtBackground.position = new Point(512.0, 512.0); // sprtBackground.position = new Point(160.0, 160.0);
addChild(sprtBackground); // addChild(sprtBackground);
assert(_spriteSheet.image != null); assert(_spriteSheet.image != null);
StarField starField = new StarField(_spriteSheet, 200, true); StarField starField = new StarField(_spriteSheet, 200, true);
addChild(starField); addChild(starField);
} }
void paint(PaintingCanvas canvas) {
canvas.drawRect(new Rect.fromLTWH(0.0, 0.0, 320.0, 320.0), new Paint()..color=new Color(0xff000000));
super.paint(canvas);
}
} }
...@@ -80,4 +80,21 @@ class GameMath { ...@@ -80,4 +80,21 @@ class GameMath {
} }
} }
} }
static double pointQuickDist(Point a, Point b) {
double dx = a.x - b.x;
double dy = a.y - b.y;
if (dx < 0.0) dx = -dx;
if (dy < 0.0) dy = -dy;
if (dx > dy) {
return dx + dy/2.0;
}
else {
return dy + dx/2.0;
}
}
static double filter (double a, double b, double filterFactor) {
return (a * (1-filterFactor)) + b * filterFactor;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment