----------------- Part 5 - Section 1 ----------------- Code Sample 5.1.1 " function startGame(%level) { exec("./player.cs"); exec("./fishfood.cs"); // Set The GUI. Canvas.setContent(mainScreenGui); Canvas.setCursor(DefaultCursor); moveMap.push(); if( isFile( %level ) || isFile( %level @ ".dso")) sceneWindow2D.loadLevel(%level); } " Code Sample 5.1.2 " function FishFood::onLevelLoaded(%this, %scenegraph) { %this.startPosition = %this.getPosition(); %this.setLinearVelocityY(getRandom(%this.minSpeed, %this.maxSpeed)); } " Code Sample 5.1.3 " function FishFood::onWorldLimit(%this, %mode, %limit) { if(%limit $= "bottom") { %this.spawn(); } } " Code Sample 5.1.4 " function FishFood::spawn(%this) { %this.setPosition(%this.startPosition); %this.setLinearVelocityY(getRandom(%this.minSpeed, %this.maxSpeed)); } " ----------------- Part 5 - Section 2 ----------------- Code Sample 5.2.1 " function FishFood::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts) { } " Code Sample 5.2.2 " function FishFood::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts) { if(%dstObj.class $= "PlayerFish") { %srcObj.spawn(); } } " ----------------- Part 5 - Section 3 ----------------- Code Sample 5.3.1 " function FishFood::onLevelLoaded(%this, %scenegraph) { %this.startPositionY = %this.getPositionY(); %this.setLinearVelocityY(getRandom(%this.minSpeed, %this.maxSpeed)); } " Code Sample 5.3.2 " function FishFood::spawn(%this) { %this.setPosition(getRandom(-50, 50), %this.startPositionY); %this.setLinearVelocityY(getRandom(%this.minSpeed, %this.maxSpeed)); } "