Im making a game that has a character mode when it eats a certain object. Kind of like in pacman when you eat the bigger ball that turns you blue and lets you eat the ghost for the short time period.
My game has a mode where when a player eats a certain object they can try and eat their opponent in 10 seconds. Ive been able to dodgely make the player change form when eating the object, the object dissapearing from the stage, a timer starting and once eaten the other player being removed from stage and a few more interactions (not good at as3). Some how i made it so the player can eat the object and then turn on the mode but not be able to eat their oppponent and it wont turn off OR straight away eat their opponent, change form and turn the timer on but not turn it off?
Any help with what ive done wrong would be greatly appreciated! code below
package {
import flash.display.MovieClip;
import flash.events.*;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class main extends MovieClip
{
public var playerName:int;
public var playerState:Number = 1;
var player1;
var player2;
var theZombieBall;
public var zombietimer:Timer = new Timer (1000,10);
public function main() {
// constructor code
//defines player and zombie mode
var playerNumber:int =1
this.playerName = playerNumber;
this.gotoAndStop(playerState);
player1 = new player(50,384, 1);
player2 = new player(944,384,2);
stage.addChild(player1);
stage.addChild(player2);
stage.addEventListener(Event.ENTER_FRAME, checkForCollision);
zombietimer.addEventListener(TimerEvent.TIMER,timerHandler);
}
public function timerHandler(event:TimerEvent):void
{
timertext.text = 11- zombietimer.currentCount+"";
if (zombietimer.currentCount <1){
//player2.gotoAndStop (1);
player1.playerState = 1;
player1.gotoAndStop (2);
}
}
//public function addBall
public function checkForCollision(e:Event): void
{
//this function checks to see if theZombieBall has collided with a player
if(theZombieBall.hitTestObject(player1) || player1.hitTestObject(player2))
{
//removes thebadball from the stage
trace("a player has eaten the zombie ball");
stage.removeChild(theZombieBall);
// change player to zombieplayer
if (player1.playerState==1)
{
player1.playerState = 2;
}
else
{
player1.playerState = 1;
}
player1.gotoAndStop (2);
//makes player larger
player1.width = player1.width *2;
player1.height = player1.height * 2;
zombietimer.start();
}
//this function checks to see if theZombieBall has collided with a player
if(theZombieBall.hitTestObject(player2))
{
//removes thebadball from the stage
trace("a player has eaten the zombie ball");
stage.removeChild(theZombieBall);
// change player to zombieplayer
if (player2.playerState==1)
{
player2.playerState = 2;
}
else
{
player2.playerState = 1;
}
player2.gotoAndStop (2);
//makes player larger
player2.width = player2.width *2;
player2.height = player2.height * 2;
zombietimer.start();
}
//this function checks to see if player in zombie mode has collided with a normal player
if(player1.hitTestObject(player2))
{
//removes player1 from stage from the stage
trace("a player has eaten another player");
stage.removeChild(player1);
// change player to normal player
if (player2.playerState==2)
{
player2.playerState = 1;
}
else
{
player2.playerState = 2;
}
player2.gotoAndStop (1);
//makes player larger
player2.width = player2.width *2;
player2.height = player2.height * 2;
//removes timer from stage
stage.removeChild(timertext);
}
}
}
}
Probably u didnt stop ur timer when player1 hit's player2(or eat). When u stop the timer DONT forget about reseting timer items like timer counter ect.
if(player1.hitTestObject(player2)) {
//removes player1 from stage from the stage
trace("a player has eaten another player");
stage.removeChild(player1);
// change player to normal player
if (player2.playerState==2)
{
player2.playerState = 1;
}
else
{
player2.playerState = 2;
}
player2.gotoAndStop (1);
//makes player larger
player2.width = player2.width *2;
player2.height = player2.height * 2;
//removes timer from stage
stage.removeChild(timertext);
zombietimer.start();
///also reset zombietimer items
}
Hope this would help :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.