function Get(id){ return document.getElementById(id) ; } function circle(context, x, y, r){ context.arc(x,y,r,0,2*Math.PI,true) ; } function draw_all(){ Math.seed = 6 ; context.fillStyle = 'rgb(255,255,255)' ; context.fillRect(0,0,w,h) ; //draw_grid() ; draw_all_cells() ; draw_cell_contents() ; draw_room_name() ; if(edit_mode) update_surrounding_rooms() ; draw_fade() ; draw_inventory() ; } function draw_room_name(){ if(edit_mode==true) return ; var A = player.A-O_A ; var B = player.B-O_B ; Get('h2_room_name').style.backgroundColor = room.wallEdgeColor ; Get('span_room_name').innerHTML = (spotlight_mode==true) ? ' ' : room.name ; Get('span_room_coords').innerHTML = (spotlight_mode==true) ? ' ' : '(' + A + ',' + B + ')' ; } function draw_grid(){ context.lineWidth = 1 ; context.strokeStyle = 'rgb(200,200,200)' ; for(var i=0 ; inap_steps){ nap_counter = 0 ; napping = false ; draw_all() ; return ; } if(nap_counter<=nap_steps/3){ fade_fill = 'rgba(0,0,0,'+nap_counter/(nap_steps/3)+')' ; } else if(nap_counter<=2*nap_steps/3){ fade_fill = 'rgba(0,0,0,1)' ; } else{ fade_fill = 'rgba(0,0,0,'+(nap_steps-nap_counter)/(nap_steps/3)+')' ; } if(nap_counter==15){ // Do all the sleepy things here. // Restore health etc. } draw_all() ; if(nap_counter>=2+1*nap_steps/3 && nap_counter<=2*nap_steps/3-2){ context.fillStyle = 'rgb(255,255,0)' ; context.font = 'italic 50px georgia' ; context.textAlign = 'center' ; context.fillText('zzz...',0.5*w,0.5*h) ; context.beginPath() ; var x = 0.75*w ; var y = 0.20*h ; context.arc(x,y,0.1*w,0,2*Math.PI,true) ; context.fill() ; context.fillStyle = 'rgb(0,0,0)' ; context.beginPath() ; context.arc(x-0.03*w,y-0.01*h,0.09*w,0,2*Math.PI,true) ; context.fill() ; } window.setTimeout(iterate_nap, nap_delay) ; } var sea_fill_color = 'rgb(150,200,255)' ; var sea_edge_color = 'rgb( 0, 0,255)' ; function wall_object(){ this.is_wall = true ; this.draw = function(context,i,j,tb_flag){ var th = 0 ; var dy0 = 2 ; context.fillStyle = wall_fill_color ; context.fillRect(i*cellSize+th,j*cellSize+th,cellSize-2*th,cellSize-2*th) ; context.strokeStyle = wall_edge_color ; var A = player.A ; var B = player.B ; context.lineCap = 'round' ; var lw = 4 ; context.lineWidth = lw ; if((i!=0 && get_cell(A,B,i-1,j)!=1) || tb_flag){ context.beginPath() ; context.moveTo((i+0)*cellSize+0.5*lw,(j+0)*cellSize+0.5*lw) ; context.lineTo((i+0)*cellSize+0.5*lw,(j+1)*cellSize-0.5*lw) ; context.stroke() ; } if((i!=nCol-1 && get_cell(A,B,i+1,j)!=1) || tb_flag){ context.beginPath() ; context.moveTo((i+1)*cellSize-0.5*lw,(j+0)*cellSize+0.5*lw) ; context.lineTo((i+1)*cellSize-0.5*lw,(j+1)*cellSize-0.5*lw) ; context.stroke() ; } if((j!=0 && get_cell(A,B,i,j-1)!=1) || tb_flag){ context.beginPath() ; context.moveTo((i+0)*cellSize+0.5*lw,(j+0)*cellSize+0.5*lw) ; context.lineTo((i+1)*cellSize-0.5*lw,(j+0)*cellSize+0.5*lw) ; context.stroke() ; } if((j!=nRow-1 && get_cell(A,B,i,j+1)!=1) || tb_flag){ context.beginPath() ; context.moveTo((i+0)*cellSize+0.5*lw,(j+1)*cellSize-0.5*lw) ; context.lineTo((i+1)*cellSize-0.5*lw,(j+1)*cellSize-0.5*lw) ; context.stroke() ; } var nBricksAcross = 2 ; var nBricksDown = 4 ; var mortar = 3 ; var bw = cellSize/nBricksAcross-mortar ; var bh = cellSize/nBricksDown-mortar ; context.fillStyle = wall_edge_color ; var x0 = i*cellSize+th ; for(var u=0 ; ucellSize) w = cellSize-dx ; context.fillRect(x,y,w,bh) ; } } } this.interact = function(di,dj){ return false ; } } var wall = new wall_object() ; wall.description = 'Wall' ; var fence = new wall_object() ; fence.description = 'Fence' ; fence.draw = function(context,i,j){ var fw = 0.2*cellSize ; // fence width var A = player.A ; var B = player.B ; var connect_N = get_thing(get_cell(A,B,(i+0),(j-1))).is_wall ; var connect_E = get_thing(get_cell(A,B,(i+1),(j+0))).is_wall ; var connect_S = get_thing(get_cell(A,B,(i+0),(j+1))).is_wall ; var connect_W = get_thing(get_cell(A,B,(i-1),(j+0))).is_wall ; var floor = get_thing(room.floor_type) ; floor.draw(context,i,j) ; context.fillStyle = 'rgb(205,133,63)' ; if(connect_N) context.fillRect((i+0.5)*cellSize-0.5*fw,(j+0)*cellSize,fw,0.5*cellSize) ; if(connect_E) context.fillRect((i+0.5)*cellSize,(j+0.5)*cellSize-0.5*fw,0.5*cellSize,fw) ; if(connect_S) context.fillRect((i+0.5)*cellSize-0.5*fw,(j+0.5)*cellSize,fw,0.5*cellSize) ; if(connect_W) context.fillRect((i+0.0)*cellSize,(j+0.5)*cellSize-0.5*fw,0.5*cellSize,fw) ; var draw_post = false ; var ps = 3 ; // post size if(connect_N && connect_E) draw_post = true ; if(connect_N && connect_W) draw_post = true ; if(connect_S && connect_E) draw_post = true ; if(connect_S && connect_W) draw_post = true ; var nConnect = 0 ; if(connect_N) nConnect++ ; if(connect_E) nConnect++ ; if(connect_S) nConnect++ ; if(connect_W) nConnect++ ; if(nConnect<=1) draw_post = true ; if(draw_post) context.fillRect((i+0.5)*cellSize-0.5*ps*fw,(j+0.5)*cellSize-0.5*ps*fw,ps*fw,ps*fw) ; } var stone = new wall_object() ; stone.description = 'Stone' ; stone.type = 16 ; stone.draw = function(context, i, j){ context.fillStyle = 'rgb(200,200,200)' ; context.fillRect(i*cellSize,j*cellSize,cellSize,cellSize) ; context.fillStyle = 'rgb(0,0,0)' ; var A = player.A ; var B = player.B ; if(get_cell(A,B,i,j-1)!=16) context.fillRect((i+0)*cellSize,(j+0)*cellSize,cellSize,1) ; if(get_cell(A,B,i+1,j)!=16) context.fillRect((i+1)*cellSize-1,(j+0)*cellSize,1,cellSize) ; if(get_cell(A,B,i,j+1)!=16) context.fillRect((i+0)*cellSize,(j+1)*cellSize-1,cellSize,1) ; if(get_cell(A,B,i-1,j)!=16) context.fillRect((i+0)*cellSize,(j+0)*cellSize,1,cellSize) ; this.draw_details(context, i, j) ; } stone.draw_details = function(context, i, j){ var A = player.A ; var B = player.B ; if(random_from_ABij(A,B,i,j)<0.6) return ; var rgb = 100+Math.floor(155*random_from_ABij(A,B,i,j)) ; context.beginPath() ; context.fillStyle = 'rgb('+rgb+','+rgb+','+rgb+')' ; var x0 = (i+0.2+0.6*random_from_ABij(A,B,i+j,j))*cellSize ; var y0 = (j+0.2+0.6*random_from_ABij(A,B,i,i+j))*cellSize ; var xys = [] ; var nPoints = 4 + Math.floor(10*random_from_ABij(A,B,i,j)) ; for(var u=0 ; u0){ var t = get_thing(cells[j][i-1]) ; if(cells[j][i-1]==0 || (t.is_floor==true && t.is_steps==false)){ context.beginPath() ; context.moveTo((i+0)*cellSize,(j+0)*cellSize) ; context.lineTo((i+0)*cellSize,(j+1)*cellSize) ; context.stroke() ; } } if(i0){ var t = get_thing(get_master_map_cell(player.A,player.B,i,j-1)) ; if(cells[j-1][i]==0 || (t.is_floor==true && t.is_steps==false)){ context.beginPath() ; context.moveTo((i+0)*cellSize,(j+0)*cellSize) ; context.lineTo((i+1)*cellSize,(j+0)*cellSize) ; context.stroke() ; } } if(j0){ var t = get_thing(cells[j][i-1]) ; if(cells[j][i-1]==0 || (t.is_floor==true && t.is_steps==false)){ context.beginPath() ; context.moveTo((i+0)*cellSize,(j+0)*cellSize) ; context.lineTo((i+0)*cellSize,(j+1)*cellSize) ; context.stroke() ; } } if(i1.0-flower_density){ var r = 0.15*cellSize ; var randomX = random_from_ABij(player.A,player.B,-i+5, j+5) ; var randomY = random_from_ABij(player.A,player.B,-i+5,-j+5) ; var randomC = random_from_ABij(player.A,player.B, i+5,-j+5) ; var dx = r + 0.5*randomX*cellSize ; var dy = r + 0.5*randomY*cellSize ; var x = i*cellSize + dx ; var y = j*cellSize + dy ; var color = flower_colors[ Math.floor( flower_colors.length*randomC ) ] ; draw_flower(context,x,y,r,color) ; } } function draw_flower(context,x,y,r,color){ context.lineWidth = 1 ; for(var i=0 ; i<5 ; i++){ var cx = x + 0.6*r*Math.cos(2*Math.PI*i/5) ; var cy = y + 0.6*r*Math.sin(2*Math.PI*i/5) ; context.beginPath() ; context.arc(cx,cy,r,0,2*Math.PI,true) ; context.strokeStyle = 'rgb(0,0,0)' ; context.fillStyle = color ; context.fill() ; context.stroke() ; } context.beginPath() ; context.arc(x,y,0.75*r,0,2*Math.PI,true) ; context.strokeStyle = 'rgb(0,0,0)' ; context.fillStyle = 'rgb(255,255,0)' ; context.fill() ; context.stroke() ; } function update_grass(){ // This can allow the grass to change slowly over time to show the effects of decay and generally freak out the player //return ; flower_density -= 0.00025 ; grass_g += dgrass_g ; if(grass_g<150){ grass_g = 150 ; dgrass_g = mod_dgrass_g ; } else if(grass_g>=255){ grass_g = 255 ; dgrass_g = -mod_dgrass_g ; } grass_color = 'rgb(150,'+Math.round(grass_g)+',150)' ; return ; } wood.description = 'Wooden planks' ; wood.draw = function(context,i,j){ var th = 0 ; context.fillStyle = 'rgb(160,100,60)' ; context.strokeStyle = 'rgb(160,100,60)' ; context.lineWidth = 2 ; context.fillRect(i*cellSize+th,j*cellSize+th,cellSize-2*th,cellSize-2*th) ; var nPlanks = 3 ; var padding = 4 ; var plank_size = (cellSize - nPlanks*padding)/nPlanks ; context.fillStyle = this.color ; var y = j*cellSize+th+0.5*padding ; var dxs = [0.1,0.5,0.9] ; for(var k=0 ; k=2000 && m_in<3000 && this.door_status==1) return false ; if(m_out>=1000 && m_out<2000) this.door_status = 3-this.door_status ; if(m_in >=1000 && m_in <2000) this.door_status = 3-this.door_status ; return true ; } this.write_output = function(){ return 'pad_and_door_objects.push(new pad_and_door(' + this.A1 + ',' + this.B1 + ',' + this.i1 + ',' + this.j1 + ',' + this.A2 + ',' + this.B2 + ',' + this.i2 + ',' + this.j2 + ',' + '"' + this.letter + '",true) ) ;' ; } } function lever_and_door(A1,B1,i1,j1,A2,B2,i2,j2,letter,dir){ // The switch exists at point 1 and the door is at point 2 // The switch can be labelled with a letter // The direction of the switch as it is embedded in a wall this.is_floor = true ; this.is_pushable_traversable = true ; this.id = lever_and_door_objects.length ; this.A1 = A1 ; this.A2 = A2 ; this.B1 = B1 ; this.B2 = B2 ; this.i1 = i1 ; this.i2 = i2 ; this.j1 = j1 ; this.j2 = j2 ; this.letter = letter ; this.dir = dir ; this.door_status = 1 ; // 1 for closed, 2 for open this.door_status_in = this.door_status ; this.draw = function(flag){ // flag values: // 1: Draw pressure pad // 2: Draw door // 3: Draw letter on pad var opacity = 0.2 ; if(player.A==this.A1 && player.B==this.B1){ context.font = fontSize+'pt arial' ; context.textAlign = 'center' ; if(flag==1){ var t = get_thing(1) ; //t.draw(context,this.i1,this.j1) ; context.fillStyle = wall_edge_color ; var x = (this.i1+0)*cellSize ; var y = (this.j1+0)*cellSize ; var w = cellSize ; var h = cellSize ; var th = 6 ; context.fillRect(x,y,w,h) ; if(true){ if(this.dir=='N'){ } else if(this.dir=='E'){ } else if(this.dir=='S'){ } else if(this.dir=='W'){ x += th ; y += th ; if(this.door_status==1){ context.strokeStyle = 'rgb(255,0,0)' ; context.beginPath() ; context.moveTo(x,y) ; context.lineTo(x+2*th,y+2*th) ; context.moveTo(x+2*th,y) ; context.lineTo(x,y+2*th) ; context.stroke() ; } else{ context.strokeStyle = 'rgb(0,255,0)' ; y += 4*th ; context.beginPath() ; context.moveTo(x+2.5*th,y) ; context.lineTo(x+0.5*th,y+2*th) ; context.moveTo(x+0.5*th,y+2*th) ; context.lineTo(x+0.0*th,y+1.5*th) ; context.stroke() ; } th = 12 ; x = this.i1*cellSize+2*th ; y = (this.j1-0)*cellSize+th ; w = cellSize-2*th ; h = cellSize-2*th ; context.fillStyle = wall_edge_color ; context.fillRect(x,y,w,h) ; context.fillStyle = wall_fill_color ; context.fillText(this.letter,(this.i1+0.5)*cellSize+th,(this.j1+0.7)*cellSize) ; } } } if(flag==2){ var th = 0 ; context.strokeStyle = wall_edge_color ; context.fillStyle = wall_fill_color ; //context.fillRect(this.i2*cellSize+th,(this.j2-0)*cellSize+th,cellSize-2*th,cellSize-2*th) ; context.strokeRect(this.i2*cellSize+th,(this.j2-0)*cellSize+th,cellSize-2*th,cellSize-2*th) ; th = 6 ; context.lineWidth = 4 ; context.strokeStyle = wall_edge_color ; //context.fillRect(this.i2*cellSize+th,(this.j2-0)*cellSize+th,cellSize-2*th,cellSize-2*th) ; var CS = cellSize ; var cx = (this.i2+0.5)*CS ; var cy = (this.j2+0.5)*CS ; var cr = 0.5*cellSize-th ; // Draw outline context.beginPath() ; context.moveTo(cx-0.5*CS,cy-0.5*CS) ; context.lineTo(cx+0.5*CS,cy-0.5*CS) ; context.lineTo(cx+0.5*CS,cy+0.5*CS) ; context.lineTo(cx-0.5*CS,cy+0.5*CS) ; context.lineTo(cx-0.5*CS,cy-0.5*CS) ; context.moveTo(cx-cr,cy) ; context.arc(cx,cy,cr,Math.PI,0,false) ; context.lineTo(cx+cr,cy+cr) ; context.lineTo(cx-cr,cy+cr) ; context.lineTo(cx-cr,cy) ; context.fill('evenodd') ; context.stroke() ; // Draw door context.fillStyle = 'rgb(205,133,63)' ; context.beginPath() ; context.moveTo(cx-cr,cy) ; context.arc(cx,cy,cr,Math.PI,0,false) ; context.lineTo(cx+cr,cy+cr) ; context.lineTo(cx-cr,cy+cr) ; context.lineTo(cx-cr,cy) ; context.stroke() ; if(this.door_status==1){ context.fill() ; } context.fillStyle = (this.door_status==1) ? 'rgb(0,0,0)' : 'rgba(0,0,0,'+opacity+')' ; context.fillText(this.letter,(this.i2+0.5)*cellSize,(this.j2+0.7)*cellSize) ; } if(flag==3){ var th = 15 ; context.fillStyle = 'rgba(255,255,255,0.6)' ; context.fillRect(this.i1*cellSize+th, this.j1*cellSize+th, cellSize-2*th, cellSize-2*th) ; context.fillStyle = 'rgb(0,0,0)' ; context.fillText(this.letter,(this.i1+0.5)*cellSize,(this.j1+0.7)*cellSize) ; } if(flag==4){ var th = 15 ; context.fillStyle = 'rgba(255,255,255,0.6)' ; context.fillRect(this.i2*cellSize+th, this.j2*cellSize+th, cellSize-2*th, cellSize-2*th) ; context.fillStyle = 'rgb(0,0,0)' ; context.fillText(this.letter,(this.i2+0.5)*cellSize,(this.j2+0.7)*cellSize) ; } } } this.interact = function(di,dj){ var m = get_master_map_cell(player.A,player.B,player.i+di,player.j+dj) ; if(m>=4000 && m<5000) return (this.door_status==2) ; m = get_cell(this.A2,this.B2,this.i2,this.j2) ; if(m==2) return false ; if(di== 1 && dir=='W') this.door_status = 3 - this.door_status ; if(di==-1 && dir=='E') this.door_status = 3 - this.door_status ; if(dj== 1 && dir=='N') this.door_status = 3 - this.door_status ; if(dj==-1 && dir=='S') this.door_status = 3 - this.door_status ; draw_all() ; return false ; } this.write_output = function(){ return 'lever_and_door_objects.push(new lever_and_door(' + this.A1 + ',' + this.B1 + ',' + this.i1 + ',' + this.j1 + ',' + this.A2 + ',' + this.B2 + ',' + this.i2 + ',' + this.j2 + ',' + '"' + this.letter + '","'+this.dir+'") ) ;' ; } } var gp_fontSize = 0.3*cellSize ; function gold_piece_object(amount){ this.amount = amount ; this.interact = function(di, dj){ player.gp_current_room += this.amount ; player.gp += this.amount ; var sound = Get('audio_smbcoin') ; sound.pause() ; sound.currentTime = 0 ; sound.play() ; rooms[player.B][player.A].cell_contents[player.j+dj][player.i+di] = 0 ; return true ; } this.draw = function(context,i,j){ var cx = (i+0.5)*cellSize ; var cy = (j+0.5)*cellSize ; var cr = 0.3*cellSize ; context.beginPath() ; context.strokeStyle = 'rgb(0,0,0)' ; context.lineWidth = 2 ; context.fillStyle = 'rgb(255,223,0)' ; context.arc(cx,cy,cr,0,2*Math.PI,true) ; context.fill() ; context.stroke() ; context.font = gp_fontSize+'pt arial' ; context.fillStyle = 'rgb(0,0,0)' ; context.textAlign = 'center' ; context.fillText(currency_symbol+this.amount,cx,cy+0.35*fontSize) ; } } var gp1 = new gold_piece_object(1) ; var gp2 = new gold_piece_object(2) ; var gp5 = new gold_piece_object(5) ; function count_gold_on_map(){ var gp = 0 ; for(var B=0 ; B=0 && dialogue_stepdialogue_text.length){ dialogue_step = -1 ; if(dialogue_responses.length==0){ dialogue_chosen_response = -1 ; } else{ dialogue_chosen_response = 0 ; for(var i=0 ; i=dialogue_responses.length) dialogue_chosen_response = dialogue_responses.length-1 ; //alert('$'+dialogue_chosen_response) ; draw_dialogue_reponses() ; } function dialogue_choose_default_response(){ //dialogue_chosen_response = 0 ; dialogue_respond() ; } function dialogue_choose_current_response(){ dialogue_respond() ; } function dialogue_respond(){ npcs[current_npc].dialogue_counter = dialogue_responses[dialogue_chosen_response][1] ; dialogue_waiting_for_response = false ; dialogue_responses = [] ; dialogue_chosen_response = -1 ; dialogue_written_responses = false ; npcs[current_npc].converse() ; clear_dialogue() ; } function question_object(question_text, answers_texts){ this.question_text = question_text ; this.answers_texts = answers_texts ; this.cost_type = 0 ; // 0 for not specified, free // 1 for gold pieces this.add_gp_price = function(amount){ this.cost_type = 1 ; this.price = amount ; } this.add_special_price = function(type, amount){ this.cost_type = 1 ; this.price = amount ; } } var current_npc = -1 ; function npc_object(name, A, B, i, j, color1, color2){ this.name = name ; this.A = A ; this.B = B ; this.i = i ; this.j = j ; this.color1 = color1 ; this.color2 = color2 ; this.dialogue_preamble = new Array() ; this.said_preamble = false ; this.dialogue = new Array() ; this.dialogue_counter = 0 ; this.questions = new Array() ; this.index = -1 ; this.draw = function(context,i,j){ var th = 0 ; context.fillStyle = this.color1 ; context.fillRect(i*cellSize+th,j*cellSize+th,cellSize-2*th,cellSize-2*th) ; th = 4 ; context.fillStyle = this.color2 ; context.fillRect(i*cellSize+th,j*cellSize+th,cellSize-2*th,cellSize-2*th) ; context.fillStyle = this.color1 ; var dx = th ; var dy = th ; var ew = 0.2*cellSize ; // eye width var eh = 0.2*cellSize ; // eye height context.fillRect((i+0)*cellSize+th+dx ,j*cellSize+th+dy,ew,eh) ; context.fillRect((i+1)*cellSize-th-dx-ew,j*cellSize+th+dy,ew,eh) ; context.fillRect((i+0)*cellSize+th+dx,j*cellSize+th+6*dy,cellSize-2*th-2*dx,eh) ; } this.interact = function(di,dj){ this.converse() ; current_npc = this.index ; return false ; } this.converse = function(){ if(this.dialogue_preamble.length==0) this.said_preamble = true ; if(dialogue_step>0 && dialogue_step0.5) ? 2*255*(1.0-H) : 255 ; var G = (health>0.5) ? 255 : 255*H*2 ; th = 1 ; context.fillStyle = 'rgb('+Math.floor(R)+','+Math.floor(G)+',0)' ; context.fillRect(x+th,y+th,w-2*th,h-2*th) ; } } this.interact = function(){ in_combat = true ; current_enemy = this ; increment_conflict() ; return false ; } this.kill = function(){ master_map[this.B][this.A].cell_contents[this.j][this.i] = 0 ; room.cell_contents[this.j][this.i] = 0 ; draw_all() ; } this.reset = function(){ master_map[this.B][this.A].cells[this.j][this.i] = 8000+this.index ; cells[this.j][this.i] = 8000+this.index ; this.hit_points = this.initial_hp ; draw_all() ; } } var combat_sounds = ['audio_sword','audio_clang'] ; function increment_conflict(){ if(current_enemy==0){ reset_combat_table() ; window.setTimeout(increment_conflict,combat_delay) ; return ; } var index = Math.floor(Math.random()*combat_sounds.length) ; Get(combat_sounds[index]).play() ; draw_all() ; // A little bit of overkill? Perhaps just redraw a few cells instead? var attack = player.attack_base + Math.random()*player.attack_blur ; var defence = current_enemy.defence_base + Math.random()*current_enemy.defence_blur ; var hurt = Math.floor(attack) - Math.floor(defence) ; if(hurt>0){ current_enemy.hit_points -= hurt ; } if(current_enemy.hit_points<=0){ current_enemy.kill() ; draw_combat_table() ; reset_combat_table() ; in_combat = false ; Get('audio_Wilhelm').play() ; return ; } var attack = current_enemy.attack_base + Math.random()*current_enemy.attack_blur ; var defence = player.defence_base + Math.random()*player.defence_blur ; var hurt = Math.floor(attack) - Math.floor(defence) ; if(hurt>0){ player.hit_points -= hurt ; } draw_combat_table() ; if(player.hit_points<=0){ player.kill() ; in_combat = false ; return ; } window.setTimeout(increment_conflict,combat_delay) ; } function posession_object(){ this.draw = function(context,i,j){ context.fillStyle = 'rgb(0,255,255)' ; context.fillRect(i*cellSize,j*cellSize,cellSize,cellSize) ; } this.interact = function(di,dj){ var i = player.i+di ; var j = player.j+dj ; player.add_to_inventory(this) ; set_cell_contents(player.A,player.B,i,j,0) ; draw_all() ; return true ; } } var ball = new posession_object() ; ball.draw = function(context, i, j){ context.fillStyle = 'rgb(255,0,0)' ; context.beginPath() ; context.arc((i+0.5)*cellSize,(j+0.5)*cellSize,0.4*cellSize,0,2*Math.PI,true) ; context.fill() ; } // Taken from http://indiegamr.com/generate-repeatable-random-numbers-in-js/ // the initial seed Math.seed = 6 ; // in order to work 'Math.seed' must NOT be undefined, // so in any case, you HAVE to provide a Math.seed Math.seededRandom = function(min,max){ min = min || 0 ; max = max || 1 ; Math.seed = (Math.seed * 9301 + 49297) % 233280 ; var rnd = Math.seed/233280 ; return min + rnd*(max-min) ; } function random_from_ABij(A,B,i,j){ var pow_A = Math.pow(2.5,1+A+0.1) ; var pow_B = Math.pow(3.5,1+B+0.2) ; var pow_i = Math.pow(4.5,1+i+0.3) ; var pow_j = Math.pow(5.5,1+j+0.4) ; var result = (pow_A+pow_B+pow_i+pow_j)%1 ; return result ; } function random_from_ABijuv(A,B,i,j,u,v){ var pow_A = Math.pow(3.1,1+A+0.1) ; var pow_B = Math.pow(2.5,1+B+0.2) ; var pow_i = Math.pow(A+B,1+i+0.3) ; var pow_j = Math.pow(A*B,1+j+0.4) ; var pow_u = Math.sqrt(u*u+v) ; var pow_v = Math.sqrt(u+v) ; var p = pow_A+pow_B+pow_i+pow_j+pow_u+pow_v ; var result = (100*(p))%1 ; return result ; } function pushable_block_object(id){ this.id = id ; this.A = -1 ; this.B = -1 ; this.i = -1 ; this.j = -1 ; this.draw = function(context,i,j){ var m = get_master_map_cell(player.A,player.B,i,j) ; var t = get_thing(m) ; if(m!=2) t.draw(context, i, j) ; var th = 3 ; var margin = 4 ; context.fillStyle = 'rgb(255,255, 0)' ; context.strokeStyle = 'rgb( 0, 0, 0)' ; context.lineWidth = 2 ; context.beginPath() ; var corner = 0.25*cellSize ; var x, y, w, h ; // Main body of box context.fillStyle = 'rgb(200,200,200)' ; x = (i+0)*cellSize+margin+1 ; y = (j+0)*cellSize+margin+1 ; w = cellSize-2*margin-2 ; h = cellSize-2*margin-2 ; context.fillRect(x,y,w,h) ; context.strokeRect(x,y,w,h) ; context.fillStyle = 'rgb(210,180,140)' ; x = (i+0)*cellSize+margin+5 ; y = (j+0)*cellSize+margin+5 ; w = cellSize-2*margin-10 ; h = cellSize-2*margin-10 ; context.fillRect(x,y,w,h) ; context.strokeRect(x,y,w,h) ; // Diagonal support beams context.strokeStyle = 'rgb(0,0,0)' ; context.lineWidth = 5 ; context.moveTo((i+0)*cellSize+margin+2, (j+0)*cellSize+margin+2) ; context.lineTo((i+1)*cellSize-margin-2, (j+1)*cellSize-margin-2) ; context.stroke() ; context.strokeStyle = 'rgb(200,200,200)' ; context.lineWidth = 2 ; context.moveTo((i+0)*cellSize+margin+2, (j+0)*cellSize+margin+2) ; context.lineTo((i+1)*cellSize-margin-2, (j+1)*cellSize-margin-2) ; context.stroke() ; context.strokeStyle = 'rgb(0,0,0)' ; context.lineWidth = 5 ; context.moveTo((i+1)*cellSize-margin-2, (j+0)*cellSize+margin+2) ; context.lineTo((i+0)*cellSize+margin+2, (j+1)*cellSize-margin-2) ; context.stroke() ; context.strokeStyle = 'rgb(200,200,200)' ; context.lineWidth = 2 ; context.moveTo((i+1)*cellSize-margin-2, (j+0)*cellSize+margin+2) ; context.lineTo((i+0)*cellSize+margin+2, (j+1)*cellSize-margin-2) ; context.stroke() ; // Corners context.strokeStyle = 'rgb( 0, 0, 0)' ; context.fillStyle = 'rgb(200,200,200)' ; w = corner ; h = corner ; x = (i+0)*cellSize+margin-1 ; y = (j+0)*cellSize+margin-1 ; context.fillRect(x,y,w,h) ; context.strokeRect(x,y,w,h) ; x = (i+1)*cellSize-margin+1-corner ; y = (j+0)*cellSize+margin-1 ; context.fillRect(x,y,w,h) ; context.strokeRect(x,y,w,h) ; x = (i+0)*cellSize+margin-1 ; y = (j+1)*cellSize-margin+1-corner ; context.fillRect(x,y,w,h) ; context.strokeRect(x,y,w,h) ; x = (i+1)*cellSize-margin+1-corner ; y = (j+1)*cellSize-margin+1-corner ; context.fillRect(x,y,w,h) ; context.strokeRect(x,y,w,h) ; if(m>=1000 && m<2000){ pad_and_door_objects[m%1000].draw(3) ; } if(m>=2000 && m<3000){ pad_and_door_objects[m%2000].draw(4) ; } if(m>=3000 && m<4000){ lever_and_door_objects[m%3000].draw(3) ; } if(m>=4000 && m<5000){ lever_and_door_objects[m%4000].draw(4) ; } } this.interact = function(di,dj){ var i1 = -1 ; var i2 = -1 ; var j1 = -1 ; var j2 = -1 ; if((di+nCol)%nCol==nCol-1){ // W i1 = player.i-1 ; i2 = player.i-2 ; j1 = player.j ; j2 = player.j ; // Check for travelators if(get_master_map_cell(player.A,player.B,i1,j1)==30) return false ; if(get_master_map_cell(player.A,player.B,i1,j1)==31) return false ; if(get_master_map_cell(player.A,player.B,i1,j1)==32) return false ; if(get_master_map_cell(player.A,player.B,i2,j2)==31) return false ; } if((di+nCol)%nCol==1){ // E i1 = player.i+1 ; i2 = player.i+2 ; j1 = player.j ; j2 = player.j ; // Check for travelators if(get_master_map_cell(player.A,player.B,i1,j1)==30) return false ; if(get_master_map_cell(player.A,player.B,i1,j1)==32) return false ; if(get_master_map_cell(player.A,player.B,i1,j1)==33) return false ; if(get_master_map_cell(player.A,player.B,i2,j2)==33) return false ; } if((dj+nRow)%nRow==nRow-1){ // N i1 = player.i ; i2 = player.i ; j1 = player.j-1 ; j2 = player.j-2 ; // Check for travelators if(get_master_map_cell(player.A,player.B,i1,j1)==31) return false ; if(get_master_map_cell(player.A,player.B,i1,j1)==32) return false ; if(get_master_map_cell(player.A,player.B,i1,j1)==33) return false ; if(get_master_map_cell(player.A,player.B,i2,j2)==32) return false ; } if((dj+nRow)%nRow==1){ // S i1 = player.i ; i2 = player.i ; j1 = player.j+1 ; j2 = player.j+2 ; // Check for travelators if(get_master_map_cell(player.A,player.B,i1,j1)==30) return false ; if(get_master_map_cell(player.A,player.B,i1,j1)==31) return false ; if(get_master_map_cell(player.A,player.B,i1,j1)==33) return false ; if(get_master_map_cell(player.A,player.B,i2,j2)==30) return false ; } // Protect against moving off pressure pads with doors that are blocked var m = get_master_map_cell(player.A,player.B,i1,j1) ; if(m>=1000 && m<2000){ var p = pad_and_door_objects[m%1000] ; if(rooms[p.B2][p.A2].cells[p.j2][p.i2]!=m+1000) return false ; } if(is_pushable_traversable(get_cell(player.A,player.B,i2,j2)) && get_cell_contents(player.A,player.B,i2,j2)==0){ var c_in = get_cell_coords(player.A,player.B,i2,j2) ; var c_out = get_cell_coords(player.A,player.B,i1,j1) ; var value_in = master_map[c_in[1] ][c_in[0] ].cells[c_in[3] ][c_in[2] ] ; var value_out = master_map[c_out[1]][c_out[0]].cells[c_out[3]][c_out[2]] ; if(value_in>=1000 && value_in<2000) pad_and_door_objects[value_in%1000].interact(2*di,2*dj) ; if(value_in>=2000 && value_in<3000 && pad_and_door_objects[value_in%2000].door_status==1) return false ; if(value_in>=4000 && value_in<5000 && lever_and_door_objects[value_in%4000].door_status==1) return false ; set_cell_contents(player.A,player.B,i2,j2,this.id) ; set_cell_contents(c_out[0],c_out[1],c_out[2],c_out[3],0) return true ; } return false ; } } var pb = new pushable_block_object(2) ; pb.description = 'Crate' ; var barrel = new pushable_block_object(3) ; barrel.description = 'Barrel' ; barrel.draw = function(context, i, j){ context.fillStyle = 'rgb(205,133,63)' ; context.strokeStyle = 'rgb(100,100,100)' ; context.beginPath() ; context.lineWidth = 5 ; var r = 0.4*cellSize ; var cx = (i+0.5)*cellSize ; var cy = (j+0.5)*cellSize ; context.arc(cx,cy,r,0,2*Math.PI,true) ; context.fill() ; context.stroke() ; context.beginPath() ; context.lineWidth = 2 ; for(var v=-2 ; v<=2 ; v++){ var y = cy+r*v/3 ; var Dy = y-cy ; var Dx = Math.sqrt(r*r-Dy*Dy) ; context.moveTo(cx-Dx,y) ; context.lineTo(cx+Dx,y) ; } context.stroke() ; } function furniture_object(){ this.draw = function(context, i, j){ context.save() ; context.fillStyle = 'rgb(255,0,255)' ; var th = 2 ; context.fillRect(i*cellSize+th,j*cellSize+th,cellSize-2*th,cellSize-2*th) ; context.restore() ; } this.interact = function(di,dj){ return false ; } this.is_animated = false ; } function bed(linen_colour){ var the_bed = new furniture_object() ; the_bed.description = 'Bed' ; the_bed.linen_colour = linen_colour ; the_bed.draw = function(context,i,j){ context.save() ; var th = 2 ; var x0 = i*cellSize+2*th ; var y0 = j*cellSize+th ; context.fillStyle = 'rgb(160,82,45)' ; context.fillRect(x0,y0+0.20*cellSize,0.2*cellSize-2*th,0.8*cellSize-3*th) ; context.fillRect(x0+0.8*cellSize,y0+0.5*cellSize,0.2*cellSize-2*th,0.5*cellSize-3*th) ; context.fillStyle = this.linen_colour ; context.fillRect(x0+0.1*cellSize,y0+0.45*cellSize,0.9*cellSize-2*th,0.35*cellSize-th) ; context.restore() ; } the_bed.interact = function(di,dj){ napping = true ; nap() ; return false ; } return the_bed ; } var bed_red = bed('rgb(255,0,0)') ; var bed_green = bed('rgb(0,200,0)') ; var bed_blue = bed('rgb(0,0,255)') ; var faux_bed_red = bed('rgb(255,0,0)') ; faux_bed_red.interact = function(di,dj){ return false ; } var dresser = new furniture_object() ; var gravestone_1 = new furniture_object() ; gravestone_1.description = 'Gravestone' ; gravestone_1.draw = function(context, i, j){ context.fillStyle = 'rgb(100,100,100)' ; context.fillRect((i+0.4)*cellSize,(j+0.1)*cellSize,0.2*cellSize,0.8*cellSize) ; context.fillRect((i+0.2)*cellSize,(j+0.3)*cellSize,0.6*cellSize,0.2*cellSize) ; } var gravestone_2 = new furniture_object() ; gravestone_2.description = 'Gravestone' ; gravestone_2.draw = function(context, i, j){ context.fillStyle = 'rgb(100,100,100)' ; context.fillRect((i+0.2)*cellSize,(j+0.5)*cellSize,0.6*cellSize,0.4*cellSize) ; context.beginPath() ; context.moveTo((i+0.2)*cellSize,(j+0.5)*cellSize) ; context.arc((i+0.5)*cellSize,(j+0.5)*cellSize,0.3*cellSize,0,Math.PI,true) ; context.lineTo((i+0.2)*cellSize,(j+0.5)*cellSize) ; context.fill() ; } var fire = new furniture_object() ; fire.description = 'Fire' ; fire.is_animated = true ; fire.draw = function(context, i, j){ var thing = get_thing(get_cell(player.A,player.B,i,j)) ; thing.draw(context,i,j) ; var x0 = i*cellSize ; var y0 = j*cellSize ; context.save() ; for(var u=0 ; u<4 ; u++){ context.beginPath() ; context.fillStyle = 'rgb(255,0,0)' ; var t = 2*Math.PI*(animation_ticker%4)/4 ; var x1 = x0 + (0.1+u*0.2)*cellSize ; var x2 = x1 + 0.2*cellSize ; var x_peak = 0.5*(x1+x2) + 0.1*cellSize*Math.cos(t) ; var y_peak = y0 + 0.1*cellSize + 0.1*cellSize*Math.sin(t) ; context.moveTo(x1,y0+cellSize) ; context.lineTo(x2,y0+cellSize) ; context.lineTo(x_peak,y_peak) ; context.fill() ; } for(var u=0 ; u<4 ; u++){ context.beginPath() ; context.fillStyle = 'rgb(255,255,0)' ; var t = 2*Math.PI*(animation_ticker%4)/4 ; var x1 = x0 + (0.12+u*0.2)*cellSize ; var x2 = x1 + 0.18*cellSize ; var x_peak = 0.5*(x1+x2) + 0.05*cellSize*Math.cos(t) ; var y_peak = y0 + 0.5*cellSize + 0.05*cellSize*Math.sin(t) ; context.moveTo(x1,y0+cellSize) ; context.lineTo(x2,y0+cellSize) ; context.lineTo(x_peak,y_peak) ; context.fill() ; } context.restore() ; } var vine = new furniture_object() ; vine.description = 'Grapes' ; vine.grape_r = 0.09*cellSize ; vine.grape = function(context, i, j, u, v){ context.beginPath() ; context.arc((i+u)*cellSize,(j+v)*cellSize,this.grape_r,0,2*Math.PI,true) ; context.fill() ; } vine.draw = function(context, i, j){ var x0 = i*cellSize ; var y0 = j*cellSize ; context.fillStyle = 'rgba(245,222,179,0.3)' ; context.fillStyle = 'rgba(0,200,0,0.3)' ; context.fillRect(x0,y0,cellSize,cellSize) ; // Grapes context.beginPath() ; var v0 = 0.25 ; var dv = 0.2*Math.sqrt(3)/2 ; context.fillStyle = 'rgb(200,100,200)' ; // 'rgb(215,178,235)' ; vine.grape(context, i, j, 0.3 , v0+dv*0) ; vine.grape(context, i, j, 0.5 , v0+dv*0) ; vine.grape(context, i, j, 0.7 , v0+dv*0) ; vine.grape(context, i, j, 0.25, v0+dv*1) ; vine.grape(context, i, j, 0.45, v0+dv*1) ; vine.grape(context, i, j, 0.65, v0+dv*1) ; vine.grape(context, i, j, 0.85, v0+dv*1) ; vine.grape(context, i, j, 0.4 , v0+dv*2) ; vine.grape(context, i, j, 0.6 , v0+dv*2) ; vine.grape(context, i, j, 0.8 , v0+dv*2) ; vine.grape(context, i, j, 0.5 , v0+dv*3) ; vine.grape(context, i, j, 0.7 , v0+dv*3) ; vine.grape(context, i, j, 0.6 , v0+dv*4) ; //vine.grape(context, i, j, 0.4, 0.5) ; //vine.grape(context, i, j, 0.4, 0.5) ; context.fill() ; // Leaves and vine context.beginPath() ; context.lineWidth = 2 ; context.strokeStyle = 'rgb(0,100,0)' ; context.fillStyle = 'rgb(0,100,0)' ; var cx = x0+0.4*cellSize ; var cy = y0+0.25*cellSize ; var t = Math.PI/4 ; var l = 0.1*cellSize ; var r = 0.2*cellSize ; var p = Math.acos(l/r) ; context.beginPath() ; context.arc(cx+l*Math.cos(t),cy+l*Math.sin(t),r,t+Math.PI+p,t+Math.PI-p,true) ; context.arc(cx-l*Math.cos(t),cy-l*Math.sin(t),r,t+p,t-p,true) ; context.fill() ; var cx = x0+0.72*cellSize ; var cy = y0+0.25*cellSize ; var t = -1.3*Math.PI/4 ; var l = 0.1*cellSize ; var r = 0.2*cellSize ; var p = Math.acos(l/r) ; context.beginPath() ; context.arc(cx+l*Math.cos(t),cy+l*Math.sin(t),r,t+Math.PI+p,t+Math.PI-p,true) ; context.arc(cx-l*Math.cos(t),cy-l*Math.sin(t),r,t+p,t-p,true) ; context.fill() ; context.beginPath() ; context.arc(x0+0.5*cellSize,y0+0.1*cellSize,0.1*cellSize,-0.45*Math.PI,0.5*Math.PI,false) ; context.stroke() ; } var lighthouse_lamp = new furniture_object() ; lighthouse_lamp.description = 'Lamp' ; lighthouse_lamp.is_animated = true ; lighthouse_lamp.draw = function(context,i,j){ context.save() ; var thing = get_thing(get_cell(player.A,player.B,i,j)) ; thing.draw(context,i,j) ; var x0 = (i+0.5)*cellSize ; var y0 = (j+0.5)*cellSize ; context.beginPath() ; context.fillStyle = 'rgb(255,255,255)' ; context.arc(x0, y0, 0.4*cellSize, 0, 2*Math.PI, true) ; context.fill() ; context.stroke() ; context.fillStyle = 'rgba(255,255,0,0.5)' ; var nSteps = 20 ; var tick = (animation_ticker%nSteps) ; var t1 = 2*Math.PI*(tick+0)/nSteps ; var t2 = 2*Math.PI*(tick+1)/nSteps ; context.beginPath() ; context.moveTo(x0,y0) ; context.lineTo(x0+w*Math.cos(t1),y0+h*Math.sin(t1) ) ; context.lineTo(x0+w*Math.cos(t2),y0+h*Math.sin(t2) ) ; context.lineTo(x0,y0) ; context.closePath() ; context.fill() ; context.restore() ; } var lamppost = new furniture_object() ; lamppost.draw = function(context, i, j){ var thing = get_thing(get_cell(player.A,player.B,i,j)) ; thing.draw(context,i,j) ; context.beginPath() ; context.fillStyle = 'rgb(100,100,100)' ; context.arc((i+0.5)*cellSize,(j+0.5)*cellSize,0.3*cellSize,0,2*Math.PI,true) ; context.fill() ; } var tree = new furniture_object() ; tree.description = 'Tree' ; tree.draw = function(context,i,j){ context.beginPath() ; context.fillStyle = 'rgb(0,150,0)' ; var x0 = (i+0.5)*cellSize ; var y0 = (j+0.5)*cellSize ; var nBalls = 5 + Math.floor(3*random_from_ABij(player.A,player.B,i,j)) ; for(var u=0 ; u=1000 && type<2000) return true ; if(type>=2000 && type<3000) return ( pad_and_door_objects[type%2000].door_status==2) ; if(type>=4000 && type<5000) return (lever_and_door_objects[type%4000].door_status==2) ; return false ; } function is_steps(type){ var t = get_thing(type) ; if(t.is_steps) return true ; return false ; } function is_traversable(type){ if(player.ghost_mode==true) return true ; var t = get_thing(type) ; if(t.is_floor) return true ; switch(type){ case 2 : case 21: case 22: case 23: return true ; break ; default : break ; } if(type>=1000 && type< 2000) return true ; if(type>=2000 && type< 3000) return (pad_and_door_objects[type%1000].door_status==2) ; if(type>=8000 && type< 9000) return true ; if(type>=9000 && type<10000) return true ; return false ; } function is_heavy(type){ switch(type){ case 2: case 99: return true ; } return false ; } function keyDown(evt){ var keyDownID = window.event ? event.keyCode : (evt.keyCode != 0 ? evt.keyCode : evt.which) ; switch(keyDownID){ case 37: evt.preventDefault() ; break ; // left case 38: evt.preventDefault() ; break ; // up case 39: evt.preventDefault() ; break ; // right case 40: evt.preventDefault() ; break ; // down case 27: evt.preventDefault() ; break ; // esc case 32: evt.preventDefault() ; break ; // space } if(edit_mode) return ; if(in_combat) return ; if(dialogue_waiting_for_response){ interupt_dialogue() ; switch(keyDownID){ case 38: case 87: dialogue_change_prev_response() ; break ; // up case 40: case 83: dialogue_change_next_response() ; break ; // down case 27: dialogue_choose_default_response() ; break ; // esc case 13: dialogue_choose_current_response() ; break ; // enter } return ; } else{ switch(keyDownID){ case 37: case 65: try_move_W() ; break ; // left case 38: case 87: try_move_N() ; break ; // up case 39: case 68: try_move_E() ; break ; // right case 40: case 83: try_move_S() ; break ; // down case 27: reset_room() ; break ; // esc case 32: interupt_dialogue() ; break ; // space } } } function move_player(di,dj,dA,dB){ if(napping) return ; var A = player.A ; var B = player.B ; var i = player.i ; var j = player.j ; if(!is_traversable(get_cell(A+dA,B+dB,i+di,j+dj))) return ; // r for room // c for contents var r = get_master_map_cell(A,B,i,j) ; var dr = get_master_map_cell(A,B,i+di,j+dj) ; var c = get_cell_contents(A+dA,B+dB,i,j) ; var dc = get_cell_contents(A+dA,B+dB,i+di,j+dj) ; r = (r==0) ? room.floor_type : r ; // Travelators if((r==30 || dr==30) && ((dj+nRow)%nRow)!= nRow-1) return ; if((r==31 || dr==31) && ((di-nCol)%nCol)!=-nCol+1) return ; if((r==32 || dr==32) && ((dj-nRow)%nRow)!=-nRow+1) return ; if((r==33 || dr==33) && ((di+nCol)%nCol)!= nCol-1) return ; // Conversations if(dc<9000 || dc>=10000){ interupt_dialogue() ; clear_dialogue() ; current_npc = -1 ; dialogue_step = -1 ; } dialogue_waiting_for_response = false ; var success = interact(dc,di,dj) ; if(!success) return ; if(dialogue_step>=0 && dialogue_step=1000 && c<2000) pad_and_door_objects[c%1000].interact(di,dj) ; player.i += di ; player.j += dj ; player.A += dA ; player.B += dB ; update_grass() ; for(var i=0 ; i=rooms.length ) return blank_room ; if(A<0 || A>=rooms[B].length) return blank_room ; return rooms[B][A] ; } function coords_W(A,B,i,j){ return (i<=0 ) ? [A-1,B,nCol-1,j] : [A,B,i-1,j] ; } function coords_E(A,B,i,j){ return (i>=nCol-1) ? [A+1,B, 0,j] : [A,B,i+1,j] ; } function coords_N(A,B,i,j){ return (j<=0 ) ? [A,B-1,nRow-1,j] : [A,B,i,j-1] ; } function coords_S(A,B,i,j){ return (j>=nRow-1) ? [A,B+1, 0,j] : [A,B,i,j+1] ; } function get_cell_coords(A,B,i,j){ if(i< 0 ){ i = nCol-1 ; A-- ; } if(i>=nCol){ i = 0 ; A++ ; } if(j< 0 ){ j = nRow-1 ; B-- ; } if(j>=nRow){ j = 0 ; B++ ; } var room_tmp = get_room(A,B) ; if(j<0 || j>=room_tmp.cells.length) return -1 ; if(i<0 || i>=room_tmp.cells[j].length) return -1 ; return [A,B,i,j] ; } function get_cell(A,B,i,j){ if( i<0 ){ i = nCol+i ; A-- ; } else if(i>=nCol){ i = i-nCol ; A++ ; } if( j<0 ){ j = nRow+j ; B-- ; } else if(j>=nRow){ j = j-nRow ; B++ ; } var room_tmp = get_room(A,B) ; return room_tmp.cells[j][i] ; } function get_cell_contents(A,B,i,j){ if( i<0 ){ i = nCol+i ; A-- ; } else if(i>=nCol){ i = i-nCol ; A++ ; } if( j<0 ){ j = nRow+j ; B-- ; } else if(j>=nRow){ j = j-nRow ; B++ ; } var room_tmp = get_room(A,B) ; return room_tmp.cell_contents[j][i] ; } function set_cell(A,B,i,j,value){ if(i< 0 ){ i = nCol+i ; A-- ; } if(i>=nCol){ i = i-nCol ; A++ ; } if(j< 0 ){ j = nRow+j ; B-- ; } if(j>=nRow){ j = j-nRow ; B++ ; } var room_tmp = get_room(A,B) ; room_tmp.cells[j][i] = value ; } function set_cell_contents(A,B,i,j,value){ if(i< 0 ){ i = nCol+i ; A-- ; } if(i>=nCol){ i = i-nCol ; A++ ; } if(j< 0 ){ j = nRow+j ; B-- ; } if(j>=nRow){ j = j-nRow ; B++ ; } var room_tmp = get_room(A,B) ; room_tmp.cell_contents[j][i] = value ; } function change_room(A,B,di,dj){ player.i_in = player.i+di ; player.j_in = player.j+dj ; player.gp_current_room = 0 ; if(room) room.unload() ; room = get_room(A,B) ; room.load() ; wall_edge_color = room.wallEdgeColor ; wall_fill_color = room.wallFillColor ; cells = room.cells ; backup_cells() ; draw_room_name() ; update_dialogue_box_style() ; clear_dialogue() ; for(var i=0 ; i=master_map.length) return 0 ; if(A<0 || A>=master_map[B].length) return 0 ; if(j<0 || j>=master_map[B][A].cells.length) return 0 ; if(i<0 || i>=master_map[B][A].cells[j].length) return 0 ; return master_map[B][A].cells[j][i] ; } function populate_rooms(){ rooms = new Array() ; for(var B_=0 ; B_