Shooter Tutorial
by Shawn Porath · in Torque in Education · 02/16/2007 (12:46 pm) · 5 replies
I currently teach a game programming class at the High School level. I am trying to add the Torque game engine to my curriculum. I have tried to use the Shooter Tutorial three times now, and I cannot get the ship to move. It shows up on the screen when I run the game but the ship will not move. We moved on to the enemy portion, and get the same results (shows up, but will not move).
Here's the code, if anyone can help me it would be greatly appreciated.
This is what I have for main.cs
function initializeProject()
{
// Load up the in game gui.
exec("~/gui/mainScreen.gui");
// Exec game scripts.
exec("./gameScripts/game.cs"); //game script
if ($runWithEditors)
{
toggleLevelEditor();
return;
}
startGame($levelEditor::LastLevel[$currentProject]);
}
function shutdownProject()
{
endGame();
}
function setupKeybinds()
{
new ActionMap(moveMap);
//moveMap.bind("keyboard", "a", "doAction", "Action Description");
}
Here's what's in the game scripts folder:
Game.cs
function startGame(%level)
{
exec("./player.cs"); //player script
// 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();
}
and the player.cs file
function playerShip::onLevelLoaded(%this, %scenegraph)
{
//sets the instance to the player
$pShip = %this;
//These commands bind our keys to our functions
moveMap.bindCmd(keyboard, "w", "$pShip.playerMovement(up);", "$pShip.playerMovement(stopUp);");
moveMap.bindCmd(keyboard, "s", "$pShip.playerMovement(down);", "$pShip.playerMovement(stopDown);");
moveMap.bindCmd(keyboard, "a", "$pShip.playerMovement(left);", "$pShip.playerMovement(stopLeft);");
moveMap.bindCmd(keyboard, "d", "$pShip.playerMovement(right);", "$pShip.playerMovement(stopRight);");
}
function playerShip::updateMovement(%this)
{
//If the player is moving left, move in the direction at a predefined horizontal speed
if(%this.moveLeft)
{
%this.setLinearVelocityX( -$pShip.hSpeed );
}
//If the player is moving right, move in the direction at a predefined horizontal speed
if(%this.moveRight)
{
%this.setLinearVelocityX( $pShip.hSpeed );
}
//If the player is moving UP, move in the direction at a predefined vertical speed
if(%this.moveUp)
{
%this.setLinearVelocityY( -$pShip.vSpeed );
}
//If the player is moving down, move in the direction at a predefined vertical speed
if(%this.moveDown)
{
%this.setLinearVelocityY( $pShip.vSpeed );
}
//If the player is not moving left or right, set horizontal speed to 0
if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX( 0 );
}
//If the player is not moving up or down, set vertical speed to 0
if(!%this.moveUp && !%this.moveDown)
{
%this.setLinearVelocityY( 0 );
}
}
function pShipUp()
{
$pShip.moveUp = true;
$pShip.updateMovement();
}
function pShipDown()
{
$pShip.moveDown = true;
$pShip.updateMovement();
}
function pShipLeft()
{
$pShip.moveLeft = true;
$pShip.updateMovement();
}
function pShipRight()
{
$pShip.moveRight = true;
$pShip.updateMovement();
}
function pShipLeftStop()
{
$pShip.moveLeft = false;
$pShip.updateMovement();
}
function pShipRightStop()
{
$pShip.moveRight = false;
$pShip.updateMovement();
}
function pShipUpStop()
{
$pShip.moveUp = false;
$pShip.updateMovement();
}
function pShipDownStop()
{
$pShip.moveDown = false;
$pShip.updateMovement();
}
Thanks again for any help.
Here's the code, if anyone can help me it would be greatly appreciated.
This is what I have for main.cs
function initializeProject()
{
// Load up the in game gui.
exec("~/gui/mainScreen.gui");
// Exec game scripts.
exec("./gameScripts/game.cs"); //game script
if ($runWithEditors)
{
toggleLevelEditor();
return;
}
startGame($levelEditor::LastLevel[$currentProject]);
}
function shutdownProject()
{
endGame();
}
function setupKeybinds()
{
new ActionMap(moveMap);
//moveMap.bind("keyboard", "a", "doAction", "Action Description");
}
Here's what's in the game scripts folder:
Game.cs
function startGame(%level)
{
exec("./player.cs"); //player script
// 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();
}
and the player.cs file
function playerShip::onLevelLoaded(%this, %scenegraph)
{
//sets the instance to the player
$pShip = %this;
//These commands bind our keys to our functions
moveMap.bindCmd(keyboard, "w", "$pShip.playerMovement(up);", "$pShip.playerMovement(stopUp);");
moveMap.bindCmd(keyboard, "s", "$pShip.playerMovement(down);", "$pShip.playerMovement(stopDown);");
moveMap.bindCmd(keyboard, "a", "$pShip.playerMovement(left);", "$pShip.playerMovement(stopLeft);");
moveMap.bindCmd(keyboard, "d", "$pShip.playerMovement(right);", "$pShip.playerMovement(stopRight);");
}
function playerShip::updateMovement(%this)
{
//If the player is moving left, move in the direction at a predefined horizontal speed
if(%this.moveLeft)
{
%this.setLinearVelocityX( -$pShip.hSpeed );
}
//If the player is moving right, move in the direction at a predefined horizontal speed
if(%this.moveRight)
{
%this.setLinearVelocityX( $pShip.hSpeed );
}
//If the player is moving UP, move in the direction at a predefined vertical speed
if(%this.moveUp)
{
%this.setLinearVelocityY( -$pShip.vSpeed );
}
//If the player is moving down, move in the direction at a predefined vertical speed
if(%this.moveDown)
{
%this.setLinearVelocityY( $pShip.vSpeed );
}
//If the player is not moving left or right, set horizontal speed to 0
if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX( 0 );
}
//If the player is not moving up or down, set vertical speed to 0
if(!%this.moveUp && !%this.moveDown)
{
%this.setLinearVelocityY( 0 );
}
}
function pShipUp()
{
$pShip.moveUp = true;
$pShip.updateMovement();
}
function pShipDown()
{
$pShip.moveDown = true;
$pShip.updateMovement();
}
function pShipLeft()
{
$pShip.moveLeft = true;
$pShip.updateMovement();
}
function pShipRight()
{
$pShip.moveRight = true;
$pShip.updateMovement();
}
function pShipLeftStop()
{
$pShip.moveLeft = false;
$pShip.updateMovement();
}
function pShipRightStop()
{
$pShip.moveRight = false;
$pShip.updateMovement();
}
function pShipUpStop()
{
$pShip.moveUp = false;
$pShip.updateMovement();
}
function pShipDownStop()
{
$pShip.moveDown = false;
$pShip.updateMovement();
}
Thanks again for any help.
#2
Here is a testament to the great customer support at Garbage games!
Alles Gute!
Will
04/24/2007 (11:56 am)
Howdy,Here is a testament to the great customer support at Garbage games!
Alles Gute!
Will
#3
its very easy to spot that your code in player.cs is different I'd go back and change that to what the tutorial says
10/23/2009 (7:21 pm)
well I'm not exactly sure where you problem is, but when following a tutorial it would most likely be best to keep the code exactly as the tutorial says it, right? its very easy to spot that your code in player.cs is different I'd go back and change that to what the tutorial says
#4
Also, whenever you post code to the forums, an easy way to do it is to place your code between code tags, which look like this:
['code']
['/code']
Only without the ' chracters. That then looks like this:
@Will: Attitudes like that get you support from nobody, paid or unpaid. I know some very large, fortune-500 companies who will put customers who speak poor about them at the bottom of the list, even if that customer is paying good money for the support. So it's always in your best interest to be nice to those who are trying to help you.
10/27/2009 (3:31 pm)
@Shawn: I see you have a setupKeybinds(); function, but I'm not sure where it is getting called. From what I see in your code, that's the only place that you create the actionmap, so if it doesn't exist when you add the keybinds to it, nothing will happen.Also, whenever you post code to the forums, an easy way to do it is to place your code between code tags, which look like this:
['code']
['/code']
Only without the ' chracters. That then looks like this:
function doSomething()
{
error("@@@ Woohoo! I did stuff!");
}@Will: Attitudes like that get you support from nobody, paid or unpaid. I know some very large, fortune-500 companies who will put customers who speak poor about them at the bottom of the list, even if that customer is paying good money for the support. So it's always in your best interest to be nice to those who are trying to help you.
#5
05/12/2012 (8:18 am)
@Shawn - happy to help. I teach 2D at college. Zip it up and email it to admin AT drewfx DOT com - substite AT and DOT for the symbols :) Though I see this is from 2009 - so you still having troubles?
Shawn Porath