Loops
by Anthony Ratcliffe · in Torque Game Builder · 01/21/2008 (12:06 pm) · 1 replies
Hey, wondered if you can help me I've created a small duck hunt style game where you shoot and it increases the score counter by one. How ever i wish to add difficulty to it and after say 5 kills 2 ducks appear on screen.In c# i know it would usally me like this
if ( duck > 5)
{
%spawn // adds one more spawning to the game
}
else
{
//usal game code seen below
}
so after 5 shoots the loop increases the amount of spawns I'm guessing i add one to the loop ever time a duck is hit in the %spawn function but im not sure about the loop my code is below that runs the whole game.
Any help apperciated
function duck::onLevelLoaded(%this)
{
%this.hitcount = 0;
%this.missedcount = 0;
}
function duck::onWorldLimit(%this, %mode, %limit)
{
switch$ (%limit)
{
case "left":
%this.setLinearVelocityX(20);//(getRandom(%this.minSpeed, %this.maxSpeed));
%this.setFlipX(false);
echo ("hello") ;
case "right":
%this.setLinearVelocityX(-20);//(getRandom(%this.minSpeed, %this.maxSpeed));
%this.setFlipX(true);
echo ("hellnkjkjo") ;
case "bottom":
%this.spawn();
}
}
function duck::spawn(%this)
{
%this.setPosition (getRandom(-48, 50), %this.startPositionx);
%this.setPosition (getRandom(-38, 35), %this.startPositionY);
%this.setLinearVelocityx(getRandom(%this.minSpeed, %this.maxSpeed));
%this.setLinearVelocityY(-10);
echo ("guitest"@guiscore.text);
guihit.text = %this.hitcount++ ;
}
function duck::onMouseDown( %this, %modifier, %worldPos, %mouseClicks )
{
%this.setLinearVelocityY(20);
guiclick.text = %this.missedcount++ ;
}
if ( duck > 5)
{
%spawn // adds one more spawning to the game
}
else
{
//usal game code seen below
}
so after 5 shoots the loop increases the amount of spawns I'm guessing i add one to the loop ever time a duck is hit in the %spawn function but im not sure about the loop my code is below that runs the whole game.
Any help apperciated
function duck::onLevelLoaded(%this)
{
%this.hitcount = 0;
%this.missedcount = 0;
}
function duck::onWorldLimit(%this, %mode, %limit)
{
switch$ (%limit)
{
case "left":
%this.setLinearVelocityX(20);//(getRandom(%this.minSpeed, %this.maxSpeed));
%this.setFlipX(false);
echo ("hello") ;
case "right":
%this.setLinearVelocityX(-20);//(getRandom(%this.minSpeed, %this.maxSpeed));
%this.setFlipX(true);
echo ("hellnkjkjo") ;
case "bottom":
%this.spawn();
}
}
function duck::spawn(%this)
{
%this.setPosition (getRandom(-48, 50), %this.startPositionx);
%this.setPosition (getRandom(-38, 35), %this.startPositionY);
%this.setLinearVelocityx(getRandom(%this.minSpeed, %this.maxSpeed));
%this.setLinearVelocityY(-10);
echo ("guitest"@guiscore.text);
guihit.text = %this.hitcount++ ;
}
function duck::onMouseDown( %this, %modifier, %worldPos, %mouseClicks )
{
%this.setLinearVelocityY(20);
guiclick.text = %this.missedcount++ ;
}
About the author
Torque Owner Glenn Prince
function duck::onUpdate(%this)
{
if ( duck > 5)
{
%spawn // adds one more spawning to the game
}
}
That way it checks on every tick to see wether there is enough ducks on the screen