2022-06-20 00:18:47 +00:00
|
|
|
import * as main from '../script.js';
|
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-19 21:54:34 +00:00
|
|
|
let x, y = 0
|
2022-06-20 00:18:47 +00:00
|
|
|
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")
|
|
|
|
}
|