game-engine/public/script.ts

190 lines
5.0 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 { Avatar, AvatarAction, 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
})
const avatar = new Avatar({
//figure: "hr-100-61.hd-180-7.ch-210-66.lg-270-82.sh-290-80",
// police figure: "hr-892-46.hd-209-8.ch-225-81.lg-270-64.sh-300-64.ca-1804-64.wa-2012",
figure: 'hd-209-14.ch-3688-1408.lg-280-1408.sh-290-1408.ha-1008.ea-3578.ca-1806-82.cc-3360-1408',
//figure: "hd-180-1.ch-255-66.lg-280-110.sh-305-62.ha-1012-110.hr-828-61",
2023-07-22 14:34:09 +02:00
position: {
x: 4,
2023-07-22 14:34:09 +02:00
y: 4,
z: 0
},
bodyDirection: 6,
headDirection: 6,
actions: [
//AvatarAction.Idle,
//AvatarAction.Walk,
AvatarAction.Talk,
AvatarAction.Wave,
//AvatarAction.Walk,
AvatarAction.CarryItem,
AvatarAction.Sit
],
handItem: 55
2023-07-23 18:41:23 +02:00
})
// ids: 4950, 1619
const furniture = new FloorFurniture({ id: 4967, position: { x: 5, y: 4, z: 0 }, direction: 2, state: 1 })
// room.objects.add(avatar)
/* furniture.onPointerDown = () => {
2023-07-23 18:41:23 +02:00
console.log('clicked')
} */
const furniture3 = new FloorFurniture({ id: 8916, position: { x: 10, y: 10, z: 0 }, direction: 2, state: 1 })
const furniture2 = new FloorFurniture({ id: 8916, position: { x: 8, y: 10, z: 0 }, direction: 2, state: 1 })
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
})
room.objects.add(wallFurniture)
2023-07-22 14:34:09 +02:00
const wallFurniture2 = new WallFurniture({
id: 4032,
position: { x: 3, y: -1, offsetX: 4, offsetY: -30 },
2023-07-22 14:34:09 +02:00
direction: 4,
state: 1
2023-07-23 18:41:23 +02:00
})
/* room.objects.add(furniture3)
2023-07-23 18:41:23 +02:00
room.objects.add(furniture2)
room.objects.add(wallFurniture)
room.objects.add(wallFurniture2) */
2023-07-23 18:41:23 +02:00
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-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)
//setTimeout(() => furni5.state = 0, 2000)
2023-07-22 14:34:09 +02:00
} else {
2023-07-23 18:41:23 +02:00
clearTimeout(timeout)
furni5.state = 0
2023-07-22 14:34:09 +02:00
}
2023-07-23 18:41:23 +02:00
}
} */