2022-06-19 21:54:34 +00:00
|
|
|
import {tileArray} from './tileRenderer.js';
|
2022-06-20 00:18:47 +00:00
|
|
|
import { cursor } from '../interface/game/mouse.js'
|
2022-06-22 20:01:58 +00:00
|
|
|
import { ctx} from './html.js';
|
2022-06-20 00:18:47 +00:00
|
|
|
import { game } from '../game/game.js'
|
2022-06-19 21:54:34 +00:00
|
|
|
|
2022-06-20 00:18:47 +00:00
|
|
|
export function render() {
|
|
|
|
renderTiles()
|
|
|
|
}
|
|
|
|
|
|
|
|
export function renderTiles() { // DRAW THE IMAGE TO THE CANVAS.
|
2022-06-23 05:44:57 +00:00
|
|
|
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
|
2022-06-20 00:18:47 +00:00
|
|
|
const tileSize = game.tileSize;
|
2022-06-23 05:44:57 +00:00
|
|
|
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")
|
|
|
|
}
|