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

Side by Side Diff: samples/pop_pop_win/lib/src/canvas/game_background_element.dart

Issue 242443008: samples/pop_pop_win: now based on StageXL (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: tiny nit Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 part of pop_pop_win.canvas;
2
3 class GameBackgroundElement extends Thing {
4 GameBackgroundElement(): super(0, 0) {
5 cacheEnabled = true;
6 }
7
8 void update() {
9 if (size != this._gameElement.size) {
10 size = this._gameElement.size;
11 }
12 }
13
14 void drawOverride(CanvasRenderingContext2D ctx) {
15 final rightBgLoc = SquareElement._size * (_gameElement._game.field.width -1) +
16 GameElement._edgeOffset;
17 final bottomBgLoc = SquareElement._size * (_gameElement._game.field.height - 1) +
18 GameElement._edgeOffset;
19
20 ctx.save();
21 ctx.translate(_gameElement._scaledBoardOffset.x, _gameElement._scaledBoardOf fset.y);
22
23 _textureData.drawTextureKeyAt(ctx, 'game_board_corner_top_left.png');
24
25 _textureData.drawTextureKeyAt(ctx, 'game_board_corner_top_right.png',
26 new Coordinate(rightBgLoc, 0));
27
28 _textureData.drawTextureKeyAt(ctx, 'game_board_corner_bottom_left.png',
29 new Coordinate(0, bottomBgLoc));
30 _textureData.drawTextureKeyAt(ctx, 'game_board_corner_bottom_right.png',
31 new Coordinate(rightBgLoc, bottomBgLoc));
32
33 for (var i = 1; i < _gameElement._game.field.width - 1; i++) {
34 final xLoc = SquareElement._size * i + GameElement._edgeOffset;
35 _textureData.drawTextureKeyAt(ctx, 'game_board_side_top.png',
36 new Coordinate(xLoc, 0));
37 _textureData.drawTextureKeyAt(ctx, 'game_board_side_bottom.png',
38 new Coordinate(xLoc, bottomBgLoc));
39 }
40
41 for (var i = 1; i < _gameElement._game.field.height - 1; i++) {
42 final yLoc = SquareElement._size * i + GameElement._edgeOffset;
43 _textureData.drawTextureKeyAt(ctx, 'game_board_side_left.png',
44 new Coordinate(0, yLoc));
45 _textureData.drawTextureKeyAt(ctx, 'game_board_side_right.png',
46 new Coordinate(rightBgLoc, yLoc));
47 }
48
49 ctx.restore();
50
51 //
52 // start drawing corners
53 //
54
55 ctx.save();
56 // top left
57 ctx.transform(_gameElement._scale, 0, 0, _gameElement._scale, 0, 0);
58 _drawCorner(ctx);
59
60 // right flip
61 ctx.save();
62 ctx.transform(-1, 0, 0, 1, GameElement._backgroundSize.width, 0);
63 _drawCorner(ctx);
64
65 // nested bottom, right flip
66 ctx.transform(1, 0, 0, -1, 0, GameElement._backgroundSize.height);
67 _drawCorner(ctx);
68
69 ctx.restore();
70
71 // bottom left
72 ctx.transform(1, 0, 0, -1, 0, GameElement._backgroundSize.height);
73 _drawCorner(ctx);
74
75 ctx.restore();
76
77 //
78 // end drawing corners
79 //
80 }
81
82 void _drawCorner(CanvasRenderingContext2D ctx) {
83 _textureData.drawTextureKeyAt(ctx, 'background_top_left.png');
84 _textureData.drawTextureKeyAt(ctx, 'background_side_left.png',
85 new Coordinate(0, GameElement._boardOffset.y));
86 }
87
88 GameElement get _gameElement => (parent as CanvasThing).parent;
89
90 TextureData get _textureData => _gameElement._textureData;
91 }
OLDNEW
« no previous file with comments | « samples/pop_pop_win/lib/src/canvas/game_audio.dart ('k') | samples/pop_pop_win/lib/src/canvas/game_element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698