----------------- Part 2 - Section 3 ----------------- Code Sample 2.3.1 " function PlayerFish::onLevelLoaded(%this, %scenegraph) { } " Code Sample 2.3.2 " $FishPlayer = %this; " Code Sample 2.3.3 " moveMap.bindCmd(keyboard, "w", "fishPlayerUp();", "fishPlayerUpStop();"); moveMap.bindCmd(keyboard, "s", "fishPlayerDown();", "fishPlayerDownStop();"); moveMap.bindCmd(keyboard, "a", "fishPlayerLeft();", "fishPlayerLeftStop();"); moveMap.bindCmd(keyboard, "d", "fishPlayerRight();", "fishPlayerRightStop();"); " ----------------- Part 2 - Section 4 ----------------- Code Sample 2.4.1 " function fishPlayerUp() { $FishPlayer.setLinearVelocityY( -15 ); } " Code Sample 2.4.2 " function fishPlayerDown() { $FishPlayer.setLinearVelocityY( 15 ); } function fishPlayerLeft() { $FishPlayer.setLinearVelocityX( -30 ); } function fishPlayerRight() { $FishPlayer.setLinearVelocityX( 30 ); } " Code Sample 2.4.3 " function fishPlayerUpStop() { $FishPlayer.setLinearVelocityY( 0 ); } function fishPlayerDownStop() { $FishPlayer.setLinearVelocityY( 0 ); } function fishPlayerLeftStop() { $FishPlayer.setLinearVelocityX( 0 ); } function fishPlayerRightStop() { $FishPlayer.setLinearVelocityX( 0 ); } " Code Sample 2.4.4 " 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();"); } function fishPlayerUp() { $FishPlayer.setLinearVelocityY( -15 ); } function fishPlayerDown() { $FishPlayer.setLinearVelocityY( 15 ); } function fishPlayerLeft() { $FishPlayer.setLinearVelocityX( -30 ); } function fishPlayerRight() { $FishPlayer.setLinearVelocityX( 30 ); } function fishPlayerUpStop() { $FishPlayer.setLinearVelocityY( 0 ); } function fishPlayerDownStop() { $FishPlayer.setLinearVelocityY( 0 ); } function fishPlayerLeftStop() { $FishPlayer.setLinearVelocityX( 0 ); } function fishPlayerRightStop() { $FishPlayer.setLinearVelocityX( 0 ); } " ----------------- Part 2 - Section 5 ----------------- Code Sample 2.5.1 " function startGame(%level) { // Set The GUI. Canvas.setContent(mainScreenGui); Canvas.setCursor(DefaultCursor); " Code Sample 2.5.2 " exec("./player.cs"); " Code Sample 2.5.3 " //--------------------------------------------------------------------------------------------- // Torque 2D. // Copyright (C) GarageGames.com, Inc. //--------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------- // startGame // All game logic should be set up here. This will be called by the level builder when you // select "Run Game" or by the startup process of your game to load the first level. //--------------------------------------------------------------------------------------------- function startGame(%level) { exec("./player.cs"); // Set The GUI. Canvas.setContent(mainScreenGui); Canvas.setCursor(DefaultCursor); moveMap.push(); if( isFile( %level ) || isFile( %level @ ".dso")) sceneWindow2D.loadLevel(%level); } //--------------------------------------------------------------------------------------------- // endGame // Game cleanup should be done here. //--------------------------------------------------------------------------------------------- function endGame() { sceneWindow2D.endLevel(); moveMap.pop(); } "