Commit a78370fe authored by Viktor Lidholt's avatar Viktor Lidholt

New game demo, initial version

parent 1393b4c6
library game;
import 'dart:async';
import 'dart:sky' as sky;
import 'dart:math' as Math;
import 'sprites.dart';
......@@ -10,4 +11,4 @@ import 'package:sky/widgets/navigator.dart';
import 'package:sky/animation/curves.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 {
class GameDemoApp extends App {
NavigationState _navigationState;
GameDemoWorld _game;
NodeWithSize _game;
int _lastScore = 0;
void initState() {
// _game = new GameDemoNode(
// _imageMap,
// _spriteSheet,
// _spriteSheetUI,
// _sounds,
// (lastScore) {
// setState(() {_lastScore = lastScore;});
// });
_navigationState = new NavigationState([
new Route(
name: '/',
......@@ -112,24 +121,23 @@ class GameDemoApp extends App {
}
Widget _buildGameScene(navigator, route) {
return new SpriteWidget(_game);
return new SpriteWidget(_game, SpriteBoxTransformMode.fixedWidth);
}
Widget _buildMainScene(navigator, route) {
return new Stack([
new SpriteWidget(new MainScreenBackground()),
new SpriteWidget(new MainScreenBackground(), SpriteBoxTransformMode.fixedWidth),
new Flex([
new TextureButton(
onPressed: () {
_game = new GameDemoWorld(
_app,
navigator,
_game = new GameDemoNode(
_imageMap,
_spriteSheet,
_spriteSheetUI,
_sounds,
(lastScore) {
setState(() {_lastScore = lastScore;});
navigator.pop();
}
);
navigator.pushNamed('/game');
......@@ -243,14 +251,19 @@ class _TextureButtonToken {
}
class MainScreenBackground extends NodeWithSize {
MainScreenBackground() : super(new Size(1024.0, 1024.0)) {
Sprite sprtBackground = new Sprite.fromImage(_imageMap['assets/starfield.png']);
sprtBackground.position = new Point(512.0, 512.0);
addChild(sprtBackground);
MainScreenBackground() : super(new Size(320.0, 320.0)) {
// Sprite sprtBackground = new Sprite.fromImage(_imageMap['assets/starfield.png']);
// sprtBackground.position = new Point(160.0, 160.0);
// addChild(sprtBackground);
assert(_spriteSheet.image != null);
StarField starField = new StarField(_spriteSheet, 200, true);
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 {
}
}
}
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