-1

So, as mentioned I'm doing some Flash this semester...I think I'd know how to do this in Python, with classes and all, but in AS3, everything is just so...detached.

I want to build a short chemistry game. You have 4 elements, fire, earth, wind and spirit, but the water is missing, the point is to make water. So you have on the stage, a fire_mc, a wind_mc, an earth_mc, a spirit_mc and the pot_mc. Clicking them adds a drop of them in the pot.

You have to put elements in there in a very specific order, but if you mess up, the count resets and you have to restart. The order is fire, spirit, earth, fire, spirit, wind. (very arbitrary at the moment, but let's say it's like that)

How would I make that in AS3?

(these tags are there to help people that want to build this specific kind of game)

This is my current code.

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

1 回答 1

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

            }
        }
    }

我希望这会有所帮助

于 2012-12-02T15:54:54.207 回答