lundi 21 décembre 2015

How to generate multiple random-spawning scrolling objects in Action Script 3?

I'm making a game for a school project where you jump over objects and collect others. I'm doing this all in the timeline so the .swf file is the only thing that needs to be turned in.

Here is the current code; the last part, 'spawning things' is where I got lost.

import flash.events.Event;
import flash.events.KeyboardEvent;

stop();



//intro screen
play_btn.addEventListener(MouseEvent.CLICK, clickAway);
function clickAway(event:MouseEvent):void
{
    introScreen.visible = false;
    play_btn.visible = false;
}

//jump
var grav:Number = 8;
var jumping:Boolean = false;
var jumpPow:Number = 0;

stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(Event.ENTER_FRAME, update);

function onKeyDown(evt:KeyboardEvent):void
{
    if(evt.keyCode == Keyboard.UP)
    {
        if(jumping != true)
        {
            jumpPow = -50;
            jumping = true;
        }

    }   
}


function update(evt:Event):void
{
    if(jumping)
    {
        okami_mc.y += jumpPow;
        jumpPow += grav;

        if(okami_mc.y >=300)
        {
            jumping = false;
            okami_mc.y =300;
        }

    }
} 


//make the background move
stage.addEventListener(Event.ENTER_FRAME, repeat);
function repeat(thing:Event):void
{
    treebg_mc.x -=  13;

    if (treebg_mc.x < -100)
    {
        treebg_mc.x = 1000;
    }

    sun_mc.x -= 5;
    if (sun_mc.x < -100)
    {
        sun_mc.x = 700;
    }
}

//spawning things
bdemon_mc.addEventListener(Event.ENTER_FRAME, bscrollMove);
function bscrollMove(event:Event):void
{
    if (bdemon_mc.x>=-100){
        bdemon_mc.x -=10;
    }else{
        bdemon_mc.x=600;
    }
}

Aucun commentaire:

Enregistrer un commentaire