Object confusion
by Joe Banko · in Torque Game Builder · 02/18/2008 (7:11 pm) · 0 replies
I am TRYING to get 1 player sprite and 4 enemy sprites into a game. I've seen at least 6 different ways of doing it, none of which have worked. I thought I was beginning to understand but I feel really clueless. There are no compile errors. Can someone PLEASE help me with this concept. Where I'm at:
in game.cs:
...
...
...
function t2dSceneGraph::onUpdateScene(%this)
{
for (%i = 0; %i < EnemyGroup.getCount(); %i++)
{
playerClose(EnemyGroup.getObject(%i));
}
}
in enemy.cs
new SimGroup(EnemyGroup);
function enemyShip::onLevelLoaded(%this, %scenegraph)
{
%this.spawn(%scenegraph);
%this.spawn(%scenegraph);
%this.spawn(%scenegraph);
%this.spawn(%scenegraph);
}
...
...
...
function enemyShip::spawn(%that)
{
%this = new t2dStaticSprite()
{
scenegraph = %that;
};
%this.setImageMap(enemyImageMap);
%this.setLinearVelocityX(getRandom(%this.minSpeed, %this.maxSpeed));
%this.setPositionY(getRandom(-275,280));
%this.setPositionX(200);
EnemyGroup.add(%this);
}
...
...
...
function playerClose(%this)
{
%d = %this.getPositionY() - pShip.getPositionY();
if(%d < 20 && %d > -20)
{
$locY = "LOCKED";
if($fired == 0)
{
eShip.fireMissile(%this);
$fired = 1;
}
else
{
$fired = $fired + 1;
if($fired == 50)
{
$fired = 0;
$locY = " ";
}
}
}
else
{
$locY = " ";
}
}
TIA,
Joe B
in game.cs:
...
...
...
function t2dSceneGraph::onUpdateScene(%this)
{
for (%i = 0; %i < EnemyGroup.getCount(); %i++)
{
playerClose(EnemyGroup.getObject(%i));
}
}
in enemy.cs
new SimGroup(EnemyGroup);
function enemyShip::onLevelLoaded(%this, %scenegraph)
{
%this.spawn(%scenegraph);
%this.spawn(%scenegraph);
%this.spawn(%scenegraph);
%this.spawn(%scenegraph);
}
...
...
...
function enemyShip::spawn(%that)
{
%this = new t2dStaticSprite()
{
scenegraph = %that;
};
%this.setImageMap(enemyImageMap);
%this.setLinearVelocityX(getRandom(%this.minSpeed, %this.maxSpeed));
%this.setPositionY(getRandom(-275,280));
%this.setPositionX(200);
EnemyGroup.add(%this);
}
...
...
...
function playerClose(%this)
{
%d = %this.getPositionY() - pShip.getPositionY();
if(%d < 20 && %d > -20)
{
$locY = "LOCKED";
if($fired == 0)
{
eShip.fireMissile(%this);
$fired = 1;
}
else
{
$fired = $fired + 1;
if($fired == 50)
{
$fired = 0;
$locY = " ";
}
}
}
else
{
$locY = " ";
}
}
TIA,
Joe B
About the author