Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>tileEngine - Isometric</title>
- <style type="text/javascript">
- * { margin: 0px; padding: 0px; font-family: arial, helvetica, sans-serif; font-size: 12px; cursor: default; }
- body,html {
- background-image: url(wood.jpg);
- overflow: hidden;
- }
- #hud {
- background-color: #000;
- color: #c4c4c4;
- padding: 5px 0px 5px 0px;
- }
- #main {
- border:#333;
- border-width:0px;
- border-style:solid;
- }
- input {
- width: 30px;
- border: 1px solid #666;
- background-color: #c4c4c4;
- text-align: center;
- font-weight: bold;
- }
- #hp {
- color: #000;
- width: 35px;
- font-size: 16px;
- }
- #money {
- color: gold;
- background-color: #181818;
- }
- #pts {
- font-size: 16px;
- width: 35px;
- color: red;
- }
- #time {
- width: 55px;
- color: #666;
- }
- #status {
- float: right;
- position: absolute;
- right: 5px;
- top: 55px;
- width: 200px;
- height: 175px;
- border: 1px solid #666;
- -webkit-border-radius: 15px;
- -moz-border-radius: 15px;
- border-radius: 15px;
- font-size: 16px;
- color: #fff;
- text-align: center;
- padding: 10px 5px 5px 5px;
- -moz-opacity:.50;
- filter:alpha(opacity=50);
- opacity:.50
- }
- #infoKey {
- float: left;
- position: absolute;
- left: 5px;
- top: 55px;
- width: 120px;
- height: 155px;
- border: 1px solid #666;
- -webkit-border-radius: 15px;
- -moz-border-radius: 15px;
- border-radius: 15px;
- font-size: 11px;
- color: #fff;
- text-align: left;
- padding: 5px 5px 5px 5px;
- -moz-opacity:.50;
- filter:alpha(opacity=50);
- opacity:.50
- }
- </style>
- <script type="text/javascript">
- var you; //you
- var time = 0;
- //player starting position
- var playerX = 0;
- var playerY = 1;
- var map = Array( //land
- [1,0,1,1,1,1,1,1,1,1,1,1,1,1,1],
- [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
- [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
- [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
- [1,0,0,0,0,0,0,0,0,0,0,0,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,0,0,6,0,0,0,0,0,0,0,1],
- [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
- [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
- [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
- [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
- );
- var tileDict = Array("tiles/land.png","tiles/water.png","tiles/swamp.png","tiles/land-road-up.png","tiles/land-road-down.png","tiles/land-road-corner1.png","tiles/soil.png","tiles/land-seeded.png");
- var charDict = Array("tiles/mario.png");
- var objectDict = Array("tiles/blank.png","tiles/rock.png","tiles/hut.png","tiles/flowers.png","tiles/golden-flowers.png","tiles/treelarge.png"); //value +1
- var objectImg = new Array();
- var charImg = new Array();
- var tileImg = new Array();
- var loaded = 0;
- var loadTimer;
- var ymouse;
- var xmouse;
- function loadImg(){ //preload images and calculate the total loading time
- for(var i=0;i<tileDict.length;i++){
- tileImg[i] = new Image();
- tileImg[i].src = tileDict[i];
- tileImg[i].onload = function(){
- loaded++;
- }
- }
- i = 0;
- for(var i=0;i<charDict.length;i++){
- charImg[i] = new Image();
- charImg[i].src = charDict[i];
- charImg[i].onload = function(){
- loaded++;
- }
- }
- i = 0;
- for(var i=0;i<objectDict.length;i++){
- objectImg[i] = new Image();
- objectImg[i].src = objectDict[i];
- objectImg[i].onload = function(){
- loaded++;
- }
- }
- }
- function checkKeycode(event) { //key pressed
- var keycode;
- if(event == null) {
- keyCode = window.event.keyCode;
- } else {
- keyCode = event.keyCode;
- }
- //document.title = keyCode;
- switch(keyCode) {
- case 38: //left
- if(!objectMap[playerX-1][playerY] > 0){
- playerX--;
- }
- break;
- case 40: //right
- if(!objectMap[playerX+1][playerY] > 0){
- playerX++;
- }
- break;
- case 39: //up
- if(!objectMap[playerX][playerY-1] > 0){
- playerY--;
- }
- break;
- case 37: //down
- if(!objectMap[playerX][playerY+1] > 0){
- playerY++;
- }
- break;
- default:
- break;
- }
- tmpEle = document.getElementById("coords");
- tmpCoord = playerX + ", " + playerY;
- tmpEle.value = tmpCoord;
- }
- function loadAll(){ //load the game
- if(loaded == tileDict.length + charDict.length + objectDict.length){
- clearInterval(loadTimer);
- loadTimer = setInterval(gameUpdate,100);
- }
- }
- function drawMap(){ //draw the map (in intervals)
- var tileH = 25;
- var tileW = 50;
- mapX = 80;
- mapY = 10;
- for(i=0;i<map.length;i++){
- for(j=0;j<map[i].length;j++){
- var drawTile= map[i][j];
- var drawObj = objectMap[i][j];
- var xpos = (i-j)*tileH + mapX*4.5;
- var ypos = (i+j)*tileH/2+ mapY*3.0;
- ctx.drawImage(tileImg[drawTile],xpos,ypos);
- if(drawObj){
- if (drawObj > 0) {
- ctx.drawImage(objectImg[drawObj-1],xpos,ypos-(objectImg[drawObj-1].height/2));
- }
- }
- if(i == playerX && j == playerY){
- you = ctx.drawImage(charImg[0],xpos,ypos-(charImg[0].height/2));
- }
- }
- }
- }
- function init(){ //initialise the main functions and even handlers
- setInterval('updateClock()',1000);
- ctx = document.getElementById('main').getContext('2d');
- loadImg();
- loadTimer = setInterval(loadAll,100);
- //document.getElementById("main").addEventListener("mousemove", mouseCheck, false);
- //document.getElementById("main").addEventListener("mousedown", mouseClick, false);
- document.onkeydown = checkKeycode;
- tmpEle = document.getElementById("coords");
- tmpCoord = playerX + ", " + playerY;
- tmpEle.value = tmpCoord;
- }
- function gameUpdate() { //update the game, clear canvas etc
- ctx.clearRect(0,0,904,460);
- ctx.fillStyle = "rgba(255, 255, 255, 1.0)"; //assign color
- drawMap();
- }
- function updateClock() {
- time++;
- document.getElementById("time").value = time;
- }
- </script>
- </head>
- <body align="center" style="text-align: center;" onload="init();">
- <div id="hud">
- Co-ords: <input disabled type="text" id="coords" value="" />
- Time: <input disabled type="text" id="time" value="" />
- <br />
- </div>
- <div id="status">
- <!-- status updates -->
- </div>
- <div id="infoKey">
- </div>
- <canvas id="main" width="904" height="465">
- <h1 style="color: white; font-size: 24px;">I'll be damned, there be no HTML5 & canvas support on this 'ere electronic machine!<sub>This game, jus' plain ol' won't work!</sub></h1>
- </canvas>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement