Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
169 additions
and
1,051 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
TODO: | ||
|
||
- implement singleton pattern in fusite.js | ||
- implement GameMap like GamePlayer in fusite |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
( function(window, undefined) { | ||
|
||
function GamePlayer() { | ||
this.initialize(); | ||
} | ||
|
||
var p = GamePlayer.prototype; | ||
|
||
p._assetManager; | ||
|
||
p.stage; | ||
|
||
p._spritePosition = 's0'; | ||
|
||
/* | ||
* Constructor | ||
*/ | ||
p.initialize = function(ctx) { | ||
if (!ctx) return; | ||
|
||
this.stage = ctx; | ||
} | ||
|
||
/* | ||
* Draw player on the map | ||
*/ | ||
p.draw = function(assets) { | ||
if (!this.stage) return; | ||
|
||
this._loadAssets(assets); | ||
assets = null; | ||
}, | ||
|
||
/* | ||
* Calculate the location of the player in the map | ||
*/ | ||
p._calculateLocation = function() { | ||
var character = { | ||
width: this._assetsManager.getAsset('n0').width, | ||
height: this._assetsManager.getAsset('n0').height | ||
}; | ||
|
||
var screen = { | ||
width: 144, // Fix me: get data from Fusite object | ||
height: 144 // Fix me: get data from Fusite object | ||
}; | ||
|
||
var x = (screen.width / 2) - (character.width / 2), | ||
y = (screen.height / 2)+ 8 - (character.height); | ||
|
||
return {left: x, top: y}; | ||
} | ||
|
||
/* | ||
* Load all assets required for the map | ||
*/ | ||
p._loadAssets = function(assets) { | ||
var assetsLoaded = 0, | ||
self = this; | ||
|
||
this._assetsManager = new AssetManager(); | ||
|
||
for(var i=0, len=assets.length; i < len; i++) { | ||
this._assetsManager.queueDownload(assets[i]); | ||
} | ||
this._assetsManager.downloadAll(function(){ | ||
assetsLoaded++; | ||
|
||
if (assetsLoaded == assets.length) { | ||
self._assetsLoaded = true; | ||
|
||
self._render(); | ||
|
||
assets = null; | ||
} | ||
}); | ||
} | ||
|
||
p._render = function() { | ||
var loc = this._calculateLocation(); | ||
this.stage.drawImage( this._assetsManager.getAsset(this._spritePosition), loc.left, loc.top ); | ||
} | ||
|
||
p.update = function(position) { | ||
this._spritePosition = position; | ||
this._render(); | ||
} | ||
|
||
window.GamePlayer = GamePlayer; | ||
})(window) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,41 @@ | ||
var Fusite = function() { | ||
|
||
var gs; | ||
var gs, | ||
SCREEN_WIDTH, | ||
SCREEN_HEIGHT; | ||
|
||
/* | ||
* The fun begins | ||
*/ | ||
function start(options) { | ||
gs = new GameStage( window.document.getElementById('canvas') ); | ||
gs.width(160); | ||
gs.height(160); | ||
gs.start(options.map, options.tiles); | ||
} | ||
|
||
function drawMap(map) { | ||
gs.drawMap(map); | ||
} | ||
|
||
function setTiles() { | ||
|
||
} | ||
|
||
function addPlayers() { | ||
SCREEN_WIDTH = options.screenWidth; | ||
SCREEN_HEIGHT = options.screenHeight; | ||
SPRITE_SIZE = (options.spriteSize) ? options.spriteSize : 16; | ||
|
||
gs.width(SCREEN_WIDTH); | ||
gs.height(SCREEN_HEIGHT); | ||
gs.start(options.map, options.tiles); | ||
} | ||
|
||
function addPlayer() { | ||
|
||
/* | ||
* Add player to the game | ||
* | ||
* @params object { | ||
* name: '' | ||
* sprites: [] | ||
* } | ||
*/ | ||
function player(options) { | ||
gs.addPlayer(options); | ||
} | ||
|
||
return { | ||
start: start, | ||
drawMap: drawMap, | ||
setTiles: setTiles, | ||
addPlayer: addPlayer, | ||
addPlayers: addPlayers | ||
player: player, | ||
SCREEN_WIDTH: SCREEN_WIDTH, | ||
SCREEN_HEIGHT: SCREEN_HEIGHT | ||
} | ||
|
||
}(); |
Oops, something went wrong.