----------------- Part 4 - Section 1 ----------------- Code Sample 4.1.1 " function fishPlayerLeft() { $FishPlayer.setLinearVelocityX( -30 ); } " Code Sample 4.1.2 " function fishPlayerLeft() { $FishPlayer.setFlipX(false); $FishPlayer.setLinearVelocityX( -30 ); } " Code Sample 4.1.3 " function fishPlayerRight() { $FishPlayer.setFlipX(true); $FishPlayer.setLinearVelocityX( 30 ); } " ----------------- Part 4 - Section 2 ----------------- Code Sample 4.2.1 " function fishPlayerLeft() { $FishPlayer.setFlipX(false); $FishPlayer.setLinearVelocityX( -$FishPlayer.hSpeed ); } " Code Sample 4.2.2 " function fishPlayerUp() { $FishPlayer.setLinearVelocityY( -$FishPlayer.vSpeed ); } function fishPlayerDown() { $FishPlayer.setLinearVelocityY( $FishPlayer.vSpeed ); } function fishPlayerRight() { $FishPlayer.setFlipX(true); $FishPlayer.setLinearVelocityX( $FishPlayer.hSpeed ); } " ----------------- Part 4 - Section 3 ----------------- Code Sample 4.3.1 " function PlayerFish::onLevelLoaded(%this, %scenegraph) { $FishPlayer = %this; moveMap.bindCmd(keyboard, "w", "fishPlayerUp();", "fishPlayerUpStop();"); moveMap.bindCmd(keyboard, "s", "fishPlayerDown();", "fishPlayerDownStop();"); moveMap.bindCmd(keyboard, "a", "fishPlayerLeft();", "fishPlayerLeftStop();"); moveMap.bindCmd(keyboard, "d", "fishPlayerRight();", "fishPlayerRightStop();"); } " Code Sample 4.3.2 " moveMap.bindCmd(keyboard, "space", "fishPlayerBoost();", "fishPlayerBoostStop();"); " Code Sample 4.3.3 " function fishPlayerBoost() { %flipX = $FishPlayer.getFlipX(); if(%flipX) { %hSpeed = $FishPlayer.hSpeed * 3; } else { %hSpeed = -$FishPlayer.hSpeed * 3; } $FishPlayer.setLinearVelocityX(%hSpeed); } " Code Sample 4.3.4 " function fishPlayerBoostStop() { $FishPlayer.setLinearVelocityX(0); } " ----------------- Part 4 - Section 4 ----------------- Code Sample 4.4.1 " function PlayerFish::updateMovement(%this) { if(%this.moveLeft) { $FishPlayer.setFlipX(false); $FishPlayer.setLinearVelocityX( -$FishPlayer.hSpeed ); } if(%this.moveRight) { $FishPlayer.setFlipX(true); $FishPlayer.setLinearVelocityX( $FishPlayer.hSpeed ); } if(%this.moveUp) { %this.setLinearVelocityY( -$FishPlayer.vSpeed ); } if(%this.moveDown) { %this.setLinearVelocityY( $FishPlayer.vSpeed ); } if(!%this.moveLeft && !%this.moveRight) { %this.setLinearVelocityX( 0 ); } if(!%this.moveUp && !%this.moveDown) { %this.setLinearVelocityY( 0 ); } } " Code Sample 4.4.2 " function PlayerFish::updateMovement(%this) { if(%this.moveLeft) { $FishPlayer.setFlipX(false); $FishPlayer.setLinearVelocityX( -$FishPlayer.hSpeed ); } " Code Sample 4.4.3 " if(!%this.moveLeft && !%this.moveRight) { %this.setLinearVelocityX( 0 ); } if(!%this.moveUp && !%this.moveDown) { %this.setLinearVelocityY( 0 ); } " Code Sample 4.4.4 " function fishPlayerUp() { $FishPlayer.moveUp = true; $FishPlayer.updateMovement(); } function fishPlayerDown() { $FishPlayer.moveDown = true; $FishPlayer.updateMovement(); } function fishPlayerLeft() { $FishPlayer.moveLeft = true; $FishPlayer.updateMovement(); } function fishPlayerRight() { $FishPlayer.moveRight = true; $FishPlayer.updateMovement(); } function fishPlayerUpStop() { $FishPlayer.moveUp = false; $FishPlayer.updateMovement(); } function fishPlayerDownStop() { $FishPlayer.moveDown = false; $FishPlayer.updateMovement(); } function fishPlayerLeftStop() { $FishPlayer.moveLeft = false; $FishPlayer.updateMovement(); } function fishPlayerRightStop() { $FishPlayer.moveRight = false; $FishPlayer.updateMovement(); } "