BAM5
06-28-2008, 10:21 AM
Alright so basically I have created a game. A crude one, but it still works... Kinda... I was hoping to learn a bit more about how flash runs through it's code for I obviously can't figure it out.
Here is my (perilous) code:
import fl.transitions.Tween;
import fl.transitions.easing.*;
stage.addEventListener(MouseEvent.MOUSE_MOVE, redrawCursor);
stage.addEventListener(MouseEvent.MOUSE_DOWN, charge);
stage.addEventListener(MouseEvent.MOUSE_UP, releaseCharge);
stage.addEventListener(KeyboardEvent.KEY_UP, reportKeyUp);
stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);
stage.addEventListener(Event.ENTER_FRAME, update);
_Ian.removeEventListener(MouseEvent.CLICK, chooseIan);
var ballTweenX :Tween = new Tween(ball, "x", Strong.easeIn, 0, Math.random() * 550, 10);
var ballTweenY :Tween = new Tween(ball, "y", Strong.easeIn, 0, Math.random() * 600, 10);
var w :Boolean = false;
var s :Boolean = false;
var a :Boolean = false;
var d :Boolean = false;
var number :Number = 1;
Mouse.hide();
var possesion:Boolean = false;
function redrawCursor(event:MouseEvent):void
{
CrossHairs.x = event.stageX;
CrossHairs.y = event.stageY;
four.text = "(" + Math.floor(event.stageX) + ", " + Math.floor(event.stageY) + ")";
}
function reportKeyUp(event:KeyboardEvent):void
{
switch (String.fromCharCode(event.charCode))
{
case "w":
w = false;
break;
case "s":
s = false;
break;
case "d":
d = false;
break;
case "a":
a = false;
break;
}
}
function reportKeyDown(event:KeyboardEvent):void
{
switch (String.fromCharCode(event.charCode))
{
case "w":
w = true;
break;
case "s":
s = true;
break;
case "d":
d = true;
break;
case "a":
a = true;
break;
}
}
function charge(event:MouseEvent):void
{
if (possesion)
{
CrossHairs.play();
}
}
function releaseCharge(event:MouseEvent):void
{
if (possesion)
{
possesion = false;
ballTweenX.duration = 37 - CrossHairs.currentFrame/3;
ballTweenY.duration = 37 - CrossHairs.currentFrame/3;
CrossHairs.gotoAndStop(1);
ballTweenX.begin = ball.x;
ballTweenX.finish = Math.floor(event.stageX);
ballTweenY.begin = ball.y;
ballTweenY.finish = Math.floor(event.stageY);
ballTweenY.start();
ballTweenX.start();
}
}
function update(event:Event):void
{
var rawrg :Number = 37 - CrossHairs.currentFrame/3;
five.text = (number ++).toString();
one.text = Math.floor(rawrg).toString();
two.text = "(" + Math.floor(ball.x) + ", " + Math.floor(ball.y) + ")";
three.text = "(" + Math.floor(_Ian.x) + ", " + Math.floor(_Ian.y) + ")";
if (_Ian.hitTestPoint(ball.x, ball.y))
{
possesion = true;
}
if (w)
{
_Ian.y -= 5;
_Ian.gotoAndStop(3);
if (possesion && !ballTweenX.isPlaying)
{
ball.x = _Ian.x + 68;
ball.y = _Ian.y + 48;
}
} else if (s)
{
_Ian.y += 5;
_Ian.gotoAndStop(4);
if (possesion && !ballTweenX.isPlaying)
{
ball.x = _Ian.x + 7;
ball.y = _Ian.y + 48;
}
}
if (d)
{
_Ian.x += 5;
_Ian.gotoAndStop(3);
if (possesion && !ballTweenX.isPlaying)
{
ball.x = _Ian.x + 68;
ball.y = _Ian.y + 48;
}
} else if (a)
{
_Ian.x -= 5;
_Ian.gotoAndStop(4);
if (possesion && !ballTweenX.isPlaying)
{
ball.x = _Ian.x + 7;
ball.y = _Ian.y + 48;
}
}
}
stop();
If you have read through it I congratulate and thank you.
Now the few things that I can't figure out are:
Why the ball stops short durring a tween.
Why the user regains possesion of the ball after it is thrown.
And that's about it.
If you wish for me to upload the swf or fla then please just say so.
(I'm going to bed now and hope there will be some answers in the morning :) )
Here is my (perilous) code:
import fl.transitions.Tween;
import fl.transitions.easing.*;
stage.addEventListener(MouseEvent.MOUSE_MOVE, redrawCursor);
stage.addEventListener(MouseEvent.MOUSE_DOWN, charge);
stage.addEventListener(MouseEvent.MOUSE_UP, releaseCharge);
stage.addEventListener(KeyboardEvent.KEY_UP, reportKeyUp);
stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);
stage.addEventListener(Event.ENTER_FRAME, update);
_Ian.removeEventListener(MouseEvent.CLICK, chooseIan);
var ballTweenX :Tween = new Tween(ball, "x", Strong.easeIn, 0, Math.random() * 550, 10);
var ballTweenY :Tween = new Tween(ball, "y", Strong.easeIn, 0, Math.random() * 600, 10);
var w :Boolean = false;
var s :Boolean = false;
var a :Boolean = false;
var d :Boolean = false;
var number :Number = 1;
Mouse.hide();
var possesion:Boolean = false;
function redrawCursor(event:MouseEvent):void
{
CrossHairs.x = event.stageX;
CrossHairs.y = event.stageY;
four.text = "(" + Math.floor(event.stageX) + ", " + Math.floor(event.stageY) + ")";
}
function reportKeyUp(event:KeyboardEvent):void
{
switch (String.fromCharCode(event.charCode))
{
case "w":
w = false;
break;
case "s":
s = false;
break;
case "d":
d = false;
break;
case "a":
a = false;
break;
}
}
function reportKeyDown(event:KeyboardEvent):void
{
switch (String.fromCharCode(event.charCode))
{
case "w":
w = true;
break;
case "s":
s = true;
break;
case "d":
d = true;
break;
case "a":
a = true;
break;
}
}
function charge(event:MouseEvent):void
{
if (possesion)
{
CrossHairs.play();
}
}
function releaseCharge(event:MouseEvent):void
{
if (possesion)
{
possesion = false;
ballTweenX.duration = 37 - CrossHairs.currentFrame/3;
ballTweenY.duration = 37 - CrossHairs.currentFrame/3;
CrossHairs.gotoAndStop(1);
ballTweenX.begin = ball.x;
ballTweenX.finish = Math.floor(event.stageX);
ballTweenY.begin = ball.y;
ballTweenY.finish = Math.floor(event.stageY);
ballTweenY.start();
ballTweenX.start();
}
}
function update(event:Event):void
{
var rawrg :Number = 37 - CrossHairs.currentFrame/3;
five.text = (number ++).toString();
one.text = Math.floor(rawrg).toString();
two.text = "(" + Math.floor(ball.x) + ", " + Math.floor(ball.y) + ")";
three.text = "(" + Math.floor(_Ian.x) + ", " + Math.floor(_Ian.y) + ")";
if (_Ian.hitTestPoint(ball.x, ball.y))
{
possesion = true;
}
if (w)
{
_Ian.y -= 5;
_Ian.gotoAndStop(3);
if (possesion && !ballTweenX.isPlaying)
{
ball.x = _Ian.x + 68;
ball.y = _Ian.y + 48;
}
} else if (s)
{
_Ian.y += 5;
_Ian.gotoAndStop(4);
if (possesion && !ballTweenX.isPlaying)
{
ball.x = _Ian.x + 7;
ball.y = _Ian.y + 48;
}
}
if (d)
{
_Ian.x += 5;
_Ian.gotoAndStop(3);
if (possesion && !ballTweenX.isPlaying)
{
ball.x = _Ian.x + 68;
ball.y = _Ian.y + 48;
}
} else if (a)
{
_Ian.x -= 5;
_Ian.gotoAndStop(4);
if (possesion && !ballTweenX.isPlaying)
{
ball.x = _Ian.x + 7;
ball.y = _Ian.y + 48;
}
}
}
stop();
If you have read through it I congratulate and thank you.
Now the few things that I can't figure out are:
Why the ball stops short durring a tween.
Why the user regains possesion of the ball after it is thrown.
And that's about it.
If you wish for me to upload the swf or fla then please just say so.
(I'm going to bed now and hope there will be some answers in the morning :) )