//--------------------------------------------------------------------------------------------- // Torque Game Builder // 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) { %dekstopres = getDesktopResolution(); setverticalsync(true); setres( 1024, 768, getWord(%dekstopres, 2)); Canvas.setContent(mainScreenGui); Canvas.setCursor(DefaultCursor); new ActionMap(moveMap); moveMap.push(); $enableDirectInput = true; activateDirectInput(); enableJoystick(); sceneWindow2D.loadLevel(%level); //--------------------------------------------------------------------------- player.enableupdatecallback(); movemap.bindCmd(keyboard, "up", "player.goup();", "player.upstop();"); movemap.bindCmd(keyboard, "down", "player.godown();", "player.downstop();"); movemap.bindCmd(keyboard, "left", "player.goleft();", "player.leftstop();"); movemap.bindCmd(keyboard, "right", "player.goright();", "player.rightstop();"); //--------------------------------------------------------------------------- scenewindow2d.mount(player, 0, 0, 5, true); } function player::goup(%this) { %this.up = true; } function player::upstop(%this) { %this.up = false; } function player::godown(%this) { %this.down = true; } function player::downstop(%this) { %this.down = false; } function player::goleft(%this) { %this.left = true; } function player::leftstop(%this) { %this.left = false; } function player::goright(%this) { %this.right = true; } function player::rightstop(%this) { %this.right = false; } function player::onupdate(%this) { if(%this.up) %this.setlinearvelocityy(-40); else if(%this.down) %this.setlinearvelocityy(40); else if(%this.right) %this.setlinearvelocityx(40); else if(%this.left) %this.setlinearvelocityx(-40); else %this.setlinearvelocity(0, 0); } //--------------------------------------------------------------------------------------------- // endGame // Game cleanup should be done here. //--------------------------------------------------------------------------------------------- function endGame() { sceneWindow2D.endLevel(); moveMap.pop(); moveMap.delete(); }