Skip to content

Commit 03f9c95

Browse files
author
Kevin Chappellet
committed
Prototype
1 parent 1052ef3 commit 03f9c95

24 files changed

+9277
-0
lines changed

.vscode/settings.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
// The number of spaces a tab is equal to. This setting is overriden based on the file contents when `editor.detectIndentation` is on.
4+
"editor.tabSize": 4,
5+
6+
"typescript.tsdk": "/usr/lib/node_modules/typescript/lib"
7+
}

.vscode/tasks.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "0.1.0",
5+
"command": "tsc",
6+
"isShellCommand": true,
7+
"args": ["-p", ".", "--out", "bin/js/game.js"],
8+
"showOutput": "silent",
9+
"problemMatcher": "$tsc"
10+
}

bin/assets/loader.png

3.03 KB
Loading

bin/assets/raw/grass.xcf

10.3 KB
Binary file not shown.

bin/assets/raw/sample_tile.xcf

12.7 KB
Binary file not shown.

bin/assets/splashs/phaser.png

176 KB
Loading

bin/assets/tiles/grass.png

2.51 KB
Loading

bin/index.html

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="chrome=1, IE=9">
6+
<meta name="format-detection" content="telephone=no">
7+
<meta name="HandheldFriendly" content="true" />
8+
<meta name="robots" content="noindex,nofollow" />
9+
<meta name="apple-mobile-web-app-capable" content="yes" />
10+
<meta name="apple-mobile-web-app-status-bar-style" content="white" />
11+
<meta name="apple-mobile-web-app-title" content="Phaser App">
12+
<meta name="viewport" content="initial-scale=1 maximum-scale=1 user-scalable=0 minimal-ui" />
13+
<title>Oddkyn</title>
14+
<script src="js/phaser.min.js"></script>
15+
<script src="js/game.js"></script>
16+
</head>
17+
<body>
18+
<div id="game"></div>
19+
</body>
20+
</html>

bin/js/game.js

+298
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,298 @@
1+
var __extends = (this && this.__extends) || function (d, b) {
2+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
3+
function __() { this.constructor = d; }
4+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
5+
};
6+
var Oddkyn;
7+
(function (Oddkyn) {
8+
/// <reference path="Case.ts" />
9+
var Board = (function (_super) {
10+
__extends(Board, _super);
11+
function Board(game, size) {
12+
if (size === void 0) { size = 17; }
13+
_super.call(this);
14+
this.game = game;
15+
//Construct Board View
16+
this.size = size;
17+
this.gameCenterX = game.world.centerX;
18+
this.gameCenterY = game.world.centerY;
19+
this.gameHalfHeight = game.world.height * 0.5;
20+
this.gameHalfWidth = game.world.width * 0.5;
21+
var H = this.size * Oddkyn.Case.Data.halfHeight;
22+
var W = this.size * Oddkyn.Case.Data.halfWidth;
23+
this.points = new Array();
24+
this.points.push(new Phaser.Point(this.gameCenterX, this.gameCenterY + H));
25+
this.points.push(new Phaser.Point(this.gameCenterX + W, this.gameCenterY + Oddkyn.Case.Data.upperSide));
26+
this.points.push(new Phaser.Point(this.gameCenterX + W, this.gameCenterY - Oddkyn.Case.Data.lowerSide));
27+
this.points.push(new Phaser.Point(this.gameCenterX, this.gameCenterY - H));
28+
this.points.push(new Phaser.Point(this.gameCenterX - W, this.gameCenterY - Oddkyn.Case.Data.upperSide));
29+
this.points.push(new Phaser.Point(this.gameCenterX - W, this.gameCenterY + Oddkyn.Case.Data.lowerSide));
30+
var graphic = game.add.graphics(0, 0);
31+
graphic.alpha = 0.2;
32+
graphic.beginFill(0xFF33FF);
33+
graphic.drawPolygon(this);
34+
graphic.endFill();
35+
game.input.onDown.add(this.click, this);
36+
//Init cases
37+
this.cases = new Array();
38+
for (var i = 0; i < this.size; i++) {
39+
this.cases[i] = new Array();
40+
for (var j = 0; j < this.size; j++) {
41+
this.cases[i][j] = null;
42+
}
43+
}
44+
}
45+
Board.prototype.translate = function (x, y) {
46+
for (var _i = 0, _a = this.points; _i < _a.length; _i++) {
47+
var p = _a[_i];
48+
p.setTo(p.x + x, p.y + y);
49+
}
50+
};
51+
Board.prototype.click = function (pointer) {
52+
if (this.contains(pointer.x, pointer.y)) {
53+
console.log(pointer.x, pointer.y);
54+
var _a = this.xyToij(pointer.x, pointer.y), i = _a[0], j = _a[1];
55+
console.log(i, j);
56+
var _b = this.ijToxy(0, 0), x = _b[0], y = _b[1];
57+
console.log(x, y);
58+
new Oddkyn.Case(this.game, x, y, "grass");
59+
}
60+
};
61+
Board.prototype.addCase = function (i, j) {
62+
};
63+
Board.prototype.xyToij = function (x, y) {
64+
var xx = x - (this.game.width * 0.5 - this.size * 0.5 * Oddkyn.Case.Data.width);
65+
var yy = y - (this.game.height * 0.5 - this.size * 0.5 * Oddkyn.Case.Data.height);
66+
var i = Math.floor(xx / Oddkyn.Case.Data.width);
67+
var j = Math.floor(yy / (Oddkyn.Case.Data.height));
68+
return [i, j];
69+
};
70+
Board.prototype.ijToxy = function (i, j) {
71+
var x = this.gameHalfWidth + (i - j - 1) * Oddkyn.Case.Data.halfWidth;
72+
var C = this.gameHalfHeight - (Oddkyn.Case.Data.halfHeight - Oddkyn.Case.Data.upperSide) -
73+
(((this.size + 1) * 0.5 - 1) * Oddkyn.Case.Data.upperSide -
74+
(this.size - 1) * Oddkyn.Case.Data.upperSide);
75+
var y = C + (i + j) * (Oddkyn.Case.Data.halfHeight - Oddkyn.Case.Data.upperSide);
76+
return [x, y];
77+
};
78+
return Board;
79+
}(Phaser.Polygon));
80+
Oddkyn.Board = Board;
81+
})(Oddkyn || (Oddkyn = {}));
82+
var Oddkyn;
83+
(function (Oddkyn) {
84+
var Boot = (function (_super) {
85+
__extends(Boot, _super);
86+
function Boot() {
87+
_super.apply(this, arguments);
88+
}
89+
Boot.prototype.init = function () {
90+
this.idx = 0;
91+
};
92+
Boot.prototype.preload = function () {
93+
this.load.image('preLoadBar', 'assets/loader.png');
94+
this.load.image('phaser', 'assets/splashs/phaser.png');
95+
};
96+
Boot.prototype.create = function () {
97+
//let splashs_key = this.game.cache.getKeys(Phaser.Cache.IMAGE);
98+
var splash_keys = [];
99+
var idx = splash_keys.indexOf('preLoadBar');
100+
idx > -1 ? splash_keys.splice(idx, 1) : [];
101+
var splash_events = this.time.events.repeat(
102+
//4 * Phaser.Timer.SECOND,
103+
0, splash_keys.length + 1, this.showSplash, this, splash_keys);
104+
};
105+
Boot.prototype.showSplash = function (keys) {
106+
if (this.idx < keys.length) {
107+
var splash = new Splash(this.game, keys[this.idx]);
108+
this.idx++;
109+
}
110+
else {
111+
this.game.state.start('PreLoader', true, false);
112+
}
113+
};
114+
return Boot;
115+
}(Phaser.State));
116+
Oddkyn.Boot = Boot;
117+
})(Oddkyn || (Oddkyn = {}));
118+
var Oddkyn;
119+
(function (Oddkyn) {
120+
(function (Orientation) {
121+
Orientation[Orientation["North"] = 0] = "North";
122+
Orientation[Orientation["West"] = 1] = "West";
123+
Orientation[Orientation["South"] = 2] = "South";
124+
Orientation[Orientation["East"] = 3] = "East";
125+
})(Oddkyn.Orientation || (Oddkyn.Orientation = {}));
126+
var Orientation = Oddkyn.Orientation;
127+
var Visual = (function (_super) {
128+
__extends(Visual, _super);
129+
function Visual(game, x, y, key, ori) {
130+
if (ori === void 0) { ori = Orientation.North; }
131+
_super.call(this, game, x, y, key);
132+
this.inputEnabled = true;
133+
this.input.pixelPerfectOver = true;
134+
this.input.pixelPerfectClick = true;
135+
this.orientation = ori;
136+
this.frame = this.orientation;
137+
}
138+
Visual.prototype.rotateRight = function () {
139+
this.frame = (this.orientation + 1) % 4;
140+
};
141+
Visual.prototype.rotateLeft = function () {
142+
this.frame = (this.orientation - 1) % 4;
143+
};
144+
return Visual;
145+
}(Phaser.Sprite));
146+
Oddkyn.Visual = Visual;
147+
})(Oddkyn || (Oddkyn = {}));
148+
/// <reference path="Visual.ts" />
149+
var Oddkyn;
150+
(function (Oddkyn) {
151+
var Case = (function (_super) {
152+
__extends(Case, _super);
153+
function Case(game, x, y, key, ori) {
154+
if (ori === void 0) { ori = Oddkyn.Orientation.North; }
155+
_super.call(this, game, x, y, key, ori);
156+
this.events.onInputOver.add(this.mouseOver, this);
157+
this.events.onInputOut.add(this.mouseOut, this);
158+
game.add.existing(this);
159+
this.effects = key;
160+
}
161+
Case.prototype.mouseOver = function () {
162+
this.tint = 0x00FF00;
163+
};
164+
Case.prototype.mouseOut = function () {
165+
this.tint = 0xFFFFFF;
166+
};
167+
return Case;
168+
}(Oddkyn.Visual));
169+
Oddkyn.Case = Case;
170+
var Case;
171+
(function (Case) {
172+
var Data = (function () {
173+
function Data() {
174+
}
175+
Data.height = 66;
176+
Data.width = 100;
177+
Data.halfHeight = Data.height * 0.5;
178+
Data.halfWidth = Data.width * 0.5;
179+
Data.side = 12;
180+
Data.upperSide = 6;
181+
Data.lowerSide = 6;
182+
return Data;
183+
}());
184+
Case.Data = Data;
185+
})(Case = Oddkyn.Case || (Oddkyn.Case = {}));
186+
})(Oddkyn || (Oddkyn = {}));
187+
var Oddkyn;
188+
(function (Oddkyn) {
189+
var Game = (function (_super) {
190+
__extends(Game, _super);
191+
function Game() {
192+
_super.call(this, 800, 600, Phaser.AUTO, 'game', null);
193+
this.state.add('Boot', Oddkyn.Boot, false);
194+
this.state.add('PreLoader', Oddkyn.PreLoader, false);
195+
this.state.add('LevelEditor', Oddkyn.LevelEditor, false);
196+
this.state.start('Boot', true, true);
197+
}
198+
return Game;
199+
}(Phaser.Game));
200+
Oddkyn.Game = Game;
201+
})(Oddkyn || (Oddkyn = {}));
202+
// when the page has finished loading, create our game
203+
window.onload = function () {
204+
var game = new Oddkyn.Game();
205+
};
206+
/// <reference path="Board.ts" />
207+
var Oddkyn;
208+
(function (Oddkyn) {
209+
var LevelEditor = (function (_super) {
210+
__extends(LevelEditor, _super);
211+
function LevelEditor() {
212+
_super.apply(this, arguments);
213+
}
214+
LevelEditor.prototype.init = function () {
215+
this.game.stage.backgroundColor = "#A4A4A4";
216+
};
217+
LevelEditor.prototype.preload = function () {
218+
};
219+
LevelEditor.prototype.create = function () {
220+
this.board = new Oddkyn.Board(this.game, 5);
221+
};
222+
return LevelEditor;
223+
}(Phaser.State));
224+
Oddkyn.LevelEditor = LevelEditor;
225+
})(Oddkyn || (Oddkyn = {}));
226+
/// <reference path="../tsDefinitions/phaser.d.ts" />
227+
var Splash = (function () {
228+
function Splash(game, key) {
229+
this.sprite = game.add.sprite(game.world.centerX, game.world.centerY, key);
230+
this.sprite.alpha = 0;
231+
this.sprite.anchor.set(0.5, 0.5);
232+
this.tween = game.add.tween(this.sprite).to({ alpha: 1 }, 3 * Phaser.Timer.SECOND, "Linear", true, 0, 0);
233+
this.tween.onComplete.add(this.end, this);
234+
}
235+
Splash.prototype.end = function () {
236+
this.sprite.game.time.events.add(Phaser.Timer.SECOND, this.kill, this);
237+
};
238+
Splash.prototype.kill = function () {
239+
this.sprite.game.cache.removeImage(this.sprite.name);
240+
this.sprite.kill();
241+
};
242+
return Splash;
243+
}());
244+
/// <reference path="../tsDefinitions/phaser.d.ts" />
245+
/// <reference path="../src/Splash.ts" />
246+
var LOL = (function () {
247+
function LOL() {
248+
// create our phaser game
249+
// 800 - width
250+
// 600 - height
251+
// Phaser.AUTO - determine the renderer automatically (canvas, webgl)
252+
// 'content' - the name of the container to add our game to
253+
// { preload:this.preload, create:this.create} - functions to call for our states
254+
this.game = new Phaser.Game(800, 600, Phaser.AUTO, 'game', { preload: this.preload, create: this.create });
255+
//this.game.add('Load', )
256+
this.idx = 0;
257+
}
258+
LOL.prototype.preload = function () {
259+
};
260+
LOL.prototype.create = function () {
261+
var splashs_key = this.game.cache.getKeys(Phaser.Cache.IMAGE);
262+
var splash_events = this.game.time.events.repeat(3 * Phaser.Timer.SECOND, splashs_key.length, this.showSplash, this);
263+
};
264+
LOL.prototype.showSplash = function (keys) {
265+
if (this.idx < keys.length) {
266+
var splash = new Splash(this.game, keys[this.idx]);
267+
}
268+
else {
269+
this.game.cache.destroy();
270+
this.game.state.start('Load');
271+
}
272+
};
273+
return LOL;
274+
}());
275+
var Oddkyn;
276+
(function (Oddkyn) {
277+
var PreLoader = (function (_super) {
278+
__extends(PreLoader, _super);
279+
function PreLoader() {
280+
_super.apply(this, arguments);
281+
}
282+
PreLoader.prototype.preload = function () {
283+
this.preLoadBar = this.add.sprite(200, 250, 'preLoadBar');
284+
this.load.setPreloadSprite(this.preLoadBar);
285+
this.load.spritesheet('grass', 'assets/tiles/grass.png', 100, 66, 4);
286+
//this.load.spritesheet('dirt', 'assets/tiles/dirt.png', 50, 50, 4);
287+
};
288+
PreLoader.prototype.create = function () {
289+
var tween = this.add.tween(this.preLoadBar).to({ alpha: 0 }, 1000, Phaser.Easing.Linear.None, true);
290+
tween.onComplete.add(this.startMainMenu, this);
291+
};
292+
PreLoader.prototype.startMainMenu = function () {
293+
this.game.state.start('LevelEditor', true, false);
294+
};
295+
return PreLoader;
296+
}(Phaser.State));
297+
Oddkyn.PreLoader = PreLoader;
298+
})(Oddkyn || (Oddkyn = {}));

bin/js/phaser.min.js

+28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)