HTML and CSS Reference
In-Depth Information
esob . setFloat ( "velocityx" , tempvelocityx );
esob . setFloat ( "velocityy" , tempvelocityy );
esob . setString ( "usercolor" , usercolor );
esob . setString ( "ballname" , username + ballcounter );
esob . setString ( "type" , "newball" );
pmr . esObject = esob ;
es . engine . send ( pmr );
statusMessages . push ( "send ball" );
}
Whenauserconnectedinthesameroomreceivesthispublicmessage,wehandlethe newball
event in a similar manner to how we handled the chat text, by using the onPublicMes-
sageEvent() function. When the function sees an event with the type newball , it calls cre-
ateNetBall() . The createNetBall() function creates ball objects to bounce around the
canvas, much like the ones we created in Chapter 5 :
function
function onPublicMessageEvent ( event ) {
statusMessages . push ( "message received" );
var
var esob = event . esObject ;
iif ( esob . getString ( "type" ) == "chatmessage" ) {
chatMessages . push ( event . userName + ":" + esob . getString ( "message" ));
} else
else iif ( 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
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 );
}
Search WWH ::




Custom Search