Fri 28 Apr 2006
Curse you, Flash!
Why solve simple problems, when you can be stumped by hard ones? I appear to have out-clevered myself for the moment. I’m not finding any good way to test for collsions against the arbitrary line movie_clip I’m drawing as a trail.
I’ll paste the code after the jump, if anyone wants to take a peek. Perhaps a good night’s sleep will bring council.
Nothing shocking:
The green ball is Player_1_mc, the green line is Line_mc
// Base Contruction for Multiplayer Line Blocking Game
Player_1_mc.gotoAndStop(10);
JUNK = 0;
badGoalSound = new Sound();
badGoalSound.attachSound("badGoal");
createEmptyMovieClip("Line_mc",1);
Line_mc.lineStyle(10,0×00FF00,100);
p1_X_Dir = 0;
p1_Y_Dir = -1;
p1_Speed = 3;
p1_X = 243;
p1_Y =590;
topSpeed = 10;
lowSpeed = 1;
baseScale=30;
Line_mc.moveTo(p1_X, p1_Y);
this.onEnterFrame = function() {
// Player_1 Keyboard Input
if (Key.isDown(Key.RIGHT)) {
if(p1_X_Dir != -1){
p1_X_Dir = 1;
p1_Y_Dir = 0;
if(p1_Speed < topSpeed){
p1_Speed += .5;
}
}
else {
if(p1_Speed > lowSpeed){
p1_Speed -= .5;
}
}
}
if (Key.isDown(Key.LEFT)) {
if(p1_X_Dir != 1){
p1_X_Dir = -1;
p1_Y_Dir = 0;
if(p1_Speed < topSpeed){
p1_Speed += .5;
}
}
else {
if(p1_Speed > lowSpeed){
p1_Speed -= .5;
}
}
}
if (Key.isDown(Key.UP)) {
if(p1_Y_Dir != 1) {
p1_X_Dir = 0;
p1_Y_Dir = -1;
if(p1_Speed < topSpeed){
p1_Speed += .5
}
}
else {
if(p1_Speed > lowSpeed){
p1_Speed -= .5
}
}
}
if (Key.isDown(Key.DOWN)) {
if(p1_Y_Dir != -1) {
p1_X_Dir = 0;
p1_Y_Dir = 1;
if(p1_Speed < topSpeed){
p1_Speed += .5;
}
}
else {
if(p1_Speed > lowSpeed){
p1_Speed -= .5;
}
}
}
// Update Player_1 Location
p1_X = p1_X + (p1_Speed * p1_X_Dir);
p1_Y = p1_Y + (p1_Speed * p1_Y_Dir);
// Place Player 1
temp_X = p1_X + (25 * p1_X_Dir);
temp_Y = p1_Y + (25 * p1_Y_Dir);
_root.Player_1_mc._x = temp_X;
_root.Player_1_mc._y = temp_Y;
_root.Player_1_mc._xscale = baseScale+(p1_Speed*11);
_root.Player_1_mc._yscale = baseScale+(p1_Speed*11);
JUNK += 1;
// Player 1 Collision Detection
// detect if edges of the player is colliding with the Maze Walls
if (_root.Player_1_mc.hitTest(getBounds(_root.Line_mc).xMax, _y, true)) {
trace("Hit xMax "+JUNK);
_root.badGoalSound.start(0,1);
}
if (_root.Player_1_mc.hitTest(getBounds(_root.Line_mc).xMin, _y, true)) {
trace("Hit xMin "+JUNK);
_root.badGoalSound.start(0,1);
}
if (_root.Player_1_mc.hitTest(_x, getBounds(_root.Line_mc).yMax, true)) {
trace("Hit yMax "+JUNK);
_root.badGoalSound.start(0,1);
}
if (_root.Player_1_mc.hitTest(_x, getBounds(_root.Line_mc).yMin, true)) {
trace("Hit yMin "+JUNK);
_root.badGoalSound.start(0,1);
}
// Draw the Line
Line_mc.lineTo(p1_X, p1_Y);
}





















