How do I add multiple items to a hitTestObject?
I have a horizontally scrolling flying game involving a character and diferent types of food moving across the screen from right to left which the character has to collect ("hit"). I have the hitTestObject working for 2 different food movieclips with one item belonging to a healthyList, and the other to a junkList.
The problem is I don't know how to add more items (movieclips) to each of the lists, so that I have for example 6 items in the healthyList and 4 items in the junkList.
Below is the code in my Engine.as file. The red highlighted text is the code that creates the problem. I thought that I just needed to add this line in order to add another item to the "healthyList" of food types, but I obviously have it in the wrong place or have the wrong code completely.
package
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
public class Engine extends MovieClip
{
private var numClouds:int = 5;
private var healthyList:Array = new Array();
private var junkList:Array = new Array();
private var myFlying:Flying;
public function Engine()
{
myFlying = new Flying(stage);
stage.addChild(myFlying);
myFlying.x = stage.stageWidth / 8;
myFlying.y = stage.stageHeight / 2;
for (var i:int = 0; i < numClouds; i++)
{
stage.addChildAt(new Cloud(stage), stage.getChildIndex(myFlying));
}
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
private function loop(e:Event) : void
{
if (Math.floor(Math.random() * 90) == 5)
{
var healthy:Carrot = new Carrot(stage, myFlying);
var healthy:Broccoli = new Broccoli(stage, myFlying);
healthy.addEventListener(Event.REMOVED_FROM_STAGE, removeHealthy, false, 0, true);
healthyList.push(healthy);
stage.addChild(healthy);
var junk:Hotdog = new Hotdog(stage, myFlying);
junk.addEventListener(Event.REMOVED_FROM_STAGE, removeJunk, false, 0, true);
junkList.push(junk);
stage.addChild(junk);
}
}
private function removeHealthy(e:Event)
{
healthyList.splice(healthyList.indexOf(e.currentTarget), 1);
}
private function removeJunk(e:Event)
{
junkList.splice(junkList.indexOf(e.currentTarget), 1);
}
}
}
All help and advice very much appreciated.
Thank you!