help please
by linkbob · in Game Design and Creative Issues · 08/05/2009 (8:31 pm) · 1 replies
this is my code...i cant get the fish to move...please tell me if you see what is wrong
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();");
moveMap.bindCmd(keyboard, "space", "fishPlayerBoost();", "fishPlayerBoostStop();");
}
function PlayerFish::updateMovement(%this)
{
if(%this.moveLeft)
{
$FishPlayer.setFlipX(true);
$FishPlayer.setLinearVelocityX( -$FishPlayer.hSpeed );
}
if(%this.moveRight)
{
$FishPlayer.setFlipX(false);
$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.setLinearVelocityYt2dSceneObject::setLinearVelocityY(float velocityY)( 0 );
}
}
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();
}
function fishPlayerBoost()
{
%flipX = $FishPlayer.getFlipX();
if(!%flipX)
{
%hSpeed = $FishPlayer.hSpeed * 3;
} else
{
%hSpeed = -$FishPlayer.hSpeed * 3;
}
$FishPlayer.setLinearVelocityX(%hSpeed);
}
function fishPlayerBoostStop()
{
$FishPlayer.setLinearVelocityX(0);
}
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();");
moveMap.bindCmd(keyboard, "space", "fishPlayerBoost();", "fishPlayerBoostStop();");
}
function PlayerFish::updateMovement(%this)
{
if(%this.moveLeft)
{
$FishPlayer.setFlipX(true);
$FishPlayer.setLinearVelocityX( -$FishPlayer.hSpeed );
}
if(%this.moveRight)
{
$FishPlayer.setFlipX(false);
$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.setLinearVelocityYt2dSceneObject::setLinearVelocityY(float velocityY)( 0 );
}
}
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();
}
function fishPlayerBoost()
{
%flipX = $FishPlayer.getFlipX();
if(!%flipX)
{
%hSpeed = $FishPlayer.hSpeed * 3;
} else
{
%hSpeed = -$FishPlayer.hSpeed * 3;
}
$FishPlayer.setLinearVelocityX(%hSpeed);
}
function fishPlayerBoostStop()
{
$FishPlayer.setLinearVelocityX(0);
}
About the author
Torque Owner Robert Carroll