----------------- Part 2 ----------------- Code Sample 2.1 " function startGame(%level) { //exec game scripts exec("./mole.cs"); exec("./respawnPoint.cs"); // Set The GUI. Canvas.setContent(mainScreenGui); Canvas.setCursor(DefaultCursor); moveMap.push(); // this has been added: sceneWindow2D.setUseObjectMouseEvents( true ); if( isFile( %level ) || isFile( %level @ ".dso")) sceneWindow2D.loadLevel(%level); } " Code Sample 2.2 " datablock t2dSceneObjectDatablock( respawnPointDatablock ) { class = "respawnPoint"; // the class that will be associated with the object layer = 5; // the render layer size = "16 16"; // the size of the object }; " Code Sample 2.3 " function respawnPoint::onLevelLoaded(%this, %level) { %level.respawnPointSet.add(%this); } function respawnPoint::onLevelEnded(%this, %level) { if( isObject( %level.respawnPointSet ) ) %level.respawnPointSet.remove(%this); } " Code Sample 2.4 " function moleLevel::onLevelLoaded(%this) { %this.respawnPointSet = new SimSet(); } function moleLevel::onLevelEnded(%this) { %this.respawnPointSet.delete(); } " Code Sample 2.5 " function moleLevel::spawnMole(%this) { // find a spawn point %respawnPointIndex = getRandom( %this.respawnPointSet.getCount()-1 ); %respawnPoint = %this.respawnPointSet.getObject( %respawnPointIndex ); // select a color for the mole %color = getRandom(2); if( %color == 0 ) %color = "red"; if( %color == 1 ) %color = "green"; if( %color == 2 ) %color = "lilac"; // create a new Mole %mole = new t2dAnimatedSprite() { sceneGraph = %this; class = "mole"; layer = 4; size = "9 16"; }; // play right animation according to the color %mole.playAnimation("animMoleComeOut" @ %color); // save the selected color as dynamic field %mole.moleColor = %color; // set the position of the mole to the position // of the respawn point %mole.setPosition( %respawnPoint.getPosition() ); } " Code Sample 2.6 " function mole::onAnimationEnd(%this) { if( %this.getAnimationName() $= ("animMoleWhacked" @ %this.moleColor) ) { // after deleting the old mole schedule a respawn // >%this.sceneGraph< is the level %this.sceneGraph.schedule( 1500, "spawnMole"); %this.safeDelete(); } } "