delay canvas drawing, only update location.href if idle, add bhickey maps

This commit is contained in:
Stefan Bühler 2012-07-15 13:41:24 +02:00
parent 1a69b4673a
commit dc3726f4c0
7 changed files with 108 additions and 14 deletions

View File

@ -6,6 +6,7 @@ MAPS+=$(wildcard ../maps/flood*.map)
MAPS+=$(wildcard ../maps/contest?.map ../maps/contest10.map) MAPS+=$(wildcard ../maps/contest?.map ../maps/contest10.map)
MAPS+=$(wildcard ../maps/ems*.map) MAPS+=$(wildcard ../maps/ems*.map)
MAPS+=../maps/pacman.map ../maps/pacman2.map MAPS+=../maps/pacman.map ../maps/pacman2.map
MAPS+=$(wildcard ../maps/bhickey*.map)
all: maps.js sprites.png gui.min.js mine.min.js maps.min.js all: maps.js sprites.png gui.min.js mine.min.js maps.min.js

View File

@ -221,8 +221,8 @@ function mineGui_setMap(map, ndx) {
mineGui_curmap = mineMaps[map]; mineGui_curmap = mineMaps[map];
mineGui_curndx = ndx; mineGui_curndx = ndx;
mineGui_moves = mineGui_movesBackup[mineGui_curndx]; mineGui_moves = mineGui_movesBackup[mineGui_curndx];
location.href = '#' + mineGui_mapname + ';' + mineGui_moves;
if (!mineGui_moves) mineGui_moves = ""; if (!mineGui_moves) mineGui_moves = "";
location.href = '#' + mineGui_mapname + ';' + mineGui_moves;
mineGui_updateMine(); mineGui_updateMine();
} }
@ -239,25 +239,26 @@ function mineGui_updateMine() {
mineGui_show(); mineGui_show();
} }
function mineGui_show() { var mineGui_drawQueued = false;
if (!mineGui_mine) return; function mineGui_draw() {
if (!mineGui_drawQueued) {
mineGui_drawQueued = true;
window.setTimeout(mineGui_draw_queued, 0);
}
}
function mineGui_draw_queued() {
mineGui_drawQueued = false;
location.href = '#' + mineGui_mapname + ';' + mineGui_moves;
var state = "";
var spriteOffset = mineGui_spriteOffset; var spriteOffset = mineGui_spriteOffset;
switch (mineGui_mine.state) { switch (mineGui_mine.state) {
case Mine.ALIVE: case Mine.ALIVE:
state = "Still mining";
break; break;
case Mine.LOST: case Mine.LOST:
state = "Robot broken - " + mineGui_mine.reason;
spriteOffset = mineGui_spriteOffset_Lost; spriteOffset = mineGui_spriteOffset_Lost;
break; break;
case Mine.ABORTED: case Mine.ABORTED:
state = "Aborted";
break; break;
case Mine.WON: case Mine.WON:
state = "Won - " + mineGui_mine.reason;
spriteOffset = mineGui_spriteOffset_Won; spriteOffset = mineGui_spriteOffset_Won;
break; break;
} }
@ -278,7 +279,7 @@ function mineGui_show() {
ctx.fillStyle = "black"; ctx.fillStyle = "black";
ctx.fillRect(0,0,canv.width, canv.height); ctx.fillRect(0,0,canv.width, canv.height);
var sprites = mineGui_images.sprites; var sprites = mineGui_images.sprites;
for (var y = 0; y < mineGui_mine.height; ++y) { for (var y = 0; y < mineGui_mine.height; ++y) {
for (var x = 0; x < mineGui_mine.width; ++x) { for (var x = 0; x < mineGui_mine.width; ++x) {
ctx.drawImage(sprites, 0, spriteOffset[map[y][x]] * 16, 16, 16, 16*x, 16*y, 16, 16); ctx.drawImage(sprites, 0, spriteOffset[map[y][x]] * 16, 16, 16, 16*x, 16*y, 16, 16);
@ -294,7 +295,45 @@ function mineGui_show() {
mapNode.style.display = ''; mapNode.style.display = '';
mapNode.style.visibility = 'visible'; mapNode.style.visibility = 'visible';
} }
}
var mineGui_fragmentQueued = false;
function mineGui_updateFragment() {
if (false !== mineGui_fragmentQueued) window.clearTimeout(mineGui_fragmentQueued);
mineGui_fragmentQueued = window.setTimeout(mineGui_updateFragment_queued, 100);
}
function mineGui_updateFragment_queued() {
mineGui_fragmentQueued = false;
location.href = '#' + mineGui_mapname + ';' + mineGui_moves;
}
function mineGui_show(queued) {
if (!mineGui_mine) return;
mineGui_updateFragment();
var state = "";
switch (mineGui_mine.state) {
case Mine.ALIVE:
state = "Still mining";
break;
case Mine.LOST:
state = "Robot broken - " + mineGui_mine.reason;
break;
case Mine.ABORTED:
state = "Aborted";
break;
case Mine.WON:
state = "Won - " + mineGui_mine.reason;
break;
}
var waterLevel = Math.max(mineGui_mine.water_level, 0);
var map = mineGui_mine.toString().split(/\n/);
mineGui_draw();
if (waterLevel > 0) { if (waterLevel > 0) {
document.getElementById("mineGui_mineMapWater").textContent = map.splice(-waterLevel).join("\n"); document.getElementById("mineGui_mineMapWater").textContent = map.splice(-waterLevel).join("\n");
} else { } else {

2
js/gui.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
js/maps.min.js vendored

File diff suppressed because one or more lines are too long

26
maps/bhickey1.map Normal file
View File

@ -0,0 +1,26 @@
################################ ##
#******#******#******#**********L #
##*****##*****##*****##********* #
#*#****#*#****#*#****#*#*******## #
# *#***# *#***# *#***# *#*****# # #
# *#**# *#**# *#**# *#***# # #
# *#*# *#*# *#*# *#*# # #
# *A* *B* *C* *D* # #
# \ \ \ \ # #
# * * * * # #
#*******************************# #
#R..............................# #
#\ # #
#1 # #
# # #
################################# #
# WE #
###################################
Growth 1
Trampoline A targets 1
Trampoline B targets 1
Trampoline C targets 1
Trampoline D targets 1
Trampoline E targets 1
Author bhickey (https://gist.github.com/3115673)

28
maps/bhickey2.map Normal file
View File

@ -0,0 +1,28 @@
###L######################
#W#R #*****#!#\\\\\\\\\##
#*# ..\.. #\\\\\\\*\##
#*#A 2####### ########.###
#*# #*****# #*****#B 3##
#*# ..\.. ..\.. ##
#**E 5 ############## ##
#***.##C 1\ D# ####
#***. #****###****# ***##
#*** #G...\4 ...H# ..\ #
#\## ################# ##
#\\# #*****#F 6##*** ##
#\\# ..\.. ... ##
####################### ##
##########################
Water 0
Flooding 20
Waterproof 18
Trampoline A targets 1
Trampoline B targets 1
Trampoline C targets 2
Trampoline D targets 3
Trampoline E targets 4
Trampoline F targets 4
Trampoline G targets 5
Trampoline H targets 6
Author bhickey (https://gist.github.com/3114986)