76 lines
1.5 KiB
JavaScript
76 lines
1.5 KiB
JavaScript
$(document).ready(function() {
|
|
onPageLoaded();
|
|
});
|
|
|
|
var _running = false;
|
|
var _canvas;
|
|
var _ctx;
|
|
|
|
var player;
|
|
var backgroundImage;
|
|
var tileset;
|
|
|
|
function onPageLoaded() {
|
|
setInterval(run, 1000 / 50);
|
|
|
|
_canvas = document.getElementById("GameCanvas");
|
|
_ctx = _canvas.getContext("2d");
|
|
|
|
backgroundImage = new Image();
|
|
backgroundImage.src = "content/background-sunset.png";
|
|
backgroundImage.onload = function() {
|
|
_running = true;
|
|
};
|
|
|
|
tileset = new Tileset();
|
|
}
|
|
|
|
function run() {
|
|
if (_running) {
|
|
update();
|
|
draw();
|
|
}
|
|
}
|
|
|
|
function update() {
|
|
$("#InfoBgSrc")[0].innerHTML = backgroundImage.src.substring(backgroundImage.src.lastIndexOf("/") + 1);
|
|
}
|
|
|
|
function draw() {
|
|
// draw background
|
|
_ctx.drawImage(backgroundImage, 0, 0);
|
|
|
|
// Draw level tiles
|
|
if (tileset.Loaded) {
|
|
var rowIndex = 0;
|
|
for (var i = 0; i < level.Tiles.length; i++) {
|
|
for (var j = 0; j < level.tiles[i].length; j++) {
|
|
var levelTileID = cellPosToTilePos([rowIndex, j]);
|
|
var tilesetPos = tileset.tileIDToTilesetPos(level.tiles[i][j].getID());
|
|
var tilePos = [rowIndex * tileEngine.tileSize, j * tileEngine.tileSize];
|
|
|
|
canvasCtx.drawImage(
|
|
tileset.image,
|
|
tilesetPos[0],
|
|
tilesetPos[1],
|
|
tileEngine.tileSize,
|
|
tileEngine.tileSize,
|
|
Math.ceil((levelTileID % level.width) * tileEngine.tileSize),
|
|
Math.floor((levelTileID / level.height)) * tileEngine.tileSize,
|
|
tileEngine.tileSize, tileEngine.tileSize
|
|
);
|
|
}
|
|
|
|
rowIndex ++;
|
|
}
|
|
}
|
|
}
|
|
|
|
/******
|
|
OBJECTS
|
|
******/
|
|
var FileManager = {
|
|
getFileContent : function () {
|
|
|
|
},
|
|
}
|