Let’s put some motion into our game by taking advantage of additional Heyplay engine callbacks and functions. Replace the previous callback with following ones:
Game.onStart = () => {
for (let i = 1; i <= 5000; i++) {
Blob.create({
position: new Vector({ x: Math.random() * 1000 - 500, y: Math.random() * 1000 - 500 }),
size: 1,
color: "yellow"
})
}
}
Player.onJoin = (player: Player) => {
let blob = Blob.create({
position: new Vector({ x: (parseInt(player.id) - 1) * 20, y: 0 }),
size: 3,
velocity: new Vector({ x: 0, y: 5 })
})
player.camera.follow(blob)
}
Let’s break the changes down:
-
We define
@heyplay/iokit:Game.onStart
, another Heyplay IOKit callback, to do one-off stage setup, which comes down to creating 5K randomly placed blobs. -
For player’s blob, we specify another blob property called
velocity
in order to make it move. -
We store the blob in the
blob
variable and then we access player’s camera via@heyplay/iokit:Player.camera
property to call its@heyplay/iokit:Camera.follow
method to focus it at the blob.
Play the game to see your blob move south across a field of smaller yellow blobs.