Hello Kirupans,
The hitTests I have are to detect collisions to alter the score.
What if I wanted to go to a specific frame in the MovieClip that the user is hitting?
Here is the code I have, any ideas?
(thanks in advance)
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
public class maze02 extends MovieClip {
//collision codes - correct multiples
private static const pointsForRight_16:int = 10;
private static const pointsForRight_32:int = 10;
private static const pointsForRight_48:int = 10;
private static const pointsForRight_56:int = 10;
private static const pointsForRight_72:int = 10;
private static const pointsForRight_96:int = 10;
//collision codes - bonus points
private static const pointsForBonusBananaR:int = 25;
private static const pointsForBonusOrange:int = 25;
private static const pointsForBonusBananaL:int = 25;
private static const pointsForBonusStrawberry:int = 25;
private static const pointsForBonusApple:int = 25;
//(collision) lose Life code
private static const pointsForLoseLife_14:int = -1;
private static const pointsForLoseLife_68:int = -1;
private static const pointsForLoseLife_75:int = -1;
private static const pointsForLoseLife_90:int = -1;
//score & life tallies
private var gameScore:int;
private var lifeCount:int;
//arrow variables
var leftArrow:Boolean = false;
var rightArrow:Boolean = false;
var upArrow:Boolean = false;
var downArrow:Boolean = false;
//the Mazoonist's MAZE code
var speed:Number = 10;
var padding:int = 10;//to space the bee away from the maze walls
public function maze02 () {
//score count starts at 0
gameScore = 0;
// count based on lives remaining
lifeCount = 3;
//listen for the user's keyboard Use
stage.addEventListener (KeyboardEvent.KEY_DOWN, keyPressedDown);
stage.addEventListener (KeyboardEvent.KEY_UP, keyPressedUp);
stage.addEventListener (Event.ENTER_FRAME, moveBee);
}
//user controls Bee with KeyBoard (arrows)
function keyPressedDown (event:KeyboardEvent) {
if (event.keyCode == 37) {
leftArrow = true;
} else if (event.keyCode == 39) {
rightArrow = true;
} else if (event.keyCode == 38) {
upArrow = true;
} else if (event.keyCode == 40) {
downArrow = true;
}
}
function keyPressedUp (event:KeyboardEvent) {
if (event.keyCode == 37) {
leftArrow = false;
} else if (event.keyCode == 39) {
rightArrow = false;
} else if (event.keyCode == 38) {
upArrow = false;
} else if (event.keyCode == 40) {
downArrow = false;
}
}
// Mazoonist MAZE code (2)
function moveBee (event:Event) {
if (rightArrow) {
for (var i:int = 0; i < speed; i++) {
if (this.maze.hitTestPoint(this.playerBee.x + i + padding, this.playerBee.y, true)) {
break;
} else {
this.playerBee.x++;
}
}
}
if (leftArrow) {
for (var j:int = 0; j < speed; j++) {
if (this.maze.hitTestPoint(this.playerBee.x - j - padding, this.playerBee.y, true)) {
break;
} else {
this.playerBee.x--;
}
}
}
if (upArrow) {
for (var k:int = 0; k < speed; k++) {
if (this.maze.hitTestPoint(this.playerBee.x, this.playerBee.y - k - padding, true)) {
break;
} else {
this.playerBee.y--;
}
}
}
if (downArrow) {
for (var m:int = 0; m < speed; m++) {
if (this.maze.hitTestPoint(this.playerBee.x, this.playerBee.y + m + padding, true)) {
break;
} else {
this.playerBee.y++;
}
}
}
//here's where to check for the Collision
checkCollisionRight ("Right_16");
checkCollisionRight ("Right_96");
}
//set up score function
public function showGameScore () {
gameScoreField.text = gameScore.toString();
}
//show how many lives are left
public function showLifeCount () {
lifeCountField.text = lifeCount.toString();
}
//good collisions add to the score
public function checkCollisionRight (mcname:String) {
if (this.getChildByName(mcname.toLowerCase()) != null) {
// if Bee collides with the Good Number
if (this.playerBee.hitTestObject(this.getChildByName(mcname.toLowerCase()))) {
gameScore += maze02["pointsFor" + mcname];
showGameScore ();
}
}
}
}
}