TGB/Tutorials/Asteroids/Section3
From TDN
[edit] Asteroids TutorialWritten for TGB Version: 1.6 |
|
[edit] Adding Behaviors
//-----------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
// Behavior by Mike Lilligreen for TDN Asteroids Tutorial
//-----------------------------------------------------------------------------
if (!isObject(DisplayScoreBehavior))
{
%template = new BehaviorTemplate(DisplayScoreBehavior);
%template.friendlyName = "Display Score";
%template.behaviorType = "GUI";
%template.description = "Allows a text object to display the score";
}
function DisplayScoreBehavior::onAddToScene(%this, %scenegraph)
{
$currentScore = 0;
%this.owner.text = "Score:" SPC $currentScore;
}
function DisplayScoreBehavior::updateScore(%this)
{
%this.owner.text = "Score:" SPC $currentScore;
}
//-----------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
// Behavior by Mike Lilligreen for TDN Asteroids Tutorial
//-----------------------------------------------------------------------------
if (!isObject(ScorePointsBehavior))
{
%template = new BehaviorTemplate(ScorePointsBehavior);
%template.friendlyName = "Score Points";
%template.behaviorType = "Game";
%template.description = "Gives the object a point value for scoring purposes";
%template.addBehaviorField(pointValue, "How much the object is worth", int, 10);
%template.addBehaviorField(counter, "The score counter object", object, "", t2dSceneObject);
}
function ScorePointsBehavior::onRemove(%this)
{
%counter = %this.counter.getBehavior("DisplayScoreBehavior");
if (!isObject(%counter))
return;
$currentScore = $currentScore + %this.pointValue;
%counter.updateScore();
}
Now with these behaviors, start up TGB. [edit] Create a Score GUI Element
Score: Place the object wherever you wish, for this tutorial it is in the upper left hand corner of the camera view.
[edit] Give the Asteroids Some Points
|









