在Flash中制作化学游戏的最佳思维流程



所以,如前所述,我这学期正在做一些Flash......我想我会知道如何在 Python 中做到这一点,有类和所有,但在 AS3 中,一切都是如此......超然。

我想做一个简短的化学游戏。你有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();
}

我会这样做。所以你有 4 个元素。为它们中的每一个制作一个按钮/影片剪辑(当您单击其中一个时,锅里装满了它),这就是您必须处理的动画。但是要检查组合是否正确,请使用此代码

    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");
            }
        }
    }

我希望这有所帮助

最新更新