----------------- Part 4 - Section 1 ----------------- Code Sample 4.1.1 " function enemyShip::onLevelLoaded(%this, %scenegraph) { %this.enemyMovement(); } function enemyShip::enemyMovement(%this) { %this.setLinearVelocityX(getRandom(%this.minSpeed, %this.maxSpeed)); } " Code Sample 4.1.2 " exec(“./enemy.cs”); " Code Sample 4.2.1 " function enemyShip::onLevelLoaded(%this, %scenegraph) { %this.startX = %this.getPositionX(); %this.spawn(); } " ----------------- Part 4 - Section 2 ----------------- Code Sample 4.2.2 " function enemyShip::onWorldLimit(%this, %mode, %limit) { if(%limit $= "left") { %this.spawn(); } } " Code Sample 4.2.3 " function enemyShip::spawn(%this) { %this.setLinearVelocityX(getRandom(%this.minSpeed, %this.maxSpeed)); %this.setPositionY(getRandom(%this.minY, %this.maxY)); %this.setPositionX(%this.startX); } " Code Sample 4.2.4 " function enemyShip::onLevelLoaded(%this, %scenegraph) { %this.startX = %this.getPositionX(); %this.spawn(); } function enemyShip::onWorldLimit(%this, %mode, %limit) { if(%limit $= "left") { %this.spawn(); } } function enemyShip::spawn(%this) { %this.setLinearVelocityX(getRandom(%this.minSpeed, %this.maxSpeed)); %this.setPositionY(getRandom(%this.minY, %this.maxY)); %this.setPositionX(%this.startX); } "