spoint 0.1.0 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -209
- package/SKILL.md +95 -0
- package/apps/environment/index.js +200 -1
- package/apps/environment/models/decorative/.gitkeep +0 -0
- package/apps/environment/models/hazards/.gitkeep +0 -0
- package/apps/environment/models/interactive/.gitkeep +0 -0
- package/apps/environment/models/structures/.gitkeep +0 -0
- package/apps/environment/smartObjects.js +114 -0
- package/apps/interactable/index.js +155 -0
- package/apps/physics-crate/index.js +15 -9
- package/apps/power-crate/index.js +18 -12
- package/apps/tps-game/$GDUPI.vrm +0 -0
- package/apps/tps-game/Cleetus.vrm +0 -0
- package/apps/tps-game/index.js +185 -27
- package/apps/world/index.js +68 -22
- package/bin/create-app.js +337 -0
- package/client/ARControls.js +301 -0
- package/client/LoadingManager.js +117 -0
- package/client/MobileControls.js +1122 -0
- package/client/anim-lib.glb +0 -0
- package/client/animation.js +306 -0
- package/client/app.js +1341 -65
- package/client/camera.js +191 -33
- package/client/createLoadingScreen.js +69 -0
- package/client/editor/bridge.js +113 -0
- package/client/editor/css/main.css +794 -0
- package/client/editor/images/rotate.svg +4 -0
- package/client/editor/images/scale.svg +4 -0
- package/client/editor/images/translate.svg +4 -0
- package/client/editor/index.html +103 -0
- package/client/editor/js/Command.js +41 -0
- package/client/editor/js/Config.js +81 -0
- package/client/editor/js/Editor.js +785 -0
- package/client/editor/js/EditorControls.js +438 -0
- package/client/editor/js/History.js +321 -0
- package/client/editor/js/Loader.js +987 -0
- package/client/editor/js/LoaderUtils.js +90 -0
- package/client/editor/js/Menubar.Add.js +510 -0
- package/client/editor/js/Menubar.Edit.js +145 -0
- package/client/editor/js/Menubar.File.js +466 -0
- package/client/editor/js/Menubar.Help.js +73 -0
- package/client/editor/js/Menubar.Status.js +51 -0
- package/client/editor/js/Menubar.View.js +183 -0
- package/client/editor/js/Menubar.js +27 -0
- package/client/editor/js/Player.js +53 -0
- package/client/editor/js/Resizer.js +58 -0
- package/client/editor/js/Script.js +503 -0
- package/client/editor/js/Selector.js +102 -0
- package/client/editor/js/Sidebar.Geometry.BoxGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.BufferGeometry.js +115 -0
- package/client/editor/js/Sidebar.Geometry.CapsuleGeometry.js +97 -0
- package/client/editor/js/Sidebar.Geometry.CircleGeometry.js +97 -0
- package/client/editor/js/Sidebar.Geometry.CylinderGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.DodecahedronGeometry.js +73 -0
- package/client/editor/js/Sidebar.Geometry.ExtrudeGeometry.js +196 -0
- package/client/editor/js/Sidebar.Geometry.IcosahedronGeometry.js +73 -0
- package/client/editor/js/Sidebar.Geometry.LatheGeometry.js +98 -0
- package/client/editor/js/Sidebar.Geometry.Modifiers.js +73 -0
- package/client/editor/js/Sidebar.Geometry.OctahedronGeometry.js +74 -0
- package/client/editor/js/Sidebar.Geometry.PlaneGeometry.js +97 -0
- package/client/editor/js/Sidebar.Geometry.RingGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.ShapeGeometry.js +76 -0
- package/client/editor/js/Sidebar.Geometry.SphereGeometry.js +133 -0
- package/client/editor/js/Sidebar.Geometry.TetrahedronGeometry.js +74 -0
- package/client/editor/js/Sidebar.Geometry.TorusGeometry.js +109 -0
- package/client/editor/js/Sidebar.Geometry.TorusKnotGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.TubeGeometry.js +135 -0
- package/client/editor/js/Sidebar.Geometry.js +332 -0
- package/client/editor/js/Sidebar.Material.BooleanProperty.js +60 -0
- package/client/editor/js/Sidebar.Material.ColorProperty.js +87 -0
- package/client/editor/js/Sidebar.Material.ConstantProperty.js +62 -0
- package/client/editor/js/Sidebar.Material.MapProperty.js +249 -0
- package/client/editor/js/Sidebar.Material.NumberProperty.js +60 -0
- package/client/editor/js/Sidebar.Material.Program.js +73 -0
- package/client/editor/js/Sidebar.Material.RangeValueProperty.js +63 -0
- package/client/editor/js/Sidebar.Material.js +751 -0
- package/client/editor/js/Sidebar.Object.Animation.js +102 -0
- package/client/editor/js/Sidebar.Object.js +898 -0
- package/client/editor/js/Sidebar.Project.App.js +165 -0
- package/client/editor/js/Sidebar.Project.Image.js +225 -0
- package/client/editor/js/Sidebar.Project.Materials.js +82 -0
- package/client/editor/js/Sidebar.Project.Renderer.js +144 -0
- package/client/editor/js/Sidebar.Project.Video.js +242 -0
- package/client/editor/js/Sidebar.Project.js +31 -0
- package/client/editor/js/Sidebar.Properties.js +73 -0
- package/client/editor/js/Sidebar.Scene.js +585 -0
- package/client/editor/js/Sidebar.Script.js +129 -0
- package/client/editor/js/Sidebar.Settings.History.js +146 -0
- package/client/editor/js/Sidebar.Settings.Shortcuts.js +175 -0
- package/client/editor/js/Sidebar.Settings.js +60 -0
- package/client/editor/js/Sidebar.js +41 -0
- package/client/editor/js/Storage.js +98 -0
- package/client/editor/js/Strings.js +2028 -0
- package/client/editor/js/Toolbar.js +84 -0
- package/client/editor/js/Viewport.Controls.js +92 -0
- package/client/editor/js/Viewport.Info.js +136 -0
- package/client/editor/js/Viewport.Pathtracer.js +91 -0
- package/client/editor/js/Viewport.ViewHelper.js +39 -0
- package/client/editor/js/Viewport.XR.js +222 -0
- package/client/editor/js/Viewport.js +900 -0
- package/client/editor/js/commands/AddObjectCommand.js +68 -0
- package/client/editor/js/commands/AddScriptCommand.js +75 -0
- package/client/editor/js/commands/Commands.js +23 -0
- package/client/editor/js/commands/MoveObjectCommand.js +111 -0
- package/client/editor/js/commands/MultiCmdsCommand.js +85 -0
- package/client/editor/js/commands/RemoveObjectCommand.js +88 -0
- package/client/editor/js/commands/RemoveScriptCommand.js +81 -0
- package/client/editor/js/commands/SetColorCommand.js +73 -0
- package/client/editor/js/commands/SetGeometryCommand.js +87 -0
- package/client/editor/js/commands/SetGeometryValueCommand.js +70 -0
- package/client/editor/js/commands/SetMaterialColorCommand.js +86 -0
- package/client/editor/js/commands/SetMaterialCommand.js +79 -0
- package/client/editor/js/commands/SetMaterialMapCommand.js +143 -0
- package/client/editor/js/commands/SetMaterialRangeCommand.js +91 -0
- package/client/editor/js/commands/SetMaterialValueCommand.js +90 -0
- package/client/editor/js/commands/SetMaterialVectorCommand.js +79 -0
- package/client/editor/js/commands/SetPositionCommand.js +84 -0
- package/client/editor/js/commands/SetRotationCommand.js +84 -0
- package/client/editor/js/commands/SetScaleCommand.js +84 -0
- package/client/editor/js/commands/SetSceneCommand.js +103 -0
- package/client/editor/js/commands/SetScriptValueCommand.js +80 -0
- package/client/editor/js/commands/SetShadowValueCommand.js +73 -0
- package/client/editor/js/commands/SetUuidCommand.js +70 -0
- package/client/editor/js/commands/SetValueCommand.js +75 -0
- package/client/editor/js/libs/acorn/acorn.js +3236 -0
- package/client/editor/js/libs/acorn/acorn_loose.js +1299 -0
- package/client/editor/js/libs/acorn/walk.js +344 -0
- package/client/editor/js/libs/app/index.html +57 -0
- package/client/editor/js/libs/app.js +251 -0
- package/client/editor/js/libs/codemirror/addon/dialog.css +32 -0
- package/client/editor/js/libs/codemirror/addon/dialog.js +163 -0
- package/client/editor/js/libs/codemirror/addon/show-hint.css +36 -0
- package/client/editor/js/libs/codemirror/addon/show-hint.js +529 -0
- package/client/editor/js/libs/codemirror/addon/tern.css +87 -0
- package/client/editor/js/libs/codemirror/addon/tern.js +750 -0
- package/client/editor/js/libs/codemirror/codemirror.css +344 -0
- package/client/editor/js/libs/codemirror/codemirror.js +9849 -0
- package/client/editor/js/libs/codemirror/mode/glsl.js +233 -0
- package/client/editor/js/libs/codemirror/mode/javascript.js +959 -0
- package/client/editor/js/libs/codemirror/theme/monokai.css +41 -0
- package/client/editor/js/libs/esprima.js +6401 -0
- package/client/editor/js/libs/jsonlint.js +453 -0
- package/client/editor/js/libs/signals.min.js +14 -0
- package/client/editor/js/libs/tern-threejs/threejs.js +5031 -0
- package/client/editor/js/libs/ternjs/comment.js +87 -0
- package/client/editor/js/libs/ternjs/def.js +588 -0
- package/client/editor/js/libs/ternjs/doc_comment.js +401 -0
- package/client/editor/js/libs/ternjs/infer.js +1635 -0
- package/client/editor/js/libs/ternjs/polyfill.js +80 -0
- package/client/editor/js/libs/ternjs/signal.js +26 -0
- package/client/editor/js/libs/ternjs/tern.js +993 -0
- package/client/editor/js/libs/ui.js +1346 -0
- package/client/editor/js/libs/ui.three.js +855 -0
- package/client/facial-animation.js +455 -0
- package/client/index.html +7 -4
- package/client/loading.css +147 -0
- package/client/loading.html +25 -0
- package/client/style.css +251 -0
- package/package.json +7 -3
- package/server.js +9 -1
- package/src/apps/AppContext.js +1 -1
- package/src/apps/AppLoader.js +50 -37
- package/src/apps/AppRuntime.js +32 -8
- package/src/client/InputHandler.js +233 -0
- package/src/client/JitterBuffer.js +207 -0
- package/src/client/KalmanFilter.js +125 -0
- package/src/client/MessageHandler.js +101 -0
- package/src/client/PhysicsNetworkClient.js +141 -68
- package/src/client/ReconnectManager.js +62 -0
- package/src/client/SmoothInterpolation.js +127 -0
- package/src/client/SnapshotProcessor.js +144 -0
- package/src/connection/ConnectionManager.js +21 -3
- package/src/connection/SessionStore.js +13 -3
- package/src/index.client.js +4 -6
- package/src/netcode/EventLog.js +29 -15
- package/src/netcode/LagCompensator.js +25 -26
- package/src/netcode/NetworkState.js +4 -1
- package/src/netcode/PhysicsIntegration.js +20 -6
- package/src/netcode/PlayerManager.js +10 -2
- package/src/netcode/SnapshotEncoder.js +66 -19
- package/src/netcode/TickSystem.js +13 -4
- package/src/physics/World.js +66 -13
- package/src/protocol/msgpack.js +90 -63
- package/src/sdk/ReloadHandlers.js +12 -2
- package/src/sdk/ReloadManager.js +5 -0
- package/src/sdk/ServerHandlers.js +50 -11
- package/src/sdk/StaticHandler.js +22 -6
- package/src/sdk/TickHandler.js +101 -34
- package/src/sdk/scaffold.js +28 -0
- package/src/sdk/server.js +59 -33
- package/src/shared/movement.js +2 -1
- package/src/spatial/Octree.js +5 -0
- package/apps/interactive-door/index.js +0 -33
- package/apps/patrol-npc/index.js +0 -37
- package/src/connection/QualityMonitor.js +0 -46
- package/src/debug/StateInspector.js +0 -42
- package/src/index.js +0 -1
- package/src/index.server.js +0 -27
- package/src/protocol/Codec.js +0 -60
- package/src/protocol/SequenceTracker.js +0 -71
- package/src/sdk/ClientMessageHandler.js +0 -80
- package/src/sdk/client.js +0 -122
- package/world/kaira.glb +0 -0
- package/world/schwust.glb +0 -0
package/apps/tps-game/index.js
CHANGED
|
@@ -3,13 +3,16 @@ export default {
|
|
|
3
3
|
setup(ctx) {
|
|
4
4
|
ctx.state.map = 'schwust'
|
|
5
5
|
ctx.state.mode = 'ffa'
|
|
6
|
-
ctx.state.config = { respawnTime: 3, health: 100, damagePerHit:
|
|
6
|
+
ctx.state.config = { respawnTime: 3, health: 100, damagePerHit: 20, headshotMultiplier: 2.5, headshotZone: 0.7, hitKnockback: 4, shootKnockback: 2, magazineSize: 30, reloadTime: 2000 }
|
|
7
7
|
ctx.state.spawnPoints = findSpawnPoints(ctx)
|
|
8
8
|
ctx.state.playerStats = new Map()
|
|
9
9
|
ctx.state.respawning = new Map()
|
|
10
10
|
ctx.state.buffs = new Map()
|
|
11
|
+
ctx.state.ammo = new Map()
|
|
12
|
+
ctx.state.reloading = new Map()
|
|
11
13
|
ctx.state.started = Date.now()
|
|
12
14
|
ctx.state.gameTime = 0
|
|
15
|
+
ctx.state.fallTimers = new Map()
|
|
13
16
|
|
|
14
17
|
ctx.bus.on('powerup.collected', (event) => {
|
|
15
18
|
const d = event.data
|
|
@@ -38,6 +41,30 @@ export default {
|
|
|
38
41
|
if (now >= buff.expiresAt) {
|
|
39
42
|
ctx.state.buffs.delete(pid)
|
|
40
43
|
ctx.players.send(pid, { type: 'buff_expired' })
|
|
44
|
+
} else {
|
|
45
|
+
const player = ctx.players.getAll().find(p => p.id === pid)
|
|
46
|
+
if (player?.state) {
|
|
47
|
+
const maxHp = ctx.state.config.health
|
|
48
|
+
const healRate = maxHp / 10
|
|
49
|
+
player.state.health = Math.min(maxHp, (player.state.health ?? maxHp) + healRate * dt)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
for (const player of ctx.players.getAll()) {
|
|
54
|
+
if (!player.state || ctx.state.respawning.has(player.id)) continue
|
|
55
|
+
if ((player.state.health ?? ctx.state.config.health) <= 0) continue
|
|
56
|
+
const y = player.state.position?.[1] ?? 0
|
|
57
|
+
if (y < -20) {
|
|
58
|
+
const t = ctx.state.fallTimers.get(player.id) || 0
|
|
59
|
+
ctx.state.fallTimers.set(player.id, t + dt)
|
|
60
|
+
if (t + dt >= 5) {
|
|
61
|
+
player.state.health = 0
|
|
62
|
+
ctx.state.respawning.set(player.id, { respawnAt: now + ctx.state.config.respawnTime * 1000, killer: null })
|
|
63
|
+
ctx.network.broadcast({ type: 'death', victim: player.id, killer: null })
|
|
64
|
+
ctx.state.fallTimers.delete(player.id)
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
ctx.state.fallTimers.delete(player.id)
|
|
41
68
|
}
|
|
42
69
|
}
|
|
43
70
|
for (const [pid, data] of ctx.state.respawning) {
|
|
@@ -60,34 +87,152 @@ export default {
|
|
|
60
87
|
const p = ctx.players.getAll().find(pl => pl.id === msg.playerId)
|
|
61
88
|
if (p && p.state) p.state.health = ctx.state.config.health
|
|
62
89
|
ctx.state.playerStats.set(msg.playerId, { kills: 0, deaths: 0, damage: 0 })
|
|
90
|
+
ctx.state.ammo.set(msg.playerId, ctx.state.config.magazineSize)
|
|
91
|
+
ctx.state.reloading.delete(msg.playerId)
|
|
63
92
|
}
|
|
64
93
|
if (msg.type === 'player_leave') {
|
|
65
94
|
ctx.state.playerStats.delete(msg.playerId)
|
|
66
95
|
ctx.state.respawning.delete(msg.playerId)
|
|
96
|
+
ctx.state.fallTimers.delete(msg.playerId)
|
|
97
|
+
ctx.state.ammo.delete(msg.playerId)
|
|
98
|
+
ctx.state.reloading.delete(msg.playerId)
|
|
99
|
+
}
|
|
100
|
+
if (msg.type === 'reload') {
|
|
101
|
+
const playerId = msg.senderId || msg.playerId
|
|
102
|
+
if (ctx.state.reloading.has(playerId)) return
|
|
103
|
+
const currentAmmo = ctx.state.ammo.get(playerId) ?? 0
|
|
104
|
+
if (currentAmmo >= ctx.state.config.magazineSize) return
|
|
105
|
+
ctx.state.reloading.set(playerId, { startTime: Date.now() })
|
|
106
|
+
ctx.players.send(playerId, { type: 'reload_start', duration: ctx.state.config.reloadTime })
|
|
107
|
+
setTimeout(() => {
|
|
108
|
+
ctx.state.ammo.set(playerId, ctx.state.config.magazineSize)
|
|
109
|
+
ctx.state.reloading.delete(playerId)
|
|
110
|
+
ctx.players.send(playerId, { type: 'reload_complete' })
|
|
111
|
+
}, ctx.state.config.reloadTime)
|
|
67
112
|
}
|
|
68
113
|
if (msg.type === 'fire') {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
114
|
+
const shooterId = msg.senderId || msg.shooterId
|
|
115
|
+
if (ctx.state.reloading.has(shooterId)) return
|
|
116
|
+
const ammo = ctx.state.ammo.get(shooterId) ?? 0
|
|
117
|
+
if (ammo <= 0) {
|
|
118
|
+
ctx.players.send(shooterId, { type: 'empty_click' })
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
ctx.state.ammo.set(shooterId, ammo - 1)
|
|
122
|
+
const shooter = ctx.players.getAll().find(p => p.id === shooterId)
|
|
123
|
+
const pos = shooter?.state?.position || [0, 0, 0]
|
|
124
|
+
const origin = [pos[0], pos[1] + 0.9, pos[2]]
|
|
125
|
+
const fireData = { shooterId, origin, direction: msg.direction }
|
|
126
|
+
ctx.bus.emit('combat.fire', fireData)
|
|
127
|
+
const dir = msg.direction
|
|
128
|
+
if (shooter?.state) {
|
|
129
|
+
shooter.state.velocity[0] -= dir[0] * ctx.state.config.shootKnockback
|
|
130
|
+
shooter.state.velocity[2] -= dir[2] * ctx.state.config.shootKnockback
|
|
131
|
+
}
|
|
132
|
+
ctx.players.send(shooterId, { type: 'aimpunch', intensity: 0.3 })
|
|
133
|
+
handleFire(ctx, fireData)
|
|
75
134
|
}
|
|
76
135
|
}
|
|
77
136
|
},
|
|
78
137
|
|
|
79
138
|
client: {
|
|
139
|
+
_tps: null,
|
|
140
|
+
setup(engine) {
|
|
141
|
+
const flash = new engine.THREE.PointLight(0xffaa00, 0, 8)
|
|
142
|
+
engine.scene.add(flash)
|
|
143
|
+
engine._tps = { lastShootTime: 0, isAiming: false, boost: null, flash, flashOff: 0, ammo: 30, reloading: false, lastReloadTime: 0 }
|
|
144
|
+
this._tps = engine._tps
|
|
145
|
+
},
|
|
146
|
+
onMouseDown(e, engine) {
|
|
147
|
+
if (e.button === 2 && engine._tps) engine._tps.isAiming = true
|
|
148
|
+
},
|
|
149
|
+
onMouseUp(e, engine) {
|
|
150
|
+
if (e.button === 2 && engine._tps) engine._tps.isAiming = false
|
|
151
|
+
},
|
|
152
|
+
onInput(input, engine) {
|
|
153
|
+
const tps = engine._tps
|
|
154
|
+
if (!tps) return
|
|
155
|
+
if (input.reload && !tps.reloading && Date.now() - tps.lastReloadTime > 100) {
|
|
156
|
+
tps.lastReloadTime = Date.now()
|
|
157
|
+
engine.client.sendReload()
|
|
158
|
+
}
|
|
159
|
+
if (input.shoot && !tps.reloading && tps.ammo > 0 && Date.now() - tps.lastShootTime > 100) {
|
|
160
|
+
tps.lastShootTime = Date.now()
|
|
161
|
+
const local = engine.client.state?.players?.find(p => p.id === engine.playerId)
|
|
162
|
+
if (local) {
|
|
163
|
+
const pos = local.position
|
|
164
|
+
engine.client.sendFire({ origin: [pos[0], pos[1] + 0.9, pos[2]], direction: engine.cam.getAimDirection(pos) })
|
|
165
|
+
const animator = engine.players.getAnimator(engine.playerId)
|
|
166
|
+
if (animator) animator.shoot()
|
|
167
|
+
tps.flash.position.set(pos[0], pos[1] + 0.5, pos[2])
|
|
168
|
+
tps.flash.intensity = 3
|
|
169
|
+
tps.flashOff = Date.now() + 60
|
|
170
|
+
tps.ammo = Math.max(0, tps.ammo - 1)
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
onEvent(payload, engine) {
|
|
175
|
+
const tps = engine._tps
|
|
176
|
+
if (payload.type === 'hit' && payload.target) {
|
|
177
|
+
engine.players.setExpression(payload.target, 'angry', 0.6)
|
|
178
|
+
setTimeout(() => engine.players.setExpression(payload.target, 'angry', 0), 500)
|
|
179
|
+
}
|
|
180
|
+
if (payload.type === 'aimpunch' && engine.cam?.punch) {
|
|
181
|
+
engine.cam.punch(payload.intensity || 0.3)
|
|
182
|
+
}
|
|
183
|
+
if (payload.type === 'death' && payload.victim) {
|
|
184
|
+
engine.players.setExpression(payload.victim, 'sorrow', 1.0)
|
|
185
|
+
}
|
|
186
|
+
if (payload.type === 'buff_applied' && tps) {
|
|
187
|
+
tps.boost = { expiresAt: Date.now() + (payload.duration || 45) * 1000 }
|
|
188
|
+
}
|
|
189
|
+
if (payload.type === 'buff_expired' && tps) { tps.boost = null }
|
|
190
|
+
if (payload.type === 'reload_start' && tps) {
|
|
191
|
+
tps.reloading = true
|
|
192
|
+
tps.reloadEndTime = Date.now() + (payload.duration || 2000)
|
|
193
|
+
const animator = engine.players?.getAnimator(engine.playerId)
|
|
194
|
+
if (animator) animator.reload()
|
|
195
|
+
}
|
|
196
|
+
if (payload.type === 'reload_complete' && tps) {
|
|
197
|
+
tps.reloading = false
|
|
198
|
+
tps.ammo = 30
|
|
199
|
+
}
|
|
200
|
+
if (payload.type === 'empty_click' && tps) {
|
|
201
|
+
// Could play empty click sound here
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
onFrame(dt, engine) {
|
|
205
|
+
const tps = engine._tps
|
|
206
|
+
if (!tps) return
|
|
207
|
+
if (tps.boost && Date.now() >= tps.boost.expiresAt) tps.boost = null
|
|
208
|
+
if (tps.flash && tps.flashOff && Date.now() >= tps.flashOff) { tps.flash.intensity = 0; tps.flashOff = 0 }
|
|
209
|
+
engine.players.setAiming(engine.playerId, tps.isAiming)
|
|
210
|
+
},
|
|
80
211
|
render(ctx) {
|
|
81
212
|
const h = ctx.h
|
|
213
|
+
if (!h) return { position: ctx.entity.position }
|
|
82
214
|
const s = ctx.state || {}
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
) :
|
|
215
|
+
const local = ctx.players?.find(p => p.id === ctx.engine?.playerId)
|
|
216
|
+
const hp = local?.health ?? 100
|
|
217
|
+
const tps = ctx.engine?._tps
|
|
218
|
+
const boostSec = tps?.boost ? Math.ceil((tps.boost.expiresAt - Date.now()) / 1000) : 0
|
|
219
|
+
const ammo = tps?.ammo ?? 0
|
|
220
|
+
const reloading = tps?.reloading ?? false
|
|
221
|
+
const reloadProgress = reloading && tps?.reloadEndTime ? Math.min(100, Math.round((1 - (tps.reloadEndTime - Date.now()) / 2000) * 100)) : 0
|
|
87
222
|
return {
|
|
88
223
|
position: ctx.entity.position,
|
|
89
|
-
custom: { game: s.map, mode: s.mode
|
|
90
|
-
ui
|
|
224
|
+
custom: { game: s.map, mode: s.mode },
|
|
225
|
+
ui: h('div', { class: 'tps-hud' },
|
|
226
|
+
h('div', { id: 'crosshair', style: 'position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);font-size:24px;color:#fff;text-shadow:0 0 2px #000' }, '+'),
|
|
227
|
+
h('div', { id: 'ammo-counter', style: 'position:fixed;bottom:50px;right:20px;font-size:24px;font-weight:bold;color:#fff;text-shadow:0 0 4px #000;font-family:monospace' },
|
|
228
|
+
reloading ? h('span', { style: 'color:#ff0' }, `RELOADING ${reloadProgress}%`) : h('span', null, `${ammo}/30`)
|
|
229
|
+
),
|
|
230
|
+
h('div', { id: 'health-bar', style: 'position:fixed;bottom:20px;left:50%;transform:translateX(-50%);width:200px;height:20px;background:#333;border-radius:4px;overflow:hidden' },
|
|
231
|
+
h('div', { style: `width:${hp}%;height:100%;background:${hp > 60 ? '#0f0' : hp > 30 ? '#ff0' : '#f00'};transition:width 0.2s` }),
|
|
232
|
+
h('span', { style: 'position:absolute;width:100%;text-align:center;color:#fff;font-size:12px;line-height:20px' }, String(hp))
|
|
233
|
+
),
|
|
234
|
+
boostSec > 0 ? h('div', { style: 'position:fixed;top:80px;right:20px;padding:8px 16px;background:linear-gradient(135deg,#ffd700,#ff8c00);color:#000;font-weight:bold;border-radius:6px;font-size:14px;box-shadow:0 0 12px rgba(255,215,0,0.6)' }, `BOOSTED ${boostSec}s`) : null
|
|
235
|
+
)
|
|
91
236
|
}
|
|
92
237
|
}
|
|
93
238
|
}
|
|
@@ -95,8 +240,8 @@ export default {
|
|
|
95
240
|
|
|
96
241
|
function findSpawnPoints(ctx) {
|
|
97
242
|
const valid = []
|
|
98
|
-
for (let x = -
|
|
99
|
-
for (let z = -
|
|
243
|
+
for (let x = -56; x <= 44; x += 13) {
|
|
244
|
+
for (let z = -90; z <= 34; z += 12) {
|
|
100
245
|
const hit = ctx.raycast([x, 20, z], [0, -1, 0], 30)
|
|
101
246
|
if (hit.hit && hit.position[1] > -3) valid.push([x, hit.position[1] + 2, z])
|
|
102
247
|
}
|
|
@@ -106,16 +251,21 @@ function findSpawnPoints(ctx) {
|
|
|
106
251
|
}
|
|
107
252
|
|
|
108
253
|
function getAvailableSpawnPoint(ctx, spawnPoints) {
|
|
109
|
-
const MIN_SAFE_DISTANCE =
|
|
254
|
+
const MIN_SAFE_DISTANCE = 15
|
|
110
255
|
const activePlayers = ctx.players.getAll().filter(p => p.state && !ctx.state.respawning.has(p.id))
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
256
|
+
if (activePlayers.length === 0) return spawnPoints[Math.floor(Math.random() * spawnPoints.length)]
|
|
257
|
+
const scored = spawnPoints.map(sp => {
|
|
258
|
+
let minDist = Infinity
|
|
259
|
+
for (const player of activePlayers) {
|
|
260
|
+
const dist = Math.hypot(sp[0] - player.state.position[0], sp[2] - player.state.position[2])
|
|
261
|
+
if (dist < minDist) minDist = dist
|
|
262
|
+
}
|
|
263
|
+
return { sp, minDist }
|
|
116
264
|
})
|
|
117
|
-
const
|
|
118
|
-
return
|
|
265
|
+
const safe = scored.filter(s => s.minDist >= MIN_SAFE_DISTANCE)
|
|
266
|
+
if (safe.length > 0) return safe[Math.floor(Math.random() * safe.length)].sp
|
|
267
|
+
scored.sort((a, b) => b.minDist - a.minDist)
|
|
268
|
+
return scored[0].sp
|
|
119
269
|
}
|
|
120
270
|
|
|
121
271
|
function handleFire(ctx, msg) {
|
|
@@ -142,16 +292,24 @@ function handleFire(ctx, msg) {
|
|
|
142
292
|
const dist = Math.hypot(proj[0] - tp[0], proj[1] - (tp[1] + 0.9), proj[2] - tp[2])
|
|
143
293
|
if (dist > 0.6) continue
|
|
144
294
|
|
|
295
|
+
const hitY = proj[1]
|
|
296
|
+
const playerHeight = 1.8
|
|
297
|
+
const hitRatio = (hitY - tp[1]) / playerHeight
|
|
298
|
+
const isHeadshot = hitRatio >= ctx.state.config.headshotZone
|
|
299
|
+
const finalDamage = isHeadshot ? Math.round(damage * ctx.state.config.headshotMultiplier) : damage
|
|
145
300
|
const hp = target.state.health ?? ctx.state.config.health
|
|
146
|
-
const newHp = Math.max(0, hp -
|
|
301
|
+
const newHp = Math.max(0, hp - finalDamage)
|
|
147
302
|
target.state.health = newHp
|
|
148
303
|
|
|
149
|
-
|
|
304
|
+
target.state.velocity[0] += direction[0] * ctx.state.config.hitKnockback
|
|
305
|
+
target.state.velocity[2] += direction[2] * ctx.state.config.hitKnockback
|
|
306
|
+
ctx.players.send(target.id, { type: 'aimpunch', intensity: 0.6 })
|
|
307
|
+
ctx.network.broadcast({ type: 'hit', shooter: shooterId, target: target.id, damage: finalDamage, health: newHp, headshot: isHeadshot })
|
|
150
308
|
|
|
151
309
|
if (newHp <= 0) {
|
|
152
310
|
const shooterStats = ctx.state.playerStats.get(shooterId) || { kills: 0, deaths: 0, damage: 0 }
|
|
153
311
|
shooterStats.kills++
|
|
154
|
-
shooterStats.damage +=
|
|
312
|
+
shooterStats.damage += finalDamage
|
|
155
313
|
ctx.state.playerStats.set(shooterId, shooterStats)
|
|
156
314
|
const targetStats = ctx.state.playerStats.get(target.id) || { kills: 0, deaths: 0, damage: 0 }
|
|
157
315
|
targetStats.deaths++
|
|
@@ -160,7 +318,7 @@ function handleFire(ctx, msg) {
|
|
|
160
318
|
ctx.network.broadcast({ type: 'death', victim: target.id, killer: shooterId })
|
|
161
319
|
} else {
|
|
162
320
|
const shooterStats = ctx.state.playerStats.get(shooterId) || { kills: 0, deaths: 0, damage: 0 }
|
|
163
|
-
shooterStats.damage +=
|
|
321
|
+
shooterStats.damage += finalDamage
|
|
164
322
|
ctx.state.playerStats.set(shooterId, shooterStats)
|
|
165
323
|
}
|
|
166
324
|
break
|
package/apps/world/index.js
CHANGED
|
@@ -1,22 +1,68 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
port:
|
|
3
|
-
tickRate: 128,
|
|
4
|
-
gravity: [0, -9.81, 0],
|
|
5
|
-
movement: {
|
|
6
|
-
maxSpeed:
|
|
7
|
-
groundAccel: 10.0,
|
|
8
|
-
airAccel: 1.0,
|
|
9
|
-
friction:
|
|
10
|
-
stopSpeed: 2.0,
|
|
11
|
-
jumpImpulse: 4.
|
|
12
|
-
collisionRestitution: 0.
|
|
13
|
-
collisionDamping: 0.
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
export default {
|
|
2
|
+
port: 3001,
|
|
3
|
+
tickRate: 128,
|
|
4
|
+
gravity: [0, -9.81, 0],
|
|
5
|
+
movement: {
|
|
6
|
+
maxSpeed: 4.0,
|
|
7
|
+
groundAccel: 10.0,
|
|
8
|
+
airAccel: 1.0,
|
|
9
|
+
friction: 6.0,
|
|
10
|
+
stopSpeed: 2.0,
|
|
11
|
+
jumpImpulse: 4.0,
|
|
12
|
+
collisionRestitution: 0.2,
|
|
13
|
+
collisionDamping: 0.25
|
|
14
|
+
},
|
|
15
|
+
player: {
|
|
16
|
+
health: 100,
|
|
17
|
+
capsuleRadius: 0.4,
|
|
18
|
+
capsuleHalfHeight: 0.9,
|
|
19
|
+
crouchHalfHeight: 0.45,
|
|
20
|
+
mass: 120,
|
|
21
|
+
modelScale: 1.323,
|
|
22
|
+
feetOffset: 0.212
|
|
23
|
+
},
|
|
24
|
+
scene: {
|
|
25
|
+
skyColor: 0x87ceeb,
|
|
26
|
+
fogColor: 0x87ceeb,
|
|
27
|
+
fogNear: 80,
|
|
28
|
+
fogFar: 200,
|
|
29
|
+
ambientColor: 0xfff4d6,
|
|
30
|
+
ambientIntensity: 0.3,
|
|
31
|
+
sunColor: 0xffffff,
|
|
32
|
+
sunIntensity: 1.5,
|
|
33
|
+
sunPosition: [21, 50, 20],
|
|
34
|
+
fillColor: 0x4488ff,
|
|
35
|
+
fillIntensity: 0.4,
|
|
36
|
+
fillPosition: [-20, 30, -10],
|
|
37
|
+
shadowMapSize: 1024,
|
|
38
|
+
shadowBias: 0.0038,
|
|
39
|
+
shadowNormalBias: 0.6,
|
|
40
|
+
shadowRadius: 12,
|
|
41
|
+
shadowBlurSamples: 8
|
|
42
|
+
},
|
|
43
|
+
camera: {
|
|
44
|
+
fov: 70,
|
|
45
|
+
shoulderOffset: 0.35,
|
|
46
|
+
headHeight: 0.4,
|
|
47
|
+
zoomStages: [0, 1.5, 3, 5, 8],
|
|
48
|
+
defaultZoomIndex: 2,
|
|
49
|
+
followSpeed: 12.0,
|
|
50
|
+
snapSpeed: 30.0,
|
|
51
|
+
mouseSensitivity: 0.002,
|
|
52
|
+
pitchRange: [-1.4, 1.4]
|
|
53
|
+
},
|
|
54
|
+
animation: {
|
|
55
|
+
mixerTimeScale: 1.3,
|
|
56
|
+
walkTimeScale: 2.0,
|
|
57
|
+
sprintTimeScale: 0.56,
|
|
58
|
+
fadeTime: 0.15
|
|
59
|
+
},
|
|
60
|
+
entities: [
|
|
61
|
+
{ id: 'environment', model: './apps/tps-game/schwust.glb', position: [0, 0, 0], app: 'environment' },
|
|
62
|
+
{ id: 'game', position: [0, 0, 0], app: 'tps-game' },
|
|
63
|
+
{ id: 'power-crates', position: [0, 0, 0], app: 'power-crate' },
|
|
64
|
+
{ id: 'interact-box', position: [-100, 3, -100], app: 'interactable' }
|
|
65
|
+
],
|
|
66
|
+
playerModel: './apps/tps-game/Cleetus.vrm',
|
|
67
|
+
spawnPoint: [-35, 3, -65]
|
|
68
|
+
}
|