X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;ds=sidebyside;f=new2%2Frogue_chat_nocanvas_monochrome.html;h=d873b3761d658d5daae3b7ee7ce45cd4b630b9c4;hb=90d7e8cdc98943e46ec9a3d8d2debf2886f793e2;hp=0ca95ed908a1a8d3c42bcf276e896560a2b7db85;hpb=ad8904ecc8fccd0ce52225d86e48c5f767b16daa;p=plomrogue2-experiments diff --git a/new2/rogue_chat_nocanvas_monochrome.html b/new2/rogue_chat_nocanvas_monochrome.html index 0ca95ed..d873b37 100644 --- a/new2/rogue_chat_nocanvas_monochrome.html +++ b/new2/rogue_chat_nocanvas_monochrome.html @@ -27,7 +27,6 @@ let terminal = { } line.push(' '); } - console.log(this.content); }, refresh: function() { let pre_string = ''; @@ -38,19 +37,22 @@ let terminal = { this.pre_el.textContent = pre_string; }, write: function(start_y, start_x, msg) { - for (let x = start_x, i = 0; x < this.cols, i < msg.length; x++, i++) { + for (let x = start_x, i = 0; x < this.cols && i < msg.length; x++, i++) { this.content[start_y][x] = msg[i]; } }, drawBox: function(start_y, start_x, height, width) { let end_y = start_y + height; let end_x = start_x + width; - for (let y = start_y, x = start_x; y < end_y; x++) { - this.content[y][x] = ' '; + for (let y = start_y, x = start_x;; x++) { if (x == end_x) { - x = start_x - 1; - y += 1; - } + x = start_x; + y += 1; + if (y == end_y) { + break; + } + }; + this.content[y][x] = ' '; } }, } @@ -109,22 +111,35 @@ let tui = { } }, draw_map: function() { + terminal.drawBox(0, 0, terminal.rows, terminal.cols / 2); let map_lines = []; - let line = ''; + let line = []; for (let i = 0, j = 0; i < game.map.length; i++, j++) { if (j == game.map_size[1]) { map_lines.push(line); - line = ''; + line = []; j = 0; }; - line += game.map[i]; + line.push(game.map[i]); }; map_lines.push(line); - for (let y = 0; y < game.map_size[0]; y++) { - terminal.write(y, 0, map_lines[y]); + let player_position = [0,0]; + for (const thing_id in game.things) { + let t = game.things[thing_id]; + map_lines[t[0]][t[1]] = '@'; + if (game.player_id == thing_id) { + player_position = t; + } } - for (const t in game.things) { - terminal.write(game.things[t][0], game.things[t][1], '@'); + let offset = [(terminal.rows / 2) - player_position[0], + terminal.cols / 4 - player_position[1]]; + for (let term_y = offset[0], map_y = 0; + term_y < terminal.rows && map_y < game.map_size[0]; + term_y++, map_y++) { + if (term_y >= 0) { + let to_draw = map_lines[map_y].join('').slice(0, terminal.cols / 2 - offset[1]); + terminal.write(term_y, offset[1], to_draw); + } } }, draw_turn_line: function(n) { @@ -161,7 +176,8 @@ let game = { things: {}, turn: 0, map: "", - map_size: [0,0] + map_size: [0,0], + player_id: 0 } let chat = { @@ -210,6 +226,8 @@ websocket.onmessage = function (event) { } else if (tokens[0] === 'LOG') { tui.log_msg(tokens[1], 1); tui.refresh(); + } else if (tokens[0] === 'PLAYER_ID') { + game.player_id = parseInt(tokens[1]); } else if (tokens[0] === 'META') { tui.log_msg(tokens[1]); tui.refresh();