|
13 | 13 | import Script from './Script.svelte'; |
14 | 14 | import { gameTick } from '$lib/game'; |
15 | 15 | import { currentLevel, store } from '$stores/store'; |
16 | | - import { scripts } from '$lib/scripts'; |
17 | 16 | import { keyboard } from '$stores/keyboard'; |
18 | 17 | import { onMount } from 'svelte'; |
19 | 18 | import { updateCamera } from '$lib/camera'; |
20 | 19 | import { get } from 'svelte/store'; |
21 | 20 | import { player } from '$stores/player'; |
22 | | - import { INTERACTIVITY_DISTANCE, pointer } from '$stores/cursor'; |
| 21 | + import { INTERACTIVITY_DISTANCE, pointer, type CursorName } from '$stores/cursor'; |
23 | 22 | import Debug from './Debug.svelte'; |
24 | 23 |
|
25 | 24 | const { camera, scene } = useThrelte(); |
26 | 25 |
|
27 | 26 | interactivity(); |
28 | 27 | gameTick(); |
29 | 28 |
|
30 | | - const doWalk = () => { |
31 | | -
|
32 | | - const position = get(player).position; |
33 | | -
|
34 | | - scripts[get(store).currentLevelNumber] |
35 | | - .filter((script) => { |
36 | | - return ( |
37 | | - script.doWalk && |
38 | | - script.x === position.x && |
39 | | - script.y === position.y |
40 | | - ); |
41 | | - }) |
42 | | - .map((script) => { |
43 | | - if (!script.doWalk) { |
44 | | - return; |
45 | | - } |
46 | | - script.doWalk(); |
47 | | - }); |
48 | | - }; |
49 | | -
|
50 | 29 | const keyUp = (e: KeyboardEvent) => { |
51 | 30 | if (e.key !== 'Escape') { |
52 | 31 | return; |
|
64 | 43 | } |
65 | 44 |
|
66 | 45 | if (e.code === $keyboard.forward) { |
67 | | - player.update((player) => { |
68 | | - player.moveForward($currentLevel); |
69 | | - doWalk(); |
70 | | - store.update((store) => { |
71 | | - return store; |
72 | | - }); |
73 | | - updateCamera(camera, player.position); |
74 | | - return player; |
75 | | - }); |
| 46 | + player.moveForward(camera); |
76 | 47 | } |
77 | 48 |
|
78 | 49 | if (e.code === $keyboard.left) { |
79 | | - player.update((player) => { |
80 | | - player.moveLeft($currentLevel); |
81 | | - doWalk(); |
82 | | - store.update((store) => { |
83 | | - return store; |
84 | | - }); |
85 | | - updateCamera(camera, player.position); |
86 | | - return player; |
87 | | - }); |
| 50 | + player.moveLeft(camera); |
88 | 51 | } |
89 | 52 |
|
90 | 53 | if (e.code === $keyboard.backward) { |
91 | | - player.update((player) => { |
92 | | - player.moveBackward($currentLevel); |
93 | | - doWalk(); |
94 | | - store.update((store) => { |
95 | | - return store; |
96 | | - }); |
97 | | - updateCamera(camera, player.position); |
98 | | - return player; |
99 | | - }); |
| 54 | + player.moveBackward(camera); |
100 | 55 | } |
101 | 56 |
|
102 | 57 | if (e.code === $keyboard.right) { |
103 | | - player.update((player) => { |
104 | | - player.moveRight($currentLevel); |
105 | | - doWalk(); |
106 | | - store.update((store) => { |
107 | | - return store; |
108 | | - }); |
109 | | - updateCamera(camera, player.position); |
110 | | - return player; |
111 | | - }); |
| 58 | + player.moveRight(camera); |
112 | 59 | } |
113 | 60 |
|
114 | 61 | if (e.code === $keyboard.rotateLeft) { |
115 | | - player.update((player) => { |
116 | | - player.rotateLeft(); |
117 | | - store.update((store) => { |
118 | | - return store; |
119 | | - }); |
120 | | - updateCamera(camera, player.position); |
121 | | - return player; |
122 | | - }); |
| 62 | + player.rotateLeft(camera); |
123 | 63 | } |
124 | 64 | if (e.code === $keyboard.rotateRight) { |
125 | | - player.update((player) => { |
126 | | - player.rotateRight(); |
127 | | - store.update((store) => { |
128 | | - return store; |
129 | | - }); |
130 | | - updateCamera(camera, player.position); |
131 | | - return player; |
132 | | - }); |
| 65 | + player.rotateRight(camera); |
133 | 66 | } |
134 | 67 |
|
135 | 68 | if (e.code === $keyboard.inventory) { |
|
159 | 92 |
|
160 | 93 | if(intersects.length) { |
161 | 94 |
|
162 | | - let cursor = null; |
| 95 | + let cursor : CursorName|null = null; |
163 | 96 |
|
164 | 97 | if(intersects[0].distance < INTERACTIVITY_DISTANCE) { |
165 | 98 | if(intersects[0].object.name === 'interact') { |
|
0 commit comments