Skip to content

Commit

Permalink
added new iamges. character creation, movement, and split scripts up …
Browse files Browse the repository at this point in the history
…a bit.
  • Loading branch information
jwoertink committed Jun 28, 2010
1 parent 67a8387 commit 136960d
Show file tree
Hide file tree
Showing 21 changed files with 253 additions and 1,498 deletions.
Binary file added images/scientist_e0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/scientist_e1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/scientist_e2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/scientist_n0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/scientist_n1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/scientist_n2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/scientist_s0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/scientist_s1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/scientist_s2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/scientist_w0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/scientist_w1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/scientist_w2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 35 additions & 2 deletions index.html
Expand Up @@ -7,10 +7,43 @@
</head>
<body>
<div id="wrapper">
<canvas id="canvas" width="640" height="400"></canvas>
<canvas id="canvas" width="144" height="144"></canvas>
<div id="debug"></div>
</div>
<script src="scripts/jquery.js"></script>
<script src="scripts/engine.js"></script>
<script src="scripts/game.js"></script>
<script src="scripts/game.keyboard.js"></script>
<script src="scripts/game.player.js"></script>
<script type="text/javascript" charset="utf-8">
var mapone = [
[{ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}],
[{ground:1, item:2}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1, item:2}],
[{ground:1, item:2}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1, item:2}],
[{ground:1, item:2}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1, item:2}],
[{ground:1, item:2}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1, item:2}, {ground:1}, {ground:1}, {ground:1}, {ground:1, item:2}],
[{ground:1, item:2}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1, item:2}, {ground:1, item:2}, {ground:1}, {ground:1}, {ground:1, item:2}],
[{ground:1, item:2}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1, item:2}, {ground:1}, {ground:1}, {ground:1, item:2}],
[{ground:1, item:2}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1, item:2}, {ground:1}, {ground:1}, {ground:1, item:2}],
[{ground:1, item:2}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1, item:2}, {ground:1}, {ground:1}, {ground:1, item:2}],
[{ground:1, item:2}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1, item:2}],
[{ground:1, item:2}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1, item:2}],
[{ground:1, item:2}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1, item:2}],
[{ground:1, item:2}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1}, {ground:1, item:2}],
[{ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}, {ground:1, item:2}]
];


// Start game.

$(window).load(function() {
Game.start(mapone, 0, 0);
$(window).keydown(function(event) {
if(Game.controls[event.keyCode] != null) {
Game.keyboard.parseInput(event);
event.preventDefault;
}
});
});
</script>
</body>
</html>
Binary file modified scripts/.DS_Store
Binary file not shown.
201 changes: 0 additions & 201 deletions scripts/engine.js

This file was deleted.

135 changes: 135 additions & 0 deletions scripts/game.js
@@ -0,0 +1,135 @@
// jQuery 1.4.2 is required
// Create the main game object
var Game = {};
Game.characters = [];
Game.controls = {40: "down", 39: "right", 38: "up", 37: "left"};
Game.currentMap = null;

// This is for the debug area. could use console later
Game.log = $('#debug');
// The main canvas window
Game.canvas = $('#canvas')[0];
// the main context
Game.handle = Game.canvas.getContext('2d');

// the debugger function
Game.debug = function(message, _console) {
if(_console) {
window.console.log(message);
} else {
var now = new Date();
timestamp = (now.getHours()) + ':' + (now.getMinutes() + 1) + ':' + (now.getSeconds() + 1);
Game.log.prepend('<p>'+timestamp+'&raquo;&nbsp;' + message + '</p>');
}
};

Game.setMap = function(mapData) {
Game.currentMap = mapData;
}

Game.screen = {
width: Game.canvas.width,
height: Game.canvas.height,
tilesX: Game.canvas.width / 16,
tilesY: Game.canvas.height / 16
};

Game.viewport = {
x: 0,
y: 0
};

Game.tile = {
draw: function(x, y, tile) {
var img = Game.tile.retrieve(tile.ground);
Game.handle.drawImage(img, x * 16, y * 16);
if(tile.item) {
Game.handle.drawImage(Game.tile.retrieve(tile.item), x* 16, y * 16);
}
},
images: [],
store: function(id, imgSrc) {
var newid = Game.tile.images.length;
var tile = [id, new Image(), false];
tile[1].src = imgSrc;
tile[1].onload = function() {
tile[2] = true;
}
Game.tile.images[newid] = tile
},
retrieve: function(id) {
var i, len = Game.tile.images.length;

for(i=0; i < len; i++) {
if(Game.tile.images[i][0] == id) {
return Game.tile.images[i][1];
}
}
},
allLoaded: function() {
var i, len = Game.tile.images.length;
for(i=0;i<len;i++) {
if(Game.tile.images[i][2] == false) {
return false;
}
}

return true;
}
};

Game.map = {
draw: function() {
var xPos, yPos;
var mapX = 0;
var mapY = 0;
var tile;

Game.debug('drawing map from ' + Game.viewport.x + ',' + Game.viewport.y + ' to ' + (Game.viewport.x + Game.screen.tilesX) + ',' + (Game.viewport.y + Game.screen.tilesY));

for(yPos = 0; yPos < Game.screen.tilesY; yPos++) {
for(xPos = 0; xPos < Game.screen.tilesX; xPos++) {
mapX = xPos + Game.viewport.x;
mapY = yPos + Game.viewport.y;
tile = (Game.currentMap[mapY] && Game.currentMap[mapY][mapX]) ? Game.currentMap[mapY][mapX] : {ground: 0};
Game.tile.draw(xPos, yPos, tile);
}
}
}
};

Game.draw = function(mapData) {
if(Game.tile.allLoaded() === false) {
setTimeout(Game.draw, 100);
} else {
Game.map.draw();
Game.player.draw();
}
}

Game.start = function(mapData, x, y) {
Game.handle.translate(0,0);
Game.debug('starting...');
Game.viewport.x = x;
Game.viewport.y = y;
Game.tile.store(0, 'images/tile_black.png');
Game.tile.store(1, 'images/tile_grass.png');
Game.tile.store(2, 'images/tile_rock.png');
Game.setMap(mapData);

Game.player.store(0, 'images/scientist_n0.png');
Game.player.store(1, 'images/scientist_n1.png');
Game.player.store(2, 'images/scientist_n2.png');
Game.player.store(3, 'images/scientist_e0.png');
Game.player.store(4, 'images/scientist_e1.png');
Game.player.store(5, 'images/scientist_e2.png');
Game.player.store(6, 'images/scientist_s0.png');
Game.player.store(7, 'images/scientist_s1.png');
Game.player.store(8, 'images/scientist_s2.png');
Game.player.store(9, 'images/scientist_w0.png');
Game.player.store(10, 'images/scientist_w1.png');
Game.player.store(11, 'images/scientist_w2.png');

Game.draw();
Game.debug('done');
};

0 comments on commit 136960d

Please sign in to comment.