Actionscript 3 《捕手游戏生活》获胜';t更新为3.0
我正在尝试创建一个简单的捕手游戏。我已经弄清了基本结构/逻辑,但我面临一些问题。由于某些原因,生活没有像我希望的那样更新。只有当“好”的起重机从屏幕顶部离开时,它们才会真正工作,然后减少一个。但除此之外(抓一只“坏”起重机或抓一只“正”起重机)并没有减少或增加1。同样,分数似乎适用于“好”起重机,加上我指定的分数,但不适用于“坏”或“加”起重机 我错过了什么?救命啊Actionscript 3 《捕手游戏生活》获胜';t更新为3.0,actionscript-3,actionscript,Actionscript 3,Actionscript,我正在尝试创建一个简单的捕手游戏。我已经弄清了基本结构/逻辑,但我面临一些问题。由于某些原因,生活没有像我希望的那样更新。只有当“好”的起重机从屏幕顶部离开时,它们才会真正工作,然后减少一个。但除此之外(抓一只“坏”起重机或抓一只“正”起重机)并没有减少或增加1。同样,分数似乎适用于“好”起重机,加上我指定的分数,但不适用于“坏”或“加”起重机 我错过了什么?救命啊 package { import flash.display.*; import flash.event
package
{
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.utils.*;
public class CatchingCranes extends MovieClip
{
//Define the variables
var catcher:CloudCatcher;
var nextCrane:Timer;
var objects:Array = new Array();
var score:int = 0;
var timer:Number;
var maxCount:Number = 60;
var totalLives:int = 5;
var CirclesArray:Array = [];
var spacer:int = 5;
var startPosition:int = 415;
var speed:Number = -7.0;
public function CatchingCranes()
{
createTimer();
createCatcher();
setNextCrane();
progressLevels();
addEventListener(Event.ENTER_FRAME, moveCranes);
}
//Function to indicate level progression
public function progressLevels()
{
status_mc.status_txt.text = "LEVEL ONE";
status_mc.instructions_txt.text = "COLLECT AT LEAST 500 POINTS";
if (score == 500)
{
status_mc.status_txt.text = "LEVEL TWO";
status_mc.instructions_txt.text = "COLLECT AT LEAST 750 POINTS";
goToLevelTwo();
}
if (score == 750)
{
status_mc.status_txt.text = "LEVEL THREE";
status_mc.instructions_txt.text = "COLLECT AT LEAST 1000 POINTS";
goToLevelThree();
}
if (score == 1000)
{
status_mc.status_txt.text = "CONGRATULATIONS";
status_mc.instructions_txt.text = "YOU NOW HAVE ONE WISH TO MAKE";
goToWin();
}
if (totalLives == 0)
{
status_mc.status_txt.text = "GAME OVER";
status_mc.instructions_txt.text = "CLICK TO TRY AGAIN";
goToLoose();
}
}
//Function to create a timer
public function createTimer()
{
var myTimer:Timer = new Timer(1000,maxCount);
myTimer.addEventListener(TimerEvent.TIMER, countdown);
myTimer.start();
function countdown(event:TimerEvent):void
{
timer = (maxCount)-myTimer.currentCount;
timer_txt.text = "TIME LEFT: " + String(timer);
if (timer <= 0)
{
trace("Time's Up");
myTimer.removeEventListener(TimerEvent.TIMER, countdown);
}
}
}
//Function to create the catcher
public function createCatcher()
{
catcher = new CloudCatcher();
catcher.y = 50;
catcher.x = 350;
addChild(catcher);
}
//Function to initiate the next crane production
public function setNextCrane()
{
nextCrane = new Timer(750+Math.random()*1000,1);
nextCrane.addEventListener(TimerEvent.TIMER_COMPLETE, newCrane);
nextCrane.start();
}
//Function to create a new crane
public function newCrane(event:Event)
{
//Array definition holding different kinds of cranes
var goodCranes:Array = ["ColorCrane1","ColorCrane2","ColorCrane3","ColorCrane4","ColorCrane5"];
var evilCranes:Array = ["EvilCrane"];
var silverCranes:Array = ["SilverCrane"];
var goldCranes:Array = ["GoldCrane"];
//Create a random number and check whether or not it is less than 0.9 (90 percent probability)
if (Math.random() < 0.9)
{
//Create good cranes
var r:int = Math.floor(Math.random() * goodCranes.length);
var classRef:Class = getDefinitionByName(goodCranes[r]) as Class;
var newCrane:MovieClip = new classRef();
newCrane.typestr = "good";
}
else
{
//Create a random number and check whether or not it is more than 0.9 (10 percent probability)
//Check to see if the current lives count is less than or equal to four, if it is
if (totalLives <= 4)
{
//Create cranes that provide user with an additional life
var p:int = Math.floor(Math.random() * silverCranes.length);
classRef = getDefinitionByName(silverCranes[p]) as Class;
newCrane = new classRef();
newCrane.typstr = "plus";
//Create cranes that are evil
var s:int = Math.floor(Math.random() * evilCranes.length);
classRef = getDefinitionByName(evilCranes[s]) as Class;
newCrane = new classRef();
newCrane.typstr = "bad";
}
else
{
//If lives are equal to five, only create the evil cranes
r = Math.floor(Math.random() * evilCranes.length);
classRef = getDefinitionByName(evilCranes[r]) as Class;
newCrane = new classRef();
newCrane.typstr = "bad";
}
}
//Specify the x and y location of the cranes
newCrane.x = Math.random() * 700;
newCrane.y = 500;
//Add crane
addChildAt(newCrane, 0);
objects.push(newCrane);
setNextCrane();
}
//Function to move the cranes up the stage
public function moveCranes(event:Event)
{
for (var i:int = objects.length-1; i>=0; i--)
{
//Make the catcher follow the position of the mouse
catcher.x = mouseX;
//Specify the crane's speed
objects[i].y += speed;
//If the object exits the top stage boundaries
if (objects[i].y < 0)
{
//Remove the child and take it out of the array
removeChild(objects[i]);
objects.splice(i,1);
//If that object is good
if (objects[i].typestr == "good")
{
//Remove one life from the user
totalLives = totalLives - 1;
trace(totalLives);
}
}
//Check to see if the crane collides with the cloud, if it does
if (objects[i].hitTestObject(catcher))
{
//And the crane is good
if (objects[i].typestr == "good")
{
//Add 25 to the score
score += 25;
}
//And the crane adds a life
if (objects[i].typestr == "plus")
{
//Add 10 to the score and increase lives by one
score += 10;
totalLives = totalLives + 1;
}
//And the crane is evil
if (objects[i].typestr == "bad")
{
//Take out 5 from the score and remove a life
score -= 5;
totalLives = totalLives - 1;
}
//If the score is less than zero, take it back to zero
if (score < 0)
{
score = 0;
}
//Remove the cranes and splice them from the array
removeChild(objects[i]);
objects.splice(i,1);
}
}
//Update the score display text and the lives with the correct values
score_display.text = "Score = " + score;
lives_txt.text = "Lives: " + totalLives;
}
//Functions to specify next level options and win/loose scenarios
function goToLevelTwo():void
{
}
function goToLevelThree():void
{
}
function goToWin():void
{
}
function goToLoose():void
{
}
}
}
包
{
导入flash.display.*;
导入flash.events.*;
导入flash.text.*;
导入flash.utils。*;
公共类捕捉器扩展了MovieClip
{
//定义变量
var-catcher:CloudCatcher;
var-nextCrane:定时器;
变量对象:数组=新数组();
变量得分:int=0;
变量计时器:数字;
var maxCount:Number=60;
var总计:int=5;
var CirclesArray:Array=[];
变量间隔:int=5;
var起始位置:int=415;
变量速度:数字=-7.0;
公共功能捕捉起重机()
{
createTimer();
createCatcher();
setNextCrane();
进展水平();
addEventListener(Event.ENTER_FRAME,moveCranes);
}
//用于指示级别进程的函数
公共职能级别()
{
status_mc.status_txt.text=“一级”;
status_mc.instructions_txt.text=“收集至少500分”;
如果(分数=500)
{
status_mc.status_txt.text=“第二级”;
status_mc.instructions_txt.text=“收集至少750分”;
goToLevelTwo();
}
如果(分数=750)
{
status_mc.status_txt.text=“三级”;
status_mc.instructions_txt.text=“收集至少1000分”;
goToLevelThree();
}
如果(分数=1000)
{
status_mc.status_txt.text=“恭喜”;
status_mc.instructions_txt.text=“您现在有一个愿望”;
goToWin();
}
如果(总=0)
{
status\u mc.status\u txt.text=“游戏结束”;
status_mc.instructions_txt.text=“单击以重试”;
gotolose();
}
}
//函数创建计时器
公共函数createTimer()
{
var myTimer:Timer=新定时器(1000,最大计数);
myTimer.addEventListener(TimerEvent.TIMER,倒计时);
myTimer.start();
函数倒计时(事件:TimerEvent):无效
{
timer=(maxCount)-myTimer.currentCount;
timer_txt.text=“剩余时间:”+字符串(计时器);
if(timer)而不是依赖文本,说trace(totalives);当我跟踪totalives时,我只得到totalives的答案-1,当“好”起重机从顶部退出舞台时发生。其他任何东西都不会带来值。我还跟踪了newCrane.typestr,看看它是否识别出“坏”和“加”起重机,但它不会返回“未识别”,但它跟踪“好”,我认为if语句不足以捕捉冲突。我使用的最新版本Flash是MX,因此我对正确的语法有点生疏,但您应该考虑在捕捉器中添加一个用于碰撞/碰撞对象的eventlistener。如果它命中任何内容,请检查哪种类型的crane。