Game Development Community

WhackAMole respawning problem

by hamed · in Game Design and Creative Issues · 02/07/2012 (10:29 pm) · 1 replies

im using tgb 1.7.6 demo version and im reading the WhackAMole tutorial but ive found a problom in the second part of the tutorial and my moles just vanish and dont spawn again in any whole, ive checked everything in level builder and im sure that whole the things are right,and these are my script files
can anybody tell me that why my moles dont spawn?
main.cs
//---------------------------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------


/// Player Initialization Procedure
///
function onStart()
{
}

function onExit()
{
}

//---------------------------------------------------------------------------------------------
// Load the paths we need access to
//---------------------------------------------------------------------------------------------
function loadPath( %path )
{
setModPaths( getModPaths() @ ";" @ %path );
exec(%path @ "/main.cs");

}

//---------------------------------------------
// Do some bootstrap voodoo to get the game to
// the initializeProject phase of loading and
// pass off to the user
//---------------------------------------------

// Output a console log
setLogMode(6);

loadPath( "common" );

loadPath( "game" );

onStart();

// Initialized
echo("nTorque Game Builder (" @ getT2DVersion() @ ") initialized...");

if( !isFunction( "initializeProject" ) || !isFunction( "_initializeProject" ) )
{
messageBox( "Game Startup Error", "'initializeProject' function could not be found." @
"nThis could indicate a bad or corrupt common directory for your game." @
"nnThe Game will now shutdown because it cannot properly function", "Ok", "MIStop" );
quit();
}

_initializeProject();

// Startup the project
initializeProject();


game.cs
//---------------------------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------
// startGame
// All game logic should be set up here. This will be called by the level builder when you
// select "Run Game" or by the startup process of your game to load the first level.
//---------------------------------------------------------------------------------------------
function startGame(%level)
{
exec("./mole.cs");
exec("./respawnPoint.cs");
exec("./moleLevel.cs");
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);

new ActionMap(moveMap);
moveMap.push();

$enableDirectInput = true;
activateDirectInput();
enableJoystick();
sceneWindow2D.setUseObjectMouseEvents( true );

sceneWindow2D.loadLevel(%level);
}

//---------------------------------------------------------------------------------------------
// endGame
// Game cleanup should be done here.
//---------------------------------------------------------------------------------------------
function endGame()
{
sceneWindow2D.endLevel();
moveMap.pop();
moveMap.delete();
}
datablocks.cs
datablock t2dSceneObjectDatablock( respawnPointDatablock )
{
class = "respawnPoint"; // the class that will be associated with the object
layer = 5; // the render layer
size = "16 16"; // the size of the object
};
respawnpoint.cs
function respawnPoint::onLevelLoaded(%this, %level)
{
%level.respawnPointSet.add(%this);
}


function respawnPoint::onLevelEnded(%this, %level)
{
if( isObject( %level.respawnPointSet ) )
%level.respawnPointSet.remove(%this);
}
molelevel.cs
function moleLevel::onLevelLoaded(%this)
{
%this.respawnPointSet = new SimSet();
}


function moleLevel::onLevelEnded(%this)
{
%this.respawnPointSet.delete();
}
function moleLevel::spawnMole(%this)
{
// find a spawn point
%respawnPointIndex = getRandom( %this.respawnPointSet.getCount()-1 );
%respawnPoint = %this.respawnPointSet.getObject( %respawnPointIndex );

// select a color for the mole
%color = getRandom(2);
if( %color == 0 )
%color = "red";
if( %color == 1 )
%color = "green";
if( %color == 2 )
%color = "lilac";


// create a new Mole
%mole = new t2dAnimatedSprite()
{
sceneGraph = %this;
class = "mole";
layer = 4;
size = "9 16";
};

// play right animation according to the color
%mole.playAnimation("animMoleComeOut" @ %color);


// save the selected color as dynamic field
%mole.moleColor = %color;

// set the position of the mole to the position
// of the respawn point
%mole.setPosition( %respawnPoint.getPosition() );
mole.cs
function mole::onAdd(%this)
{
// enable mouse events for the mole so we can easily determine when it is clicked on
%this.setUseMouseEvents( true );
}
function mole::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
if( %this.getAnimationName() $= ("animMoleComeOut" @ %this.moleColor) )
%this.playAnimation( "animMoleWhacked" @ %this.moleColor );
}
function mole::onAnimationEnd(%this)
{
if( %this.getAnimationName() !$= ("animMoleComeOut" @ %this.moleColor) )
{
// after deleting the old mole schedule a respawn
// >%this.sceneGraph< is the level
%this.sceneGraph.schedule( 1500, "spawnMole");
%this.safeDelete();
}
}

About the author

the great costly games, but the only purpose is killing, and the only amuse but why we just should kill to be satisfied,why the games should not change ? great drama in the games ? maybe today , is the time to change from bullets to flowers


#1
02/08/2012 (2:04 am)
i found my problem in the last line of molelevel.cs after
%mole.setPosition( %respawnPoint.getPosition() );
i had forgotten to write "}"