Created
July 30, 2015 20:39
-
-
Save uupaa/282c7d07123aa466bee8 to your computer and use it in GitHub Desktop.
game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <meta charset="utf-8"> | |
| <script src="Retro.js"></script><script> | |
| GLOBAL.WebModule.publish = true; | |
| onload = function() { | |
| game = new Game({ w: 800, h: 400 }); | |
| game.assset = url; | |
| game.ready(function() { | |
| var sprite = new Sprite(100, 100); | |
| sprite.x = 10; | |
| sprite.y = 10; | |
| sprite.image = game.assset.url; | |
| game.rootScene += sprite; | |
| }); | |
| game.start(); | |
| }; | |
| </script> | |
| <meta charset="utf-8"> | |
| <script src="Retro.js"></script><script> | |
| GLOBAL.WebModule.publish = true; | |
| /* | |
| game.assset = url; | |
| game.ready(function() { | |
| var sprite = new Sprite(100, 100); | |
| sprite.x = 10; | |
| sprite.y = 10; | |
| sprite.image = game.assset.url; | |
| game.rootScene += sprite; | |
| }); | |
| game.start(); | |
| */ | |
| var game = new Game({ w: 800, h: 400 }); | |
| game.asset = { id: url, ... }; // setter | |
| game.asset = [url, ....]; // setter | |
| game.asset = url; // setter | |
| // どんどん追記できる | |
| // set された内容は裏で遅延ロードされる | |
| game.asset[url] // getter Object を返す | |
| // アセットを取得できる | |
| game.asset.length // アセット数を返す | |
| game.asset.loaded // ロード済みのアセット数を返す | |
| function GameAsset() { | |
| this._remain = []; | |
| this._assets = { | |
| length: 0, | |
| loaded: 0 | |
| }; | |
| } | |
| function _load() { | |
| this._remain.shift(); | |
| function loaded() { | |
| // TODO: impl | |
| this._assets[id] = object; | |
| this._assets.length += 1; | |
| this._assets.loaded += 1; | |
| } | |
| } | |
| GameAsset["prototype"] = Object.create(GameAsset, { | |
| "asset": { "get": function() { return { this._object; }, | |
| "set": function(v) { | |
| if (Array.isArray(v)) { | |
| Array.prototype.push.apply(this._remain, v); | |
| } else if (typeof v === "object") { | |
| this._remain.push(v); | |
| } else { | |
| this._remain.push(v); | |
| } | |
| _load.call(this); | |
| } }, | |
| }); | |
| game.prototype.load = function(task) { | |
| // TBD: アセットロードも一緒にやる | |
| if (document.readyState === "complete") { | |
| task.pass(); | |
| } else { | |
| window.onload = task.passfn; | |
| } | |
| }; | |
| var GameTask = TaskMap; | |
| new GameTask("Game", "Load -> GameLoop -> Ending -> GameOver", { | |
| Load: game.load, | |
| GameLoop: gameLoop, | |
| Ending: ending, | |
| GameOver: function(task) { | |
| console.log("GameOver"); | |
| task.pass(); | |
| } | |
| }, function() { | |
| onload(); | |
| }); | |
| function gameLoop(task) { | |
| if (gameOver) { | |
| task.pass(); | |
| } | |
| } | |
| </script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment