MultiplayerMinesweeper/client/www/scripts/display/draw.js

34 lines
869 B
JavaScript
Raw Normal View History

2022-06-19 21:54:34 +00:00
import {tileArray} from './tileRenderer.js';
import { cursor } from '../interface/game/mouse.js'
2022-06-22 20:01:58 +00:00
import { ctx} from './html.js';
import { game } from '../game/game.js'
2022-06-19 21:54:34 +00:00
export function render() {
renderTiles()
}
export function renderTiles() { // DRAW THE IMAGE TO THE CANVAS.
const width = game.world.width;
const height = game.world.height;
canvas.width = game.tileSize*width;
canvas.height = game.tileSize*height;
2022-06-19 21:54:34 +00:00
let x, y = 0
const tileSize = game.tileSize;
for(x = 0; x < width; x++){
for(y = 0; y < height; y++){
2022-06-20 03:08:35 +00:00
const xu = x*tileSize;
2022-06-19 21:54:34 +00:00
const yu = y*tileSize;
2022-06-22 01:51:09 +00:00
const tempWorld = game.world.data;
2022-06-21 14:46:34 +00:00
ctx.drawImage(tileArray[tempWorld[x][y].type], xu,yu)
2022-06-19 21:54:34 +00:00
2022-06-22 01:51:09 +00:00
const flag = tempWorld[x][y].flag
if (flag !== 0) {
ctx.drawImage(tileArray[flag + 7], xu,yu)
}
2022-06-19 21:54:34 +00:00
}
}
console.log("image Rendered")
}