MultiplayerMinesweeper/www/scripts/display/draw.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

import * as main from '../script.js';
2022-06-19 21:54:34 +00:00
import {tileArray} from './tileRenderer.js';
import { cursor } from '../interface/game/mouse.js'
import { ctx, hctx } 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.
2022-06-19 21:54:34 +00:00
let x, y = 0
const gridSize = game.gridSize;
const tileSize = game.tileSize;
2022-06-19 21:54:34 +00:00
for(x = 0; x < gridSize[0]; x++){
for(y = 0; y < gridSize[1]; 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-19 21:54:34 +00:00
// Draw buildings
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
// Draw Structures
2022-06-22 01:51:09 +00:00
const flag = tempWorld[x][y].flag
// console.log(flag)
if (flag !== 0) {
// console.log("FALAG")
ctx.drawImage(tileArray[flag + 7], xu,yu)
}
2022-06-19 21:54:34 +00:00
}
}
console.log("image Rendered")
}
2022-06-21 14:46:34 +00:00
2022-06-19 21:54:34 +00:00
export function renderHud(x, y) {
const tileSize = game.tileSize;
2022-06-19 21:54:34 +00:00
hctx.clearRect(cursor.xold*tileSize, cursor.yold*tileSize, tileSize, tileSize)
2022-06-21 14:46:34 +00:00
hctx.drawImage(tileArray[4], x*tileSize,y*tileSize)
2022-06-19 21:54:34 +00:00
}