28 lines
750 B
JavaScript
28 lines
750 B
JavaScript
// c:\Users\benji\OneDrive\Documents\Source Code\sandgame\state.js
|
|
export const canvas = document.getElementById('gameCanvas');
|
|
export const ctx = canvas.getContext('2d');
|
|
|
|
export const cellSize = 5;
|
|
export let cols = 0;
|
|
export let rows = 0;
|
|
export let grid = [];
|
|
export let selectedType = 'dirt';
|
|
|
|
export function setSelectedType(type) {
|
|
selectedType = type;
|
|
}
|
|
|
|
export function setGrid(newGrid) {
|
|
grid = newGrid;
|
|
}
|
|
|
|
export function resize() {
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
|
|
cols = Math.floor(canvas.width / cellSize);
|
|
rows = Math.floor(canvas.height / cellSize);
|
|
|
|
// Initialize grid with nulls
|
|
grid = new Array(cols).fill(null).map(() => new Array(rows).fill(null));
|
|
}
|