I have a vision of a game I would love to create but I'm new to Actionscript 3, and I have been working my way through an online tutorial, trying to use the code given and adapt it to a game I am working on, which kind of has similarities, but now I'm completely stuck. (I've probably bitten off more than I can chew, but I don't want to give up on my game idea)

The online tutorial is for creating a vertically scrolling shooting game where you control a Space ship and you shoot at enemy ships which fall vertically downwards randomly.

The hitTestObject on the online game is between bullets shot from your ship and the enemy ship itself.

My game is a horizontal scrolling scene where the user controls a flying superhero, which starts at the left, and items move across the screen from right to left towards the superhero and you have to collect ("hit") certain items. My hit test is to be between the superhero himself and these moving items. He doesn't fire anything.

Here's a screenshot of MY game (not the online tutorial game):

This is the section of the tutorial that I am stuck on, as my game does not involve anything "shooting" anything, rather just a character that hits objects, no weapons. And the online tutorial uses the weapon's bullets for doing the hitTestObject, so I don't know how to use the code on my superhero as opposed to "bullets".

The thing you could show would be the code that is giving you a headache. In general, if there is only one hero and many objects to hit him, have each of the objects do its own hitTestObject against the hero as they move.

Thanks Ned. I understand that I need to do a hitTestObject for each object against the superhero, but I just don't know what code I need to do a hitTestObject and where to put, that's the problem. Here are the 2 sets of code below. First one is for the Superhero Character, and the second piece of code is for the Carrot object that I want the Superhero to be able to hit in order to collect points.

1. This is the code for the superhero character. File name is Flying.as

package

{

import flash.display.MovieClip;

import flash.display.Stage;

import com.senocular.utils.KeyObject;

import flash.ui.Keyboard;

import flash.events.Event;

public class Flying extends MovieClip

{

private var stageRef:Stage;

private var key:KeyObject;

private var speed:Number = 0.5;

private var vx:Number = 0;

private var vy:Number = 0;

private var friction:Number = 0.93;

private var maxspeed:Number = 10;

public function Flying(stageRef:Stage)

{

this.stageRef = stageRef;

key = new KeyObject(stageRef);

addEventListener(Event.ENTER_FRAME, loop, false, 0, true);

}

public function loop(e:Event) : void

{

//keypresses

if (key.isDown(Keyboard.LEFT))

vx -= speed;

else if (key.isDown(Keyboard.RIGHT))

vx += speed;

else vx *= friction;

if (key.isDown(Keyboard.UP))

vy -= speed;

else if (key.isDown(Keyboard.DOWN))

vy += speed;

else vy *=friction;

//update position

x += vx;

y += vy;

//speed adjustment

if (vx > maxspeed)

vx = maxspeed;

else if (vx < -maxspeed)

vx = -maxspeed;

if (vy > maxspeed)

vy = maxspeed;

else if (vy < -maxspeed)

vy = -maxspeed;

//speed appearance

rotation = vx;

//stay inside screen

if (x > stageRef.stageWidth)

{

x = stageRef.stageWidth;

vx = -vx;

}

else if (x < 0)

{

x = 0;

vx = -vx;

}

if (y > stageRef.stageHeight)

{

y = stageRef.stageHeight;

vy = -vy;

}

else if (y < 0)

{

y = 0;

vy = -vy;

}

}

}

}

2. And this is the code for the carrot object which I want to be able to be hit by the Superhero character. File name is Carrot.as