A newbie question about Torque Game Builder, space game tutorial
by Josias Gibbs · in Torque Game Engine · 07/30/2008 (1:41 pm) · 3 replies
Hey, first time poster! Anyway...
I just started using TGB, and I'm looking for a tutorial on making a top-down space game. I'm specifically looking for a space game tutorial with semi-realistic space-flight controls (ie: 'left' rotates your ship left, 'right' rotates your ship right, 'up' thrusts your ship in the direction it's facing).
If no tutorial like this exists, then I could settle for a tutorial on how to make a tank game (ie: 'left' rotates your tank left, 'right' rotates your tank right, 'up' moves your tank forward).
help?
I just started using TGB, and I'm looking for a tutorial on making a top-down space game. I'm specifically looking for a space game tutorial with semi-realistic space-flight controls (ie: 'left' rotates your ship left, 'right' rotates your ship right, 'up' thrusts your ship in the direction it's facing).
If no tutorial like this exists, then I could settle for a tutorial on how to make a tank game (ie: 'left' rotates your tank left, 'right' rotates your tank right, 'up' moves your tank forward).
help?
About the author
#2
08/01/2008 (10:39 am)
That's exactly what I needed! Thanks Morrock
#3
if (!isObject(TankMovementControlsBehavior))
{
alxplay(engine);
%template = new BehaviorTemplate(TankMovementControlsBehavior);
%template.friendlyName = "Movement Controls";
%template.behaviorType = "Input";
%template.description = "Moves Tank in desiered directions";
%template.addBehaviorField(upKey, "Key to bind to Jump", keybind, "keyboard up");
%template.addBehaviorField(leftKey, "Key to bind to Run left", keybind, "keyboard left");
%template.addBehaviorField(rightKey, "Key to bind to Run right", keybind, "keyboard right");
}
function TankMovementControlsBehavior::onBehaviorAdd(%this)
{
if (!isObject(moveMap))
return;
%this.owner.enableUpdateCallback();
$Spell = 1;
%this.owner.spellAble = true;
moveMap.bindObj(getWord(%this.upKey, 0), getWord(%this.upKey, 1), "MoveUp", %this);
moveMap.bindObj(getWord(%this.leftKey, 0), getWord(%this.leftKey, 1), "MoveLeft", %this);
moveMap.bindObj(getWord(%this.rightKey, 0), getWord(%this.rightKey, 1), "MoveRight", %this);
moveMap.bindObj(getWord(%this.space, 0), getWord(%this.space, 1), "PressSpace", %this);
moveMap.bindObj(getWord(%this.a, 0), getWord(%this.a, 1), "PressA", %this);
}
function TankMovementControlsBehavior::onBehaviorRemove(%this)
{
if (!isObject(moveMap))
return;
%this.owner.disableUpdateCallback();
moveMap.unbindObj(getWord(%this.upKey, 0), getWord(%this.upKey, 1), %this);
moveMap.unbindObj(getWord(%this.leftKey, 0), getWord(%this.leftKey, 1), %this);
moveMap.unbindObj(getWord(%this.rightKey, 0), getWord(%this.rightKey, 1), %this);
%this.up = 0;
%this.left = 0;
%this.right = 0;
%this.space = 0;
}
function TankMovementControlsBehavior::moveUp(%this, %val)
{
%this.up = %val;
}
function TankMovementControlsBehavior::moveLeft(%this, %val)
{
if(%val < 0.20 && %val > -0.20) //used with joystick
{
%val = 0;
}
%this.left = %val * 28; // makes the playerfs horizontal speed to 28.
}
function TankMovementControlsBehavior::moveRight(%this, %val)
{
if(%val < 0.20 && %val > -0.20) //used with joystick
{
%val = 0;
}
%this.right = %val * 28;// makes the playerfs horizontal speed to 28.
}
function TankMovementControlsBehavior::PressSpace(%this, %val)
{
if(%val == 1)
{
%this.space = %val;
}}
function TankMovementControlsBehavior::OnUpdate(%this)
{
if(%this.owner.getAnimationName() $= "Player_TakeDamage" || %this.owner.getAnimationName() $= "Player_Cast" || %this.owner.getAnimationName() $= "Player_Die")
{
%this.owner.setLinearVelocityX(0);
if(%this.owner.getIsAnimationFinished())
{
%this.owner.playAnimation(Player_Wait);
}}
else
{
if(%this.owner.getLinearVelocityY() < -1)
{
//This code makes the one way collisions
%this.owner.setCollisionActive(false,false);
}
else
{
%this.owner.setCollisionActive(true,true);
}
%this.owner.SetLinearVelocityX(%this.right - %this.left);
if(%this.up == 1)
{
if(!%this.owner.airborne)
{
%this.owner.setLinearVelocityY(-100);
%this.owner.airborne = true;
}}
%yVelocity = %this.owner.getLinearVelocityY();
if(%this.owner.airborne)
{
%this.owner.setLinearVelocityY(0);
%collision = %this.owner.castCollision(0.005);
if(%collision !$= "")
%this.owner.setLinearVelocityX(0);
}
%this.owner.setLinearVelocityY(70);
%collision = %this.owner.castCollision(0.005);
if(%collision $= "")
{
%this.owner.airborne = true;
%this.owner.setConstantForceY(70);
}
else if(%yVelocity < 0 && %this.owner.airborne)
{
%this.owner.setConstantForceY(70);
}
else
{
%this.owner.airborne = false;
%this.owner.setConstantForceY(0);
}
%this.owner.setLinearVelocityY(%yVelocity);
%this.Animation();
}}
function TankMovementControlsBehavior::Animation(%this)
{
%xVelocity = %this.owner.getLinearVelocityX();
%yVelocity = %this.owner.getLinearVelocityY();
if(%xVelocity > 0)
{
%this.owner.setFlip(false, false);
}
else if(%xVelocity < 0)
{
%this.owner.setFlip(true, false);
}
if(%this.owner.airborne)
{
if(%yVelocity != 0)
{
if(%this.owner.getAnimationName() $= "Player_Wait")
{
if(%this.owner.getIsAnimationFinished())
{
%this.owner.playAnimation(Player_Wait);
}}
else
{
%this.owner.playAnimation(Player_Wait);
}}}
else
{
if(%xVelocity == 0)
{
%this.owner.playAnimation(Player_Wait);
}
else
{
if(%this.owner.getAnimationName() $= "Player_Walk")
{
if(%this.owner.getIsAnimationFinished())
{
%this.owner.playAnimation(Player_Walk);
}}
else
{
%this.owner.playAnimation(Player_Walk);
}}}}
08/16/2009 (11:56 pm)
Heres a Tank code if you still read this thread.if (!isObject(TankMovementControlsBehavior))
{
alxplay(engine);
%template = new BehaviorTemplate(TankMovementControlsBehavior);
%template.friendlyName = "Movement Controls";
%template.behaviorType = "Input";
%template.description = "Moves Tank in desiered directions";
%template.addBehaviorField(upKey, "Key to bind to Jump", keybind, "keyboard up");
%template.addBehaviorField(leftKey, "Key to bind to Run left", keybind, "keyboard left");
%template.addBehaviorField(rightKey, "Key to bind to Run right", keybind, "keyboard right");
}
function TankMovementControlsBehavior::onBehaviorAdd(%this)
{
if (!isObject(moveMap))
return;
%this.owner.enableUpdateCallback();
$Spell = 1;
%this.owner.spellAble = true;
moveMap.bindObj(getWord(%this.upKey, 0), getWord(%this.upKey, 1), "MoveUp", %this);
moveMap.bindObj(getWord(%this.leftKey, 0), getWord(%this.leftKey, 1), "MoveLeft", %this);
moveMap.bindObj(getWord(%this.rightKey, 0), getWord(%this.rightKey, 1), "MoveRight", %this);
moveMap.bindObj(getWord(%this.space, 0), getWord(%this.space, 1), "PressSpace", %this);
moveMap.bindObj(getWord(%this.a, 0), getWord(%this.a, 1), "PressA", %this);
}
function TankMovementControlsBehavior::onBehaviorRemove(%this)
{
if (!isObject(moveMap))
return;
%this.owner.disableUpdateCallback();
moveMap.unbindObj(getWord(%this.upKey, 0), getWord(%this.upKey, 1), %this);
moveMap.unbindObj(getWord(%this.leftKey, 0), getWord(%this.leftKey, 1), %this);
moveMap.unbindObj(getWord(%this.rightKey, 0), getWord(%this.rightKey, 1), %this);
%this.up = 0;
%this.left = 0;
%this.right = 0;
%this.space = 0;
}
function TankMovementControlsBehavior::moveUp(%this, %val)
{
%this.up = %val;
}
function TankMovementControlsBehavior::moveLeft(%this, %val)
{
if(%val < 0.20 && %val > -0.20) //used with joystick
{
%val = 0;
}
%this.left = %val * 28; // makes the playerfs horizontal speed to 28.
}
function TankMovementControlsBehavior::moveRight(%this, %val)
{
if(%val < 0.20 && %val > -0.20) //used with joystick
{
%val = 0;
}
%this.right = %val * 28;// makes the playerfs horizontal speed to 28.
}
function TankMovementControlsBehavior::PressSpace(%this, %val)
{
if(%val == 1)
{
%this.space = %val;
}}
function TankMovementControlsBehavior::OnUpdate(%this)
{
if(%this.owner.getAnimationName() $= "Player_TakeDamage" || %this.owner.getAnimationName() $= "Player_Cast" || %this.owner.getAnimationName() $= "Player_Die")
{
%this.owner.setLinearVelocityX(0);
if(%this.owner.getIsAnimationFinished())
{
%this.owner.playAnimation(Player_Wait);
}}
else
{
if(%this.owner.getLinearVelocityY() < -1)
{
//This code makes the one way collisions
%this.owner.setCollisionActive(false,false);
}
else
{
%this.owner.setCollisionActive(true,true);
}
%this.owner.SetLinearVelocityX(%this.right - %this.left);
if(%this.up == 1)
{
if(!%this.owner.airborne)
{
%this.owner.setLinearVelocityY(-100);
%this.owner.airborne = true;
}}
%yVelocity = %this.owner.getLinearVelocityY();
if(%this.owner.airborne)
{
%this.owner.setLinearVelocityY(0);
%collision = %this.owner.castCollision(0.005);
if(%collision !$= "")
%this.owner.setLinearVelocityX(0);
}
%this.owner.setLinearVelocityY(70);
%collision = %this.owner.castCollision(0.005);
if(%collision $= "")
{
%this.owner.airborne = true;
%this.owner.setConstantForceY(70);
}
else if(%yVelocity < 0 && %this.owner.airborne)
{
%this.owner.setConstantForceY(70);
}
else
{
%this.owner.airborne = false;
%this.owner.setConstantForceY(0);
}
%this.owner.setLinearVelocityY(%yVelocity);
%this.Animation();
}}
function TankMovementControlsBehavior::Animation(%this)
{
%xVelocity = %this.owner.getLinearVelocityX();
%yVelocity = %this.owner.getLinearVelocityY();
if(%xVelocity > 0)
{
%this.owner.setFlip(false, false);
}
else if(%xVelocity < 0)
{
%this.owner.setFlip(true, false);
}
if(%this.owner.airborne)
{
if(%yVelocity != 0)
{
if(%this.owner.getAnimationName() $= "Player_Wait")
{
if(%this.owner.getIsAnimationFinished())
{
%this.owner.playAnimation(Player_Wait);
}}
else
{
%this.owner.playAnimation(Player_Wait);
}}}
else
{
if(%xVelocity == 0)
{
%this.owner.playAnimation(Player_Wait);
}
else
{
if(%this.owner.getAnimationName() $= "Player_Walk")
{
if(%this.owner.getIsAnimationFinished())
{
%this.owner.playAnimation(Player_Walk);
}}
else
{
%this.owner.playAnimation(Player_Walk);
}}}}
Torque 3D Owner Morrock