Oh man Oh man!! I have a report due in the morning!!! please assist!!
by Chris Faraji · in Torque Game Builder · 03/16/2010 (9:06 pm) · 3 replies
Below is the Player.cs
function Player::onLevelLoaded(%this, %scenegraph)
{
//GLOBAL for player
$Player = %this;
//CONTROLS
moveMap.bindCmd(keyboard, "right", "PlayerRight();", "PlayerRightStop();");
moveMap.bindCmd(keyboard, "left", "PlayerLeft();", "PlayerLeftStop();");
moveMap.bindCmd(keyboard, "space", "PlayerBoost();", "PlayerBoostStop();");
%this.lowerLife();
}
//MOVE, and STOP
function PlayerRight()
{
$Player.moveRight = true;
$Player.updateMovement();
}
function PlayerLeft()
{
$Player.moveLeft = true;
$Player.updateMovement();
}
function PlayerBoost()
{
if(%Player.dead)
return;
%flipX = $Player.getFlipX();
if(!%flipX)
{
%hSpeed = -$Player.hSpeed * 2;
$Player.playAnimation(PrinnyFly1);
} else
{
%hSpeed = $Player.hSpeed * 2;
$Player.playAnimation(PrinnyFly1);
}
$Player.setLinearVelocityX(%hSpeed);
}
//--------------------------------------
function PlayerLeftStop()
{
$Player.moveLeft = false;
$Player.playAnimation(PrinnyIdle1);
$Player.updateMovement();
}
function PlayerRightStop()
{
$Player.moveRight = false;
$Player.playAnimation(PrinnyIdle1);
$Player.updateMovement();
}
function PlayerBoostStop()
{
$Player.setLinearVelocityX(0);
$Player.playAnimation(PrinnyIdle1);
}
//-----UPDATE----
function Player::updateMovement(%this)
{
if(%this.dead)
{
setScenePause(true)
}
if(%this.moveLeft)
{
$Player.playAnimation(PrinnyWalk1);
$Player.setLinearVelocityX(-$Player.hSpeed);
$Player.setFlipX(false);
}
if(%this.moveRight)
{
$Player.playAnimation(PrinnyWalk1);
$Player.setLinearVelocityX($Player.hSpeed);
$Player.setFlipX(true);
}
if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX(0);
}
}
//-----LIFE-----
function Player::modifyLife(%this, %dmg)
{
%this.life += %dmg;
if(%this.life > 100)
{
%this.life = 100;
}else if (%this.life < 0)
{
%this.life = 0;
}
if(%this.life <= 0)
{
%this.dead();
}
}
function Player::dead(%this)
{
%this.dead = true;
}
then the MINE.cs
function Mine::onLevelLoaded(%this, %scenegraph)
{
%this.startPosition = %this.getPositionY();
%this.setLinearVelocityY(getRandom(%this.minSpeed, %this.maxSpeed));
}
function Mine::onWorldLimit(%this, %mode, %limit)
{
if(%limit $= "bottom")
{
%this.spawn();
}
}
function Mine::spawn(%this)
{
%this.setPosition(getRandom(-50, 50), %this.startPosition);
%this.setLinearVelocityY(getRandom(%this.minSpeed, %this.maxSpeed));
}
function Mine::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
if(%dstObj.class $= "Player")
{
%srcObj.spawn();
%dstObj.modifyLife(%srcObj.lifeValue);
}
}
it wont kill me!!!
function Player::onLevelLoaded(%this, %scenegraph)
{
//GLOBAL for player
$Player = %this;
//CONTROLS
moveMap.bindCmd(keyboard, "right", "PlayerRight();", "PlayerRightStop();");
moveMap.bindCmd(keyboard, "left", "PlayerLeft();", "PlayerLeftStop();");
moveMap.bindCmd(keyboard, "space", "PlayerBoost();", "PlayerBoostStop();");
%this.lowerLife();
}
//MOVE, and STOP
function PlayerRight()
{
$Player.moveRight = true;
$Player.updateMovement();
}
function PlayerLeft()
{
$Player.moveLeft = true;
$Player.updateMovement();
}
function PlayerBoost()
{
if(%Player.dead)
return;
%flipX = $Player.getFlipX();
if(!%flipX)
{
%hSpeed = -$Player.hSpeed * 2;
$Player.playAnimation(PrinnyFly1);
} else
{
%hSpeed = $Player.hSpeed * 2;
$Player.playAnimation(PrinnyFly1);
}
$Player.setLinearVelocityX(%hSpeed);
}
//--------------------------------------
function PlayerLeftStop()
{
$Player.moveLeft = false;
$Player.playAnimation(PrinnyIdle1);
$Player.updateMovement();
}
function PlayerRightStop()
{
$Player.moveRight = false;
$Player.playAnimation(PrinnyIdle1);
$Player.updateMovement();
}
function PlayerBoostStop()
{
$Player.setLinearVelocityX(0);
$Player.playAnimation(PrinnyIdle1);
}
//-----UPDATE----
function Player::updateMovement(%this)
{
if(%this.dead)
{
setScenePause(true)
}
if(%this.moveLeft)
{
$Player.playAnimation(PrinnyWalk1);
$Player.setLinearVelocityX(-$Player.hSpeed);
$Player.setFlipX(false);
}
if(%this.moveRight)
{
$Player.playAnimation(PrinnyWalk1);
$Player.setLinearVelocityX($Player.hSpeed);
$Player.setFlipX(true);
}
if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX(0);
}
}
//-----LIFE-----
function Player::modifyLife(%this, %dmg)
{
%this.life += %dmg;
if(%this.life > 100)
{
%this.life = 100;
}else if (%this.life < 0)
{
%this.life = 0;
}
if(%this.life <= 0)
{
%this.dead();
}
}
function Player::dead(%this)
{
%this.dead = true;
}
then the MINE.cs
function Mine::onLevelLoaded(%this, %scenegraph)
{
%this.startPosition = %this.getPositionY();
%this.setLinearVelocityY(getRandom(%this.minSpeed, %this.maxSpeed));
}
function Mine::onWorldLimit(%this, %mode, %limit)
{
if(%limit $= "bottom")
{
%this.spawn();
}
}
function Mine::spawn(%this)
{
%this.setPosition(getRandom(-50, 50), %this.startPosition);
%this.setLinearVelocityY(getRandom(%this.minSpeed, %this.maxSpeed));
}
function Mine::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
if(%dstObj.class $= "Player")
{
%srcObj.spawn();
%dstObj.modifyLife(%srcObj.lifeValue);
}
}
it wont kill me!!!
About the author
College student in Game Programming, hoping to make it somewhere. I have some great ideas, and want to try and show the world what I've got.
#2
currently, I am making it safedelete my character. However I wanted it to respawn but it isnt working GAH lol
due at 1:15pm EST idk what imma do T-T
03/17/2010 (6:31 am)
I changed everything AGAIN haha...currently, I am making it safedelete my character. However I wanted it to respawn but it isnt working GAH lol
due at 1:15pm EST idk what imma do T-T
#3
You have to remember the player doesn't care if you delete your objects or simply disable them. You simply provide a believable illusion that they have died and need to be respawned according the rules of the world you've created.
03/17/2010 (11:52 am)
Well, a bit late for your deadline - but why delete the character at all? All you have to do is disable the character so it is not visible and does not interact with the rest of the scene, disable any player input actions, move it to the respawn position, and re-enable everything.You have to remember the player doesn't care if you delete your objects or simply disable them. You simply provide a believable illusion that they have died and need to be respawned according the rules of the world you've created.
Associate William Lee Sims
Machine Code Games
Just off the bat I have two things for you.
You call a function called "lowerLife" that I don't see implemented anywhere. If you look at the console, you'll see error messages that will tell you when you have mistakes like this.
Finally, you should just add echo-statements to your program to make sure that functions are being called. As a quick example:
function Mine::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts) { echo( "In Mine::onCollision" ); echo( " %dstObj.class = " @ %dstObj.class ); echo( " %srcObj.lifeValue = " @ %srcObj.lifeValue ); if( %dstObj.class $= "Player" ) { %srcObj.spawn(); %dstObj.modifyLife( %srcObj.lifeValue ); } }This will tell you if the collision function is getting called and if the values are coming in as you expected.