Online Book Reader

Home Category

HTML5 Canvas [225]

By Root 6549 0
if (esob.getString("type") == "newball") {

statusMessages.push("create ball")

createNetBall(esob.getFloat("tempX"),esob.getFloat("tempY"),

esob.getFloat("tempSpeed"),esob.getFloat("tempAngle"),

esob.getFloat("tempRadius"),esob.getFloat("velocityx"),

esob.getFloat("velocityy"),event.userName,esob.getString("usercolor"),

esob.getString("ballname") );

}

}

function createNetBall(tempX,tempY,tempSpeed,tempAngle,tempRadius,tempvelocityx,

tempvelocityy, user, usercolor, ballname) {

tempBall = {x:tempX,y:tempY,radius:tempRadius, speed:tempSpeed, angle:tempAngle,

velocityx:tempvelocityx, velocityy:tempvelocityy,nextx:tempX, nexty:tempY,

mass:tempRadius, usercolor:usercolor, ballname:ballname}

balls.push(tempBall);

}

Figure 11-6 shows what this demo looks like when users click the mouse button to send balls to other users. The colors of the balls are assigned randomly.

Figure 11-6. ElectroServer chat ball demo

Example 11-3 gives the full set of code for CH11EX3.html.

Example 11-3. ES5 ball demo

CH11EX3: ES5 Ball Demo