MultiplayerMinesweeper/www/scripts/display/draw.js

52 lines
1.2 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;
const tempWorld = game.world;
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
switch (tempWorld[x][y].structure) {
2022-06-19 21:54:34 +00:00
case (1):
ctx.drawImage(tileArray[4], xu,yu)
break;
case (2):
ctx.drawImage(tileArray[32], xu,yu)
break;
case (3):
ctx.drawImage(tileArray[33], xu,yu)
break;
case (4):
ctx.drawImage(tileArray[34], xu,yu)
2022-06-19 21:54:34 +00:00
break;
}
}
}
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
}