Game Development Community

Help with TGB/BasicTutorial2 'Shooter

by Duey Oxburger · in Torque Developer Network · 09/02/2008 (10:22 pm) · 0 replies

Sorry about the spam guys, but I'm not sure who to contact directly about this. I'm a total noob to programming and am having a problem getting my little space ship to move around in the 'Shooter' tutorial2.
Here is the way my player.cs file looks... any suggestions?:

function PlayerShip::onLevelLoaded(%this, %scenegraph)
function pShipUp()

{
// Store a reference to the player's ship in a global variable
$pShip = %this;

moveMap.bindCmd(keyboard, "up", "pShipUp();", "pShipUpStop();");
moveMap.bindCmd(keyboard, "down", "pShipDown();", "pShipDownStop();");
moveMap.bindCmd(keyboard, "left", "pShipLeft();", "pShipLeftStop();");
moveMap.bindCmd(keyboard, "right", "pShipRight();", "pShipRightStop();");
}

{
$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();
}

function PlayerShip::updateMovement(%this)
{
if (%this.moveLeft) {
%this.setLinearVelocityX( -$pShip.hSpeed );
}

if (%this.moveRight) {
%this.setLinearVelocityX( $pShip.hSpeed );
}

if (%this.moveUp) {
%this.setLinearVelocityY( -$pShip.vSpeed );
}

if (%this.moveDown) {
%this.setLinearVelocityY( $pShip.vSpeed );
}

if (!%this.moveLeft && !%this.moveRight) {
%this.setLinearVelocityX( 0 );
}

if (!%this.moveUp && !%this.moveDown) {
%this.setLinearVelocityY( 0 );
}
}