mr-crocs-adventures/tilorswift/js/module.js

33 lines
922 B
JavaScript
Raw Normal View History

2020-01-29 00:21:53 +01:00
import Terrain from "./Terrain.js";
import FileLoader from "../../js/FileLoader.js";
2020-01-30 20:51:29 +01:00
import TilorswiftEvent from "./events/TilorswiftEvent.js";
import Mouse from "./Mouse.js";
2020-01-29 00:21:53 +01:00
let image = new Image();
image.src = '../graphics/tileset-landscape01.jpg';
image.onload = function () {
let loader = new FileLoader('../levels/level.json');
let terrain = Terrain.createFromJson(loader.getContent());
2020-01-30 20:51:29 +01:00
let map = document.getElementById('map');
map.appendChild(terrain.getElement());
let mouse = new Mouse();
window.addEventListener(
TilorswiftEvent.FIELD_CLICKED,
(event) => {
event.getField().setIndex(terrain.brushTileIndex);
}
);
window.addEventListener(
TilorswiftEvent.FIELD_ENTERED,
(event) => {
if (mouse.isPressedLeft) {
event.getField().setIndex(terrain.brushTileIndex);
}
}
);
2020-01-29 00:21:53 +01:00
};