所以,正如我提到的那样,我这个学期正在做一些Flash ...我想我已经知道如何在Python中使用类和所有这些,但在AS3中,一切都是如此...分离。< / p>
我想建立一个简短的化学游戏。你有4个元素,火,土,风和精神,但缺水,重点是制造水。所以你在舞台上有一个fire_mc,一个wind_mc,一个earth_mc,一个spirit_mc和一个pot_mc。点击它们会在锅中添加一滴它们。
你必须以非常特定的顺序放置元素,但如果你陷入困境,计数会重置,你必须重新开始。命令是火,精神,土,火,精神,风。 (目前非常随意,但让我们说它就像那样)
我如何在AS3中制作?
(这些标签可以帮助那些想要构建这种特定类型游戏的人)
这是我目前的代码。
stop();
lvln.text="Phase 3 - Bargaining";
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.events.Event;
const WIDTH:int=50;
const HEIGHT:int=50;
const SEPX:int=50;
var fireb:firebtn=new firebtn();
var spiritb:spiritbtn=new spiritbtn();
var earthb:earthbtn=new earthbtn();
var windb:windbtn=new windbtn();
var combo:Array=new Array();
var truecombo:Array=[fireb,spiritb,spiritb,windb,earthb];
var lastElm=combo[combo.length-1];
firebb.addEventListener(MouseEvent.CLICK, fire1);
windbb.addEventListener(MouseEvent.CLICK, wind1);
earthbb.addEventListener(MouseEvent.CLICK, earth1);
spiritbb.addEventListener(MouseEvent.CLICK, spirit1);
function add1(clip:DisplayObject)
{
if (combo.length > 6)
{
combo.shift();
combo.push(clip);
reorder();
}
}
function reorder()
{
for(var i:int = 0; i < combo.length; i++)
{
combo[i].x = i * 50;
}
}
function fire1(e:MouseEvent)
{
lastX+=SEPX;
twist.gotoAndPlay(2);
var fireb:firebtn=new firebtn();
stage.addChild(fireb);
add1(fireb);
fireb.width=WIDTH;
fireb.height=HEIGHT;
fireb.x=lastX;
fireb.y=lastY;
pop.play();
}
function wind1(e:MouseEvent)
{
lastX+=SEPX;
twist.gotoAndPlay(2);
var windb:windbtn=new windbtn();
stage.addChild(windb);
add1(fireb);
windb.width=WIDTH;
windb.height=HEIGHT;
windb.x=lastX;
windb.y=lastY;
pop.play();
}
function earth1(e:MouseEvent)
{
lastX+=SEPX;
twist.gotoAndPlay(2);
var earthb:earthbtn=new earthbtn();
stage.addChild(earthb);
add1(fireb);
earthb.width=WIDTH;
earthb.height=HEIGHT;
earthb.x=lastX;
earthb.y=lastY;
pop.play();
}
function spirit1(e:MouseEvent)
{
lastX+=SEPX;
twist.gotoAndPlay(2);
var spiritb:spiritbtn=new spiritbtn();
stage.addChild(spiritb);
combo.push(spiritb);
spiritb.width=WIDTH;
spiritb.height=HEIGHT;
spiritb.x=lastX;
spiritb.y=lastY;
pop.play();
}
答案 0 :(得分:0)
我会这样做。 所以你有4个元素。为每个人制作一个按钮/ MovieClip(当你点击其中一个时,用它填充它)这就是你必须处理的动画。但要检查组合是否正确,请使用此代码
import flash.events.MouseEvent;
import flash.events.Event;
var combination:Array=new Array(); //Array that loads elements being clicked
var clength:Number = 0; // combination length for making water
var truecombination:Array=new Array(); // Array that holds combination for making water
truecombination.push("fire"); //first element
truecombination.push("wind"); //second element
truecombination.push("spirit"); //third element
truecombination.push("fire"); //fourth element
truecombination.push("wind"); // fifth element
truecombination.push("earth"); //sixt element(you can go for more elements in your combination but remember to change the clength variable)
//adding event listeners for elemnt buttons
fire_mc.addEventListener(MouseEvent.CLICK, fclick);
wind_mc.addEventListener(MouseEvent.CLICK, wclick);
spirit_mc.addEventListener(MouseEvent.CLICK, sclick);
earth_mc.addEventListener(MouseEvent.CLICK, eclick);
//you can also add animation labels to the functions below to make the game more interesting
function fclick(e:MouseEvent):void
{
combination.push("fire");
clength+=1;
}
function wclick(e:MouseEvent):void
{
combination.push("wind");
clength+=1;
}
function sclick(e:MouseEvent):void
{
combination.push("spirit");
clength+=1;
}
function eclick(e:MouseEvent):void
{
combination.push("earth");
clength+=1;
}
addEventListener(Event.ENTER_FRAME,loop);//making a loop function that checks the combination
function loop(e:Event):void
{
if (truecombination.length => 6) //waiting for player to enter his combination
{
if (combination[clength-6] == "fire" && combination[clength-5] == "wind" && combination[clength-4] == "spirit" && combination[clength-3] == "fire" && combination[clength-2] == "wind" && combination[clength-1] == "earth") //checking if combination is true
{
trace("You Won");
}
else // and if it is not true...
{
//trace("You Lose");
}
}
}
我希望有帮助