Game Development Community

need help

by linkbob · in General Discussion · 08/05/2009 (7:46 pm) · 0 replies

this is what i have for code but i cant get my fish to move..anyone know whats 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);
}