----------------- Part 7 - Section 2 ----------------- Code Sample 7.2.1 " function startGame(%level) { exec("./player.cs"); exec("./fishfood.cs"); exec("./fish.cs"); exec("./mine.cs"); // Set The GUI. Canvas.setContent(mainScreenGui); Canvas.setCursor(DefaultCursor); moveMap.push(); if( isFile( %level ) || isFile( %level @ ".dso")) sceneWindow2D.loadLevel(%level); } " Code Sample 7.2.2 " function Mine::onLevelLoaded(%this, %scenegraph) { %this.startingY = %this.getPositionY(); %this.spawn(); } " Code Sample 7.2.3 " function Mine::spawn(%this) { %this.state = "fallingDown"; %this.speed = getRandom(%this.minSpeed, %this.maxSpeed); %this.originX = getRandom(%this.minX, %this.maxX); %this.originY = getRandom(%this.minY, %this.maxY); %this.setPosition(%this.originX, %this.startingY); %this.moveTo(%this.originX, %this.originY, %this.speed, true, true); } " Code Sample 7.2.4 " function Mine::onPositionTarget(%this) { %this.floatRange = getRandom(%this.minFloatRange, %this.maxFloatRange); switch$(%this.state) { case "fallingDown": %this.floatDown(); case "floatingDown": %this.floatUp(); case "floatingUp": %this.floatDown(); } } " Code Sample 7.2.5 " function Mine::floatUp(%this) { %this.state = "floatingUp"; %targetY = %this.originY - %this.floatRange; %this.moveTo(%this.originX, %targetY, %this.speed, true, true); } function Mine::floatDown(%this) { %this.state = "floatingDown"; %targetY = %this.originY + %this.floatRange; %this.moveTo(%this.originX, %targetY, %this.speed, true, true); } " ----------------- Part 7 - Section 4 ----------------- Code Sample 7.4.1 " function Mine::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts) { if(%dstObj.class $= "PlayerFish") { %srcObj.spawn(); %dstObj.modifyLife(-%srcObj.damageValue); } } " ----------------- Part 7 - Section 5 ----------------- Code Sample 7.5.1 " if(isEventPending(%this.respawnSchedule)) cancel(%this.respawnSchedule); %respawnTime = getRandom(%this.minRespawnTime, %this.maxRespawnTime); %this.respawnSchedule = %this.schedule(%respawnTime, "spawn"); "