set_font: function(type='normal') {
this.ctx.font = type + ' ' + this.charHeight + 'px monospace';
},
+ write_cheap: function(start_y, start_x, msg) {
+ this.ctx.fillText(msg, start_x*this.charWidth, start_y*this.charHeight);
+ },
+ set_color: function(color) {
+ this.ctx.fillStyle = color;
+ },
write: function(start_y, start_x, msg, foreground_color='white') {
- if (foreground_color === 'black') {
- this.ctx.fillStyle = 'white';
- } else {
- this.ctx.fillStyle = 'black';
- }
- this.ctx.fillText(msg, start_x*this.charWidth, start_y*this.charHeight);
+ this.ctx.fillStyle = 'black';
this.ctx.fillRect(start_x*this.charWidth, start_y*this.charHeight,
this.charWidth*msg.length, this.charHeight);
this.ctx.fillStyle = foreground_color;
}
},
draw_map: function() {
- terminal.drawBox(0, 0, terminal.rows, terminal.cols / 2);
+ terminal.drawBox(0, 0, terminal.rows, terminal.cols / 2, 'black');
+ let last_c = '';
+ let color = 'white';
for (let i = 0, y = 0, x = 0; i < game.map.length; i++, x++) {
if (x >= game.map_size[1]) {
x = 0;
y += 1;
};
let c = game.map[i];
- let color = 'white';
- if (c == '.') {
- color = '#ffaa00';
- } else if (c == '~') {
- color = '#5555ff';
- } else if (c == 'X') {
- color = '#55ff00';
+ if (c != last_c) {
+ last_c = c;
+ color = 'white';
+ if (c == '.') {
+ color = '#ffaa00';
+ } else if (c == '~') {
+ color = '#5555ff';
+ } else if (c == 'X') {
+ color = '#55ff00';
+ }
+ terminal.set_color(color);
}
- terminal.write(y, x, game.map[i], color);
+ terminal.write_cheap(y, x, c);
}
for (const t in game.things) {
terminal.write(game.things[t][0], game.things[t][1], '@');