You are on page 1of 149

Torque Game Builder

)
Game Maker
) C
)
)
)


)


Torque Game Builder
$ # ) resolution
)
)
Open Project ) )
games/TutorialBase project.t2dProj
)
Resolution
#Torque Game Builder$ TGB )
:

#EditPreferences$ preferences )

Scene Editor

Sprites library
)
$ GarageGames logo # )
resolution )

resolution 800%600 )

resolution )

resolution edit Preferences )

Preferences ) Scene Editor


)

Scene Editor

Resolution

)
Resolution 800%600 )

resolution ) 1024%768 ) )

resolution )
GarageGames logos )
Games logos Garage )

resolution )

Camera Tool

CTRL
)

SHIFT
)

CRTL SHIFT

)

selection tool )

GarageGames logo
) )

Resolution
800%600)

10


TGB resource pack Project->Resources...
) ) resources
resources
) splite $ checkersArt #
Add To Project save )
checkersArt )
checkersArt )

11

TGB

ImageMap

) ) Animation Builder
)

imageMap ) Select )

12

)
) )
)

13

Save
Animated Sprites )
Image Map
TGB )
) imagemap
)

imagemap

( )
)

14

) camera tool
)
) Project
t2dSceneGraph )

15

t2dSceneGraph Edit ) $ width$ height ##


)

16


#zoom out$ )
View )

#Scene Editor$
)

Scene Object Layer )

17

Edit


TGB ) 32 $ 0
# $ 31
# )
Dynamic Fields
Dynamic fields )

Dynamic

fields Edit $ scroll #

Field Name dynamic Field Field Value


) vSpeed hSpeed
) hSpeed Field Name 30 Field
Value ) )

Field . )
Field Name 15 )

18

vSpeed

)
)

;%this.vSpeed = 20

)

$ scene # )

19

: )

)

20

21

TGB
) create )

new project . Name Project Template


Location ) Copy Game Executable
to Game Path )

Edit)

Scripting Name
22

script
!


Edit)

Scripting Class Class )


23



)( echo)
Echo )
)
~ ) ) ~
)
)
24

)
;)echo("The %this object is " @ %this

)

main

) cs)

main.cs

main


Tools->Folder Options )

25

Folder Options )
View)
Hide extensions for known file types
OK )
main.cs )


New Text Document )

26

New Text Document.txt


)
test.cs No Yes
Yes )

Notepad Choose Program


Notepad )
27

game.cs

game/gameScripts/ )

;)"exec("./aScript.cs
aScript )

Create Text Object )

) Edit ))) )

28


Collision Edit ) )
Receive Collision Send Collision

Detection mode

POLYGON )

( )

29

Collision Editor )
)

30

)
)" )"

) )
) X/Y
)
1.000 1.000 )
) )

)
)

0 )$ #
31

32

Show Convex Hull

0 $ #
)
Show Convex Violations )

33

)
' 1 0 )

) 3
4 )

34

New Points at End 3 2 )


) 6
New Points at End )

5 0 )

35

)
) )

36


) )
)

redo undo)
Display Scene Background
$ #
)
37

Particle Effect
Particle Effect )
particle Particle Effect Create )
particle )

particle Edit)

Particle

Effect )
Save Effect Load Effect
)
Edit Effect Graph effect )

38

$ effect #

Effect mode effect Use Effect Collisions effect


) Edit Effect Graph )

max min #time $ ) max min

time effect )
39

$ # $ #

$ # )
Current Field ) Size X
Life effect)
world limits
world limits )
)

zoom out)
) Selection toolbar
Enter )
World Limit
)
) world limit )
world limit Edit)
Limit Mode OFF ) Limit
Mode )( onWorldLimit )
Limit Mode)
:OFF )
40

:NULL World Limit


)
:BOUNCE World Limit)
:CLAMP World Limit )
:STICKY World Limit)
:KILL World Limit )

Mounting
link ) link
)
)

41

Linkpoint )
) Linkpoint )
)

42

Linkpoint )

Linkpoint
)

)
Linkpoint
)

43

Linkpoint
)
Linkpoint )

44

$ Control #
$ Shift # $ Alt # )
( tilemap !)
Create)

Tilemaps Tilemaps
tilemap )

45

newLayer

newLayer tilemap Edit)


' 'Tile Map Tilemaps )
' 'Edit Tile Layer 'Tile Map )

46


)
)
)
file open project games\BehaviorPlayground
BehaviorPlayground )
) !
)

47

file new scene )


) FollowMouseTutorial )

48

( Sprite)
Create )
)


edit)
) Behaviors)

49

)
)
Input Flee Mouse ' )
)
) Damping Impulse
)

50

F5 )
)
)

51



) )


documentation\content\documentation\Tutorials\Feature
)
imageMap1234ImageMap
Save )
52

Image Mode CELL ) CELL


) )
FlourSack
Save )

53


Create a new Animation )

imageMap1234ImageMap

Use Selected

imageMap )

Animation Builder )
)
:Frames Per Second )
:Start Frame )
54

:Total Time )
:Cycle Animation
)
:Name )

)

Save)
FlourSack ) Create Create a new
Animation ) FlourSackImageMap
)

55



Save Create animated sprite
) )

56

Torque Game Builder )

TutorialBase ) New Scene file


Save As file
)
Create asteroid )

57

CollisionTutorial

asteroid )
Edit)

Physics Constant

Force Y 40 )
) )

asteroid collision Edit
)

58

) asteroid )

collision Response ) asteroids )
collision Response CLAMP)
)
:BOUNCE )
:CLAMP )
:STICKY )
:KILL )
:RIGID )
)

59


) Edit
Debug Rendering ) Collision Bounds )

$ 'collision bounds' ) #
)

)

60

asteroid )
)
$ Edit POLYGON )#

61

asteroid
) )

62

)
) Rotation Edit
)

Collision Layers Collision Groups


) )
)
Collision Groups Collision Layers )
)
0 )
$ asteroid #
1 2 ) asteroid
Edit Collision Layers 1 Collision Groups
2 )

63

Scene Object Edit) layer 1


) Scene Object group 2
) asteroid
)
particle effects
particle effects Torque Game Builder
$ effect # )

) )
particle effects Particle Effects Create)
)
newEffect.eff )

Edit

Particle

Effect )
'emitters' 'effects' ) ' 'effects
' ' 'emitters ) ''emitters
particle effect

64

particle effect) ' 'emitters


' 'emitters

newEffect ) spritenewEffect
Image particles1ImageMap )
newEffect )

& ) ''emitter

)

save

simpleExplosion.eff )
!
Graph Editor
$

! # Graph Editor
) )
Current Field emitter )

65

Size X Life ) )
)
1 0 )
) 0 Size X Life )

0,3.5 )


$ select #)
66

Graph Editor
)
)
Visibility Life ) ) )

67

Current Field

Quantity Scale )
)

Emitter
Emitter ) ) Smoke
Create Emitter Emitter )

68

Emitter

Animation

flamesAnimation ) )
emitter's graph editor Size X Base
0,5 ) Quantity Base 0, 20 Speed Base 0,
0.5 )
graph editor ) Speed Variance
0, 0.5 ) )

Visibility Life
)

69

#0.7, 0 $ #0.3, 0.3 $ #0, 0 $

Orientation Emitter Smoke RANDOM )


) particle effects
)
( Path )
TutorialBase/project.t2proj)
)

70

path
create Path )
)

)

path )
)
Selection toolbar )

path

71

) GarageGames logo
Mount this object )

) )
) path )

)
) )

GarageGames logo Edit Pathing)

72


:Start Node )
:End Node )
Loops $ # ) -1 Loops
End Node )
:Speed )
:Move Forward )
:Orient To Path )
:Rotation Offset )
:Loops ) (1
)
:Follow Mode ) $ Wrap
$ Reverse' # )$ Restart #
)#
Path )
Path
73

Path )

Path ) Edit Path )


Path Type )

:Linear )
:Bezier $
# )
:catmull )
:custom )
Path )
)

74

function t2dPath::onUpdatePath(%this,%object,%from,%to)
{
//%this is the path object.
//%object is the object following the path.
//%from is the position of the most recently passed node.
//%to is of the node being moved toward.
}

Scroller
games\TutorialBase
Scroll
) )

75

dusk_skyImageMap )

76

edit 30 )

create )

edit )

77

Resolution 1024x768
)

78

create Scroller ) dusk_nearScrollImageMap


) Edit Scroller
) speed ) X 5 )
Scroller )

79

)
create scroller

dusk_farScrollImageMap )

80

scroller )

Edit Scroll Speed X Repeat X 10 2 )


)

81

Torque
TorqueScript c++ )
)
Variables
TorqueScript ) global local local
)

local

)
local )
global )
)
;%local_var = value
;$global_var = value2

)
TorqueScript )
' )_(
)

TorqueScript '

)123 (Integer
)1.234 (floating point
)1234e-3 (scientific notation
)0xc001 (hexadecimal

82

TorqueScript )


)(string
)(tagged string

""abcd
''abcd

" " )
tagged strings

)

TorqueScript
false true)
)true (1
)false (0

true false )

83

]$MyArray[n
)(Single-dimension
)$MyMultiArray[m,n] (Multi-dimension
)$MyMultiArray[m_n] (Multi-dimension

TorqueScript
) )
)

] $MyArray[1

$MyArray1 ] $MyMultiArray[0,1], $MyMultiArray[0_1


$MyMultiArray0_1 )


documentation\content\documentation\Reference
)

if-else
)if (%val < 0
{
;%abs = -%val
}
else
{
;%abs = %val
}
%val 0
)

84

switch
switch(%val)
{
case 1:
echo(The value is 1);
case 2:
echo(The value is 2);
default:
echo(The value is something else);
}
switch$
switch$(%val)
{
case Hello:
echo(The string is Hello);
case World:
echo(The string is World);
default:
echo(The string is something else);
}

) #switch$$ #switch$

For
for(%i = 0; %i < 10; %i++)
{
echo(%i @ / @ 10);
}
85

While
;%i = 0
)while (%i < 10
{
;)echo(%i @ / @ 10
;%i++
}
%i 10 $
# %i 10 )
while %i < 10
)
" : local $
global)
()Functions
)function myFunction(%arg1, %arg2
{
;%result = %arg1 + %arg2
;return %result
}

) return
)
#return$ )
()Objects

86

Torque
t2dSceneGraph t2dSceneObject

t2dStaticSprite ) new )
)%object = new t2dSceneObject(MyObject
{
;Position = 10 10
;Size = 5 15
;Rotation = 45
;OtherField = 10
;}

t2dSceneObject MyObject

%object

) t2dSceneObject
) #10 20$ )
;)%object.setPosition(10, 20
#1010 $

x=5 ,

y=15

45 )
TGB Reference)
dynamic field
) )
()Methods
)function t2dSceneObject::move(%this, %amount
{
;)(%position = %this.getPosition
;)%newPosition = t2dVectorAdd(%position, %amount
;)%this.setPosition(%newPosition
;return %newPosition
}
87

) )
t2dSceneObjects ) %object t2dSceneObject )
)
;)%object.move(10 5
%object 10 5 x y ) %this
object )

%object ) %this

Rainy Day
)
)

88

Edit Position Y Position X


) Width Height 100 75
) layer 31 )
File -> Save Level.t2d )
)

Image

Builder)
Save )

89

Create a new Animation )


Save )

90

) Animated Sprites Create )


Scene Object Edit ) plantAnimation
Send

Collision

) 16 Height Width

Send Physics Receive Physics Receive Collision Collision


)

91

Save )
)
)


linkpoints )
92

Edit this objects

linkpoint )

)
TGB )

93

Create Particle Effects New Particle Effect


) Edit Emitter - Untitled Emitter ) Image
raindropImageMap Use Effect Emission )
Edit Emitter Graph )

Emission Arc Base )

particles

) 360 ) particles
) 0.000 0.000

particles

)
Emission Angle Base

0.000 180.000

) )
Particle Life Base 0.000 10.000
10 )

94

Size X Base 0.000 11.013


)
Speed Base 0.000 12.658
)
Close )

Mount this Object


to another object ) linkpoint
) linkpoint )

95

5 Layer Scene Object Edit


)
) )
) #Notepad $

if (!isObject(MovementBehavior))
{
%template = new BehaviorTemplate(MovementBehavior);
%template.friendlyName = "Movement Behavior";
%template.behaviorType = "Movement Styles";
%template.description = "Shooter style movement control";
%template.addBehaviorField(upKey, "Key to bind to upward
movement", keybind, "keyboard up");//
96

%template.addBehaviorField(downKey, "Key to bind to


downward movement", keybind, "keyboard down");//
%template.addBehaviorField(leftKey, "Key to bind to left
movement", keybind, "keyboard left");//
%template.addBehaviorField(rightKey, "Key to bind to right
movement", keybind, "keyboard right");//
%template.addBehaviorField(verticalSpeed,
moving vertically", float, 20.0); //

"Speed

when

%template.addBehaviorField(horizontalSpeed, "Speed when


moving horizontally", float, 20.0); //
}
)"Movement Behavior"
)

function MovementBehavior::onBehaviorAdd(%this)
{
if (!isObject(moveMap))
return;
// bind our keys to the keyboard
moveMap.bindObj(getWord(%this.upKey,0),
getWord(%this.upKey, 1), "moveUp", %this); //
moveMap.bindObj(getWord(%this.downKey,0),
getWord(%this.downKey, 1), "moveDown", %this); //
moveMap.bindObj(getWord(%this.leftKey,0),
getWord(%this.leftKey, 1), "moveLeft", %this); //
97

moveMap.bindObj(getWord(%this.rightKey,0),
getWord(%this.rightKey, 1), "moveRight", %this); //
// set the default values to 0
%this.up = 0;
%this.down = 0;
%this.left = 0;
%this.right = 0;
}
function MovementBehavior::onBehaviorRemove(%this)
{
if (!isObject(moveMap))
return;
%this.owner.disableUpdateCallback();
// remove the keybinds
moveMap.unbindObj(getWord(%this.upKey,0),
getWord(%this.upKey, 1), %this); //
moveMap.unbindObj(getWord(%this.downKey,0),
getWord(%this.downKey, 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.down = 0;
%this.left = 0;
98

%this.right = 0;
}
function MovementBehavior::updateMovement(%this)
{
// make the player move
%this.owner.setLinearVelocityX((%this.right - %this.left) *
%this.horizontalSpeed); //
%this.owner.setLinearVelocityY((%this.down - %this.up) *
%this.verticalSpeed); //
}
function MovementBehavior::moveUp(%this, %val)
{
%this.up = %val;
%this.updateMovement();
}

function MovementBehavior::moveDown(%this, %val)


{
%this.down = %val;
%this.updateMovement();
}
function MovementBehavior::moveLeft(%this, %val)
{

99

;%this.left=%val
;)(%this.updateMovement
}
)function MovementBehavior::moveRight(%this, %val
{
;%this.right = %val
;)(%this.updateMovement
}

File Save

MovementBehavior.cs

Behaviors )
TGB

Edit Behaviors)

Movement Behavior )



!
100

)
) New File
)
if (!isObject(PlantGrowthBehavior))
{
%template = new BehaviorTemplate(PlantGrowthBehavior);
%template.friendlyName = "Plant Growth Behavior";
%template.behaviorType = "Management";
%template.description = "Controls the growth of the plants";
%template.addBehaviorField(Moisture, "", float, 10.0);
%template.addBehaviorField(minMoisture,
"The
lowest
amount of moisture for the plant", float, 0.0); //
%template.addBehaviorField(maxMoisture, "The
amount of moisture for the plant", float, 10.0); //

largest

%template.addBehaviorField(LowMoistureThreshold, "The
threshold that causes it to start growing or dying", float, 5.0); //

101

%template.addBehaviorField(DryRate, "How fast it loses


moisture", float, 0.05); //
%template.addBehaviorField(WateringRate, "How fast it
gains moisture", float, 0.05); //
{

File -> Save

PlantGrowthBehavior.cs Behaviors

) TGB ) Edit Behaviors )


Plant Growth Behavior
)
)


)

PlantGrowthBehavior )
102

function PlantGrowthBehavior::onAddtoScene(%this)
{
%this.dieAnim = %this.owner.getAnimation();
%j = 0;
for (%i = getWordCount(%this.dieAnim.animationFrames) - 1; %i >= 0;
%i--)//
{
%growAnim=setWord(%growAnim,%j,
getWord(%this.dieAnim.animationFrames, %i)); //
%j++;
}
%this.growAnim = new t2dAnimationDatablock()
{
animationCycle = %this.dieAnim.animationCycle;
animationFrames = %growAnim;
animationTime = %this.dieAnim.animationTime;
imageMap = %this.dieAnim.imageMap;
randomStart = %this.dieAnim.randomStart;
startFrame = %this.dieAnim.startFrame;
};
%this.owner.enableUpdateCallback();
{

) %this.dieAnim
)
) )
)
)
103

function PlantGrowthBehavior::runAnimation(%this, %direction)


{
if (%direction < 0.0)
{
if (%this.owner.getAnimation() != %this.growAnim)
{
%frame=(getWordCount(%this.growAnim.AnimationFrames)-1)%this.owner.getAnimationFrame();//
%this.owner.PlayAnimation(%this.growAnim);
%this.owner.setAnimationFrame(%frame);
}
} else
{
if (%this.owner.getAnimation() != %this.dieAnim)
{
%frame=(getWordCount(%this.dieAnim.AnimationFrames)-1)%this.owner.getAnimationFrame();//
%this.owner.PlayAnimation(%this.dieAnim);
%this.owner.setAnimationFrame(%frame);
}
}
}

function PlantGrowthBehavior::onUpdate(%this)
{
if (%this.moisture < %this.lowMoistureThreshold)
{
104

// dying -- run animation forwards.


%this.RunAnimation(1.0);
} else
{
// growing -- run animation backwards.
%this.RunAnimation(-1.0);
}
// modify amount of moisture based on whether we're being watered or not
if (%this.watering)
%this.moisture += %this.wateringRate;
else
%this.moisture -= %this.dryRate;
// clamp moisture amounts.
if (%this.moisture < %this.minMoisture)
%this.moisture = %this.minMoisture;
if (%this.moisture > %this.maxMoisture)
%this.moisture = %this.maxMoisture;
}

moisture level
%this.watering

) moisture
moisture

) %this.watering
function PlantGrowthBehavior::startWatering(%this)
{
%this.watering = true;
}
function PlantGrowthBehavior::endWatering(%this)
{
%this.watering = false;

105

}

) T2DTriggerObject
Save ) Trigger
) New File

if (!isObject(WateringBehavior))
{
%template = new BehaviorTemplate(WateringBehavior);
%template.friendlyName = "Watering Behavior";
%template.behaviorType = "Trigger";
%template.description = "Defines when to begin watering";
}
function WateringBehavior::onEnter(%this, %object)
{
%object.startWatering();
}
function WateringBehavior::onLeave(%this, %object)
{
%object.endWatering();
}

) WateringBehavior.cs ) watering
Project -> Reload Project TGB ) update
) particle effect )
particle effect
)

106

Create Trigger )
Mount this object to another object
) )

Trigger

Behavior Edit

Watering

Trigger
Behavior ) )
Leave Callback )

107

Trigger ! $
# )
)

108

Paste Copy

) )
)

: Shooter

player's ship )
)

)
)

109

:
)

Camera Tool )

zoom out
)
CTRL ) )

110

Selection
)

111

)
sky )
)
! )
30 )

112

113



$ # )
)

)
Scripting Edit )

Class Name

) name ' )
class ) Name pShip
Class playerShip )

114

)
) )
" * games/ * " /gameScripts )
game.cs )
script ) text
player.cs ) .cs )
)

: //
)

115

%this )
s, d )
)

116

w, a,

)
true updateMovement(), )
)( updateMovement 8 )

117

118

player.cs

) )( startGame game.cs )

;)"exec("./player.cs

player.cs )
player.cs updateMovement
)

;) %this.setLinearVelocityX( $pShip.hSpeed
;) %this.setLinearVelocityY( -$pShip.vSpeed

vSpeed velocity )

Dynamic Fields edit)

) hSpeed 100
vSpeed 80 )

119

)

)
) world limits ) world limits)

120

world limit selection )


world limit ) World Limits
edit)

CLAMP )

world limit



) Create enemy ship )
121


TGB )

800x600 TGB
) TGB

800x600

)
)

)
Edit eShip enemyShip ) gameScripts
text enemy.cs
)
122

enemy.cs )

minSpeed

maxSpeed x )
dynamic fields )
)
gameScripts game.cs

;)"exec("./player.cs

;)"exec("./enemy.cs

enemy.cs )

123

dynamic fields

maxSpeed minSpeed )

(175

(255 )
) )


)
!
#spawn$ )
)
world limit ) world limit
)

124

)
world limit )
maxY minY )
dynamic fields ) Y
Y )
Y Scene Object )

minY 25 maxY (95 )

125

Limit Mode ) callback World Limit


) world limit NULL

) enemy.cs

function enemyShip::onLevelLoaded(%this, %scenegraph)


{
%this.startX = %this.getPositionX();
%this.spawn();
}
function enemyShip::onLevelLoaded(%this, %scenegraph)
126

{
%this.enemyMovement();
}

%this.startX = %this.getPositionX();

) X
)
) world limit

function enemyShip::onWorldLimit(%this, %mode, %limit)


{
if(%limit $= "left")
{
%this.spawn();
}
}
' world limit
) ) spawn()

function enemyShip::spawn(%this)
{
%this.setLinearVelocityX(getRandom(%this.minSpeed, %this.maxSpeed));
%this.setPositionY(getRandom(%this.minY, %this.maxY));
%this.setPositionX(%this.startX);
}

127

#spawn $
maxSpeed minSpeed )
Y maxY minY
x )
)
)
)
) x $
# )

) )
dynamic field missileSpeed 1000 )

)
) '

TGB

player.cs

gameScripts ) onLevelLoaded )

;)"" moveMap.bindCmd(keyboard, "space", "$pShip.createMissile();",


128

) createMissile space
) createMissile

function playerShip::createMissile(%this)
{
%this.playerMissile = new t2dStaticSprite()
{
scenegraph = %this.scenegraph;
class = playerMissile;
missileSpeed=%this.missileSpeed;
player = %this;
};
%this.playerMissile.fire();
}

)
) ) scenegraph
) playerMissile
)
playerMissile.cs gameScripts
)

function playerMissile::fire(%this)
{
%this.setWorldLimit( kill, "-85 -115 155 50" );
%this.setLinearVelocityX(%this.missileSpeed);
%this.setPosition(%this.player.getPosition());
%this.setImageMap(playerMissileImageMap);
%this.setSize(12, 2);
129

;) %this.setCollisionActive( true, true


;)%this.setCollisionPhysics(false, false
;)%this.setCollisionCallback(true
}

world limit
world limit )

missileSpeed

) )
) )
) 12 2 )

) collision physics collision callbacks
)

function playerMissile::onCollision( %srcObj, %dstObj, %srcRef, %dstRef,


) %time, %normal, %contactCount, %contacts
{
)"if(%dstObj.class $= "enemyShip
{
;)(%srcObj.explode
;)(%dstObj.explode
}
}

130

enemyShip

explode )

)function playerMissile::explode(%this
{
;)(%this.safeDelete
}
)
explode
) enemy.cs )

)function enemyShip::explode(%this
{
;)(%this.spawn
}

game.cs ) $
#

;)"exec("./player.cs
;)"exec("./enemy.cs
;)"exec("./playerMissile.cs

131

Collision Poly )

selection )

edit Collision ) )

132


)
!
)
)

edit

133

Collision

edit dynamic fields

( 500 ) missileSpeed
)

gameScripts

)
) ) enemy.cs

function enemyShip::fireMissile(%this)
{
%this.enemyMissile = new t2dStaticSprite()
{
scenegraph = %this.scenegraph;
class = enemyMissile;
missileSpeed = %this.missileSpeed;
enemy = %this;
};

134

%this.enemyMissile.fire();
}
)
) fireMissile ) fire
) )
) enemyShip::spawn()

function enemyShip::spawn(%this)
{
%this.setLinearVelocityX(getRandom(%this.minSpeed, %this.maxSpeed));
%this.setPositionY(getRandom(%this.minY, %this.maxY));
%this.setPositionX(%this.startX);
%this.fireMissile();
}
)
)
playerMissile enemyMissile.cs gameScripts
)

function enemyMissile::fire(%this)
{
%this.setWorldLimit( kill, getWords(%this.enemy.getWorldLimit(), 1, 4) );
%this.setLinearVelocityX(%this.missileSpeed);
%this.setPosition(%this.enemy.getPosition());
%this.setImageMap(enemyMissileImageMap);
%this.setSize(12, 2);
%this.setCollisionActive( true, true );
%this.setCollisionPhysics(false, false);
%this.setCollisionCallback(true);

135

}
' fire enemy.cs ) playerMissile
) world limit
world limit )
' )

function enemyMissile::onCollision( %srcObj, %dstObj, %srcRef, %dstRef,


! %time, %normal, %contactCount, %contacts ) //
{
)"if(%dstObj.class $= "playerShip
{
;)(%srcObj.explode
;)(%dstObj.explode
}
}

onCollision ) )
)

)function enemyMissile::explode(%this
{
;)(%this.safeDelete
}

)
) player.cs )

136


) player.cs

) )
) player.cs onLevelLoaded

function playerShip::onLevelLoaded(%this, %scenegraph)


{
//set the player's ship name to the instance
$pShip = %this;
moveMap.bindCmd(keyboard, "w", "pShipUp();", "pShipUpStop();");
moveMap.bindCmd(keyboard, "s", "pShipDown();", "pShipDownStop();");
moveMap.bindCmd(keyboard, "a", "pShipLeft();", "pShipLeftStop();");
moveMap.bindCmd(keyboard, "d", "pShipRight();", "pShipRightStop();");
%this.isDead = false;
}

! false
createMissile
)
)

function playerShip::createMissile(%this)
{
%this.playerMissile = new t2dStaticSprite()
{
137

scenegraph = %this.scenegraph;
class = playerMissile;
missileSpeed=%this.missileSpeed;
player = %this;
};
%this.playerMissile.fire();
}

function playerShip::createMissile(%this)
{
if(!%this.isDead)
{
%this.playerMissile = new t2dStaticSprite()
{
scenegraph = %this.scenegraph;
class = playerMissile;
missileSpeed=%this.missileSpeed;
player = %this;
};
%this.playerMissile.fire();
}
}

)
)
)

138

function playerShip::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time,


%normal, %contactCount, %contacts )//
{
)if(%this.isDead
;return
)"if(%dstObj.class $= "enemyShip
{
;)(%srcObj.explode
;)(%dstObj.explode
}
}

onCollision
) isDead true)
true )
)( explode )

)function playerShip::explode(%this
{
;%this.isDead = true
;)%this.setEnabled(false
;)"%this.schedule(2000, "spawn
}

isDead false ) )
startY startX ( )
) startY startX )
player.cs onLevelLoaded ) )
)function playerShip::onLevelLoaded(%this, %scenegraph
139

{
//set the player's ship name to the instance
$pShip = %this;
%this.isDead = false;
//These commands bind our keys to our functions
moveMap.bindCmd(keyboard, "w", "pShipUp();", "pShipUpStop();");
moveMap.bindCmd(keyboard, "s", "pShipDown();", "pShipDownStop();");
moveMap.bindCmd(keyboard, "a", "pShipLeft();", "pShipLeftStop();");
moveMap.bindCmd(keyboard, "d", "pShipRight();", "pShipRightStop();");
moveMap.bindCmd(keyboard, "space", "$pShip.createMissile();", "");
}

) isDead

//save the players starting position


%this.startX = %this.getPositionX();
%this.startY = %this.getPositionY();

startY startX
)
) onLevelLoaded

function playerShip::onLevelLoaded(%this, %scenegraph)


{
//set the player's ship name to the instance
$pShip = %this;

140

%this.isDead = false;

//save the players starting position


%this.startX = %this.getPositionX();
%this.startY = %this.getPositionY();

//These commands bind our keys to our functions


moveMap.bindCmd(keyboard, "w", "pShipUp();", "pShipUpStop();");
moveMap.bindCmd(keyboard, "s", "pShipDown();", "pShipDownStop();");
moveMap.bindCmd(keyboard, "a", "pShipLeft();", "pShipLeftStop();");
moveMap.bindCmd(keyboard, "d", "pShipRight();", "pShipRightStop();");
moveMap.bindCmd(keyboard, "space", "$pShip.createMissile();", "");
}

) game.cs exec enemyMissile


) exec

exec("./player.cs");
exec("./enemy.cs");
exec("./playerMissile.cs");
exec("./enemyMissile.cs");

)
) )
)

141


particle
)
Edit Particle Effects )

142

particle effects

'

)
)
)

143

)
Edit particle effect )
! particle builder)

144

particle builder )


)
emmiter emmiter ) Emitter Graph )

Size X Life )

'

!
145

mount point )


) )
player.cs )( explode )
explode )

)function playerShip::explode(%this
{
;%this.isdead = true
;)%this.setEnabled(false
;)"%this.schedule(2000, "spawn
}
explode )

146

function playerShip::explode(%this)
{
%this.isdead = true;
%explosion = new t2dParticleEffect()
{
scenegraph = %this.scenegraph;
};
%explosion.loadEffect("~/data/particles/big_explosion.eff");
%explosion.setEffectLifeMode("KILL", 1);
%explosion.setPosition(%this.getPosition());
%explosion.playEffect();

%this.setEnabled(false);
%this.schedule(2000, "spawn");
{

explode

enemy.cs
)

function enemyShip::explode(%this)
{
%explosion = new t2dParticleEffect()
{
scenegraph = %this.scenegraph;
};
%explosion.loadEffect("~/data/particles/big_explosion.eff");
%explosion.setEffectLifeMode("KILL", 1);
%explosion.setPosition(%this.getPosition());
%explosion.playEffect();
147

;)(%this.spawn
}

)
)

)
edit Mounting )

148

149

You might also like