I'm currently making a DDR flash game with action script 3. I can't figure out how to get a detection system to work when the scrolling arrow is in range of the static arrow at the top of the screen for points.
Here's what I have so far. Can anyone give me a hand?
[CODE]package
{
import flash.display.MovieClip;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;
import flash.events.MouseEvent;
public class ddrGame extends MovieClip
{
var vy:int;
var score:int;
var titleScreen:Title;
var leftArrow:ArrowLeft;
var rightArrow:ArrowRight;
var upArrow:ArrowUp;
var downArrow:ArrowDown;
var leftHole:ArrowLeftHole;
var rightHole:ArrowRightHole;
var upHole:ArrowUpHole;
var downHole:ArrowDownHole;
public function ddrGame()
{
titleScreen = new Title;
addChild(titleScreen);
//Moving Arrows
leftArrow = new ArrowLeft;
leftArrow.x = 55;
leftArrow.y = 500;
rightArrow = new ArrowRight;
rightArrow.x = 500;
rightArrow.y = 500;
upArrow = new ArrowUp;
upArrow.x = 350;
upArrow.y = 500;
downArrow = new ArrowDown;
downArrow.x = 200;
downArrow.y = 500;
//Stationary Arrow Holes
leftHole = new ArrowLeftHole;
addChild(leftHole);
leftHole.x = 55;
leftHole.y = 90;
leftHole.visible = false;
rightHole = new ArrowRightHole;
addChild(rightHole);
rightHole.x = 500;
rightHole.y = 90;
rightHole.visible = false;
upHole = new ArrowUpHole;
addChild(upHole);
upHole.x = 350;
upHole.y = 90;
upHole.visible = false;
downHole = new ArrowDownHole;
addChild(downHole);
downHole.x = 200;
downHole.y = 90;
downHole.visible = false;
vy = 3;
addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
titleScreen.startButton.addEventListener(MouseEvent.CLICK, onPlayButtonClick);
}
function onPlayButtonClick(event:MouseEvent):void
{
removeChild(titleScreen);
leftHole.visible = true;
rightHole.visible = true;
upHole.visible = true;
downHole.visible = true;
addChild(leftArrow);
//addChild(rightArrow);
//addChild(upArrow);
//addChild(downArrow);
}
private function onEnterFrame(event:Event):void
{
leftArrow.y -= vy;
rightArrow.y -= vy;
upArrow.y -= vy;
downArrow.y -= vy;
trace(leftArrow.y);
}
function onKeyDown(event:KeyboardEvent):void
{
if(leftArrow.y >= leftHole.y + 5 && event.keyCode == Keyboard.LEFT)
{
score++;
trace(score);
removeChild(leftArrow);
}
}
}
}[/CODE]
Doesn't anyone out there use Action script? I really can't figure this out.
try
[code]if(Math.abs(leftArrow.y-leftHole.y)<5 && event.keyCode == Keyboard.LEFT)
{
score++;
trace(score);
removeChild(leftArrow);
}[/code]
This is probably the best way to check if the arrows are within 5 units of the 'holes'. Although you might want to look at a different way to create arrows if you want infinite of them.
Add me on steam if you want a lecture on exactly how to do that.
I resolved the problem by fixing the if statement and also making the function not public. And yeah i know it won't work for an infinite amount of arrows. It was just a temporary test to make the detection work.
Sorry, you need to Log In to post a reply to this thread.