game-engine/public/script.ts

189 lines
4.4 KiB
TypeScript
Raw Normal View History

2023-07-23 18:41:23 +02:00
import { Scuti } from '../src/Scuti'
import { Room } from '../src/objects/rooms/Room'
import { FloorMaterial } from '../src/objects/rooms/materials/FloorMaterial'
import { WallMaterial } from '../src/objects/rooms/materials/WallMaterial'
import { FloorFurniture } from '../src/objects/furnitures/FloorFurniture'
import { WiredSelectionFilter } from '../src/objects/filters/WiredSelectionFilter'
import { WallFurniture } from '../src'
2023-07-22 14:34:09 +02:00
2023-07-23 18:41:23 +02:00
// Initialising Scuti Engine
;(async () => {
2023-07-22 14:34:09 +02:00
const renderer = new Scuti({
2023-07-23 18:41:23 +02:00
canvas: document.getElementById('app') as HTMLElement,
2023-07-22 14:34:09 +02:00
width: window.innerWidth,
2023-07-23 18:41:23 +02:00
height: window.innerHeight
})
2023-07-22 14:34:09 +02:00
2023-07-23 18:41:23 +02:00
await renderer.loadResources('https://kozennnn.github.io/scuti-resources/')
const tileMap =
'xxxxxxxx000000xxxxx\n' +
'xxxxxxx000000000xxx\n' +
'xxxxxx000000000000x\n' +
'xxx0x000xx0xxxx0000\n' +
'xxx0x000x00x0000000\n' +
'xxx0x000xx0x0000000\n' +
'xxx0x000000x0000000\n' +
'xxx0x000xx0x0000000\n' +
'xxx0x000x00x0000000\n' +
'xxx00000xx0x0000000\n' +
'xxxxxx00000x0000000\n' +
'xxxxxx0000000000000\n' +
'xxxxxx0000000000000\n' +
'xxxxxx00000x0000000\n'
2023-07-22 14:34:09 +02:00
const room = new Room(renderer, {
2023-07-23 18:41:23 +02:00
tileMap,
2023-07-22 14:34:09 +02:00
floorMaterial: new FloorMaterial(renderer, 110),
wallMaterial: new WallMaterial(renderer, 2301)
2023-07-23 18:41:23 +02:00
})
2023-07-22 14:34:09 +02:00
const furniture = new FloorFurniture({
//id: 4950,
//id: 1619,
id: 4967,
position: {
x: 5,
y: 4,
z: 0
},
direction: 2,
state: 1
2023-07-23 18:41:23 +02:00
})
room.objects.add(furniture)
2023-07-22 14:34:09 +02:00
furniture.onPointerDown = () => {
2023-07-23 18:41:23 +02:00
console.log('clicked')
}
2023-07-22 14:34:09 +02:00
const furniture3 = new FloorFurniture({
id: 8916,
position: {
x: 10,
y: 10,
z: 0
},
direction: 2,
state: 1
2023-07-23 18:41:23 +02:00
})
2023-07-22 14:34:09 +02:00
const furniture2 = new FloorFurniture({
id: 8916,
position: {
x: 8,
y: 10,
z: 0
},
direction: 2,
state: 1
2023-07-23 18:41:23 +02:00
})
2023-07-22 14:34:09 +02:00
const wallFurniture = new WallFurniture({
id: 4625,
position: {
x: -1,
y: 2,
offsetX: 2,
offsetY: -25
},
direction: 2,
state: 2
2023-07-23 18:41:23 +02:00
})
2023-07-22 14:34:09 +02:00
const wallFurniture2 = new WallFurniture({
id: 4032,
position: {
x: 3,
y: -1,
offsetX: 4,
offsetY: -30
},
direction: 4,
state: 1
2023-07-23 18:41:23 +02:00
})
room.objects.add(furniture3)
room.objects.add(furniture2)
room.objects.add(wallFurniture)
room.objects.add(wallFurniture2)
setTimeout(() => {
return wallFurniture.move({
x: -1,
y: 3,
offsetX: 2,
offsetY: -25
})
}, 3000)
setTimeout(() => {
return wallFurniture.move({
x: -1,
y: 5,
offsetX: 2,
offsetY: -25
})
}, 5000)
2023-07-22 14:34:09 +02:00
//setTimeout(() => room.objects.add(furniture), 6000);
furniture3.onLoadComplete = () => {
2023-07-23 18:41:23 +02:00
console.log('loaded!')
}
2023-07-22 14:34:09 +02:00
room.tiles.onPointerDown = (event) => {
2023-07-23 18:41:23 +02:00
furniture.move(event.position)
2023-07-22 14:34:09 +02:00
//room.tileMap = tileMap;
2023-07-23 18:41:23 +02:00
}
2023-07-22 14:34:09 +02:00
//dice(room, 5, 5, 2);
document.onkeydown = (e) => {
2023-07-23 18:41:23 +02:00
e = e || window.event
2023-07-22 14:34:09 +02:00
if (e.keyCode == '38') {
if (room.camera.zoomLevel <= 1) {
2023-07-23 18:41:23 +02:00
room.camera.zoomLevel = room.camera.zoomLevel * 2
2023-07-22 14:34:09 +02:00
} else {
2023-07-23 18:41:23 +02:00
room.camera.zoomLevel += 1
2023-07-22 14:34:09 +02:00
}
} else if (e.keyCode == '40') {
if (room.camera.zoomLevel <= 1) {
2023-07-23 18:41:23 +02:00
room.camera.zoomLevel = room.camera.zoomLevel / 2
2023-07-22 14:34:09 +02:00
} else {
2023-07-23 18:41:23 +02:00
room.camera.zoomLevel -= 1
2023-07-22 14:34:09 +02:00
}
} else if (e.keyCode == '37') {
2023-07-23 18:41:23 +02:00
furniture.rotate(4)
2023-07-22 14:34:09 +02:00
} else if (e.keyCode == '39') {
2023-07-23 18:41:23 +02:00
const filter = new WiredSelectionFilter(0xffffff, 0x999999)
furniture.addFilter(filter)
2023-07-22 14:34:09 +02:00
}
2023-07-23 18:41:23 +02:00
}
})().catch((error) => {
return console.error(error)
})
2023-07-22 14:34:09 +02:00
function dice(room, x, y, z) {
2023-07-23 18:41:23 +02:00
const furni5 = new FloorFurniture({
2023-07-22 14:34:09 +02:00
position: {
2023-07-23 18:41:23 +02:00
x,
y,
z
2023-07-22 14:34:09 +02:00
},
//direction: randomRotation[Math.floor(Math.random() * randomRotation.length)],
direction: 0,
//id: furniId[Math.floor(Math.random() * furniId.length)],
id: 284,
state: 1
2023-07-23 18:41:23 +02:00
})
room.objects.add(furni5)
let timeout
2023-07-22 14:34:09 +02:00
furni5.onDoubleClick = (event) => {
2023-07-23 18:41:23 +02:00
console.log(event)
2023-07-22 14:34:09 +02:00
//if(furni5.infos.logic === "furniture_dice") {
2023-07-23 18:41:23 +02:00
console.log('clicked furni5', event)
2023-07-22 14:34:09 +02:00
if (event.tag === 'activate') {
2023-07-23 18:41:23 +02:00
clearTimeout(timeout)
furni5.state = -1
2023-07-22 14:34:09 +02:00
timeout = setTimeout(() => {
2023-07-23 18:41:23 +02:00
furni5.state = Math.floor(Math.random() * 6) + 1
}, 1000)
2023-07-22 14:34:09 +02:00
/*setTimeout(() => {
furni5.state = 0
}, 2000);*/
} else {
2023-07-23 18:41:23 +02:00
clearTimeout(timeout)
furni5.state = 0
2023-07-22 14:34:09 +02:00
}
//x@}
2023-07-23 18:41:23 +02:00
}
2023-07-22 14:34:09 +02:00
}