Entity
The non-player things. Pong has one type: the ball. There
is only ever one on the court, spawned by the serve.
Unlike Pointing's static dot, the ball moves every tick, so it carries a
schema and one update. Its
update-frontend.js is shared (server and clients both integrate it) and it has no private
logic, so there is no update-backend.js.
ball
The single ball in play. Its fields are the position x, y and the velocity
vx, vy, all shared so the client
can predict the ball between snapshots. Position is smoothed; velocity is not, since it only changes
in discrete steps at a bounce.
[
{
"gamehoster-entity-schema-name": "x",
"gamehoster-entity-schema-type": "number",
"gamehoster-entity-schema-default": 400,
"gamehoster-entity-schema-sync": "shared",
"gamehoster-entity-schema-audience": "all",
"gamehoster-entity-schema-smooth": true
},
{
"gamehoster-entity-schema-name": "y",
"gamehoster-entity-schema-type": "number",
"gamehoster-entity-schema-default": 240,
"gamehoster-entity-schema-sync": "shared",
"gamehoster-entity-schema-audience": "all",
"gamehoster-entity-schema-smooth": true
},
{
"gamehoster-entity-schema-name": "vx",
"gamehoster-entity-schema-type": "number",
"gamehoster-entity-schema-default": 0,
"gamehoster-entity-schema-sync": "shared",
"gamehoster-entity-schema-audience": "all"
},
{
"gamehoster-entity-schema-name": "vy",
"gamehoster-entity-schema-type": "number",
"gamehoster-entity-schema-default": 0,
"gamehoster-entity-schema-sync": "shared",
"gamehoster-entity-schema-audience": "all"
}
]
// The ball's shared update, one integration step. This file runs on the server
// (authority) and on every client (prediction); x/y/vx/vy are `sync: "shared"`, so
// the client's write sticks locally and reconciles when the next packet arrives.
// The ball has no private logic, so there is no gamehoster-entity-update-backend.js.
if (Gamehoster.Instance.State.Get(Gamehoster.Context.instanceId, "phase") !== "playing") return
const me = Gamehoster.Context.entityId
Gamehoster.Entity.State.Set(me, "x", Gamehoster.Entity.State.Get(me, "x") + Gamehoster.Entity.State.Get(me, "vx"))
Gamehoster.Entity.State.Set(me, "y", Gamehoster.Entity.State.Get(me, "y") + Gamehoster.Entity.State.Get(me, "vy"))