Superduper proof of concept messaging mechanism for CryptoVoxels
- Teleporters
- Stretch goal .... Battle Bot Pit with Players controlling their bots for all to watch
- Game Engine Integration
- Scripting Engine Integration
The game engine runs inside the browser on the cryptovoxel.com domain. Parcel Scripts are loaded on a subdomain inside a sandboxed iframe.
Messages are exchanged between the game engine and the sandbox using the postMessage
browser API.
With the 2.18 client the following RPC calls are implemented:
- create
- update
- snapshot
- destroy
- chat
- play
- animate
Currently the Parcel Scripts are executed in the context of a single user. There is no communication between people inside the parcel
Currently the game engine only supports sending move updates via websockets. While there is an active WebSocket connection on the cryptovoxel.com domain, there isn't one inside the parcelScript. Additionally CSP headers block externsal scripts from loading inside parcel script.
The ParcelScript
class is where we are going to target some changes. ParcelScript
renders the iframe in the browser and
sets up event listeners and acts as a proxy to the websocket for certain events. For those who want to follow along search
the compiled client file for class ParcelScript
it should be found on line 107835
This change would go inside the game engine client code.
// ...
else if("teleport"===e.type){
this.updatePacket={type:"move",rotation:Array(3),position:Array(3)};
this.updatePacket.rotation = e.targetRotation;
this.updatePacket.position = e.targetPosition;
this.send(this.updatePacket);
}
This function allows the ParcelScript
to send the player to a different predefined position.
This could would go into a ParcelScript
//Find the target location by defining another feature inside the game world.
let teleportReceiver = parcel.getFeatureById("teleport_receiver");
//feature is locally bound; it is the object in the game world you clicked on
feature.on('click', (e) => {
//parcel is in the global scope and refers to the ParcelScript object that you are contained in
parcel.broadcast({
type : "teleport",
targetRotation : teleportReceiver.rotation,
targetPosition : teleportReceiver.position
})
});