Also, a bit of help with the moving and collition detection? :(
http://www.freewebs.com/zuperxtreme/FLAS H%20TESTS/Single%20player%20overview.htm l
var moveMouseListener:Object = new Object();
speed = 1;
moving = false;
hit = false;
function onEnterFrame() {
moveLeader(leader);
//trace("Leader coords: X-"+leader._x+" | Y-"+leader._y);
//trace("waypoint coords: X-"+waypoint._x+" | Y-"+waypoint._y);
}
function moveLeader(MC) {
moveMouseListener.onMouseUp = function() {
_root.attachMovie("waypoint", "waypoint", 200, {_x:_xmouse, _y:_ymouse});
};
moveUnit(leader, waypoint);
if (checkForCollision(MC, room)) {
hit = true;
} else {
hit = false;
}
}
Mouse.addListener(moveMouseListener);
function moveUnit(MC, waypoint) {
Radians = Math.atan2(waypoint._y-MC._y, waypoint._x-MC._x);
Degrees = Math.round((Radians*180/Math.PI));
yChange = Math.round(waypoint._y-MC._y);
xChange = Math.round(waypoint._x-MC._x);
yMove = Math.round(yChange/20);
xMove = Math.round(xChange/20);
trace("Y: "+yMove+" X:"+xMove);
if (_root.hit) {
MC._y -= yMove;
MC._x -= xMove;
} else {
MC._y += yMove;
MC._x += xMove;
//MC._rotation = Degrees-90;
}
}
And this is the gskinner collision class I modified and used(if there are better ways, let me know, please):
import flash.display.BitmapData;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Rectangle;
function checkForCollision(p_clip1:MovieClip,p_clip2:MovieClip,p_alphaTolerance:Number):Rectangle {
// set up default params:
if (p_alphaTolerance == undefined) { p_alphaTolerance = 255; }
// get bounds:
var bounds1:Object = p_clip1.getBounds(_root);
var bounds2:Object = p_clip2.getBounds(_root);
// rule out anything that we know can't collide:
if (((bounds1.xMax < bounds2.xMin) || (bounds2.xMax < bounds1.xMin)) || ((bounds1.yMax < bounds2.yMin) || (bounds2.yMax < bounds1.yMin)) ) {
return null;
}
// determine test area boundaries:
var bounds:Object = {};
bounds.xMin = Math.max(bounds1.xMin,bounds2.xMin);
bounds.xMax = Math.min(bounds1.xMax,bounds2.xMax);
bounds.yMin = Math.max(bounds1.yMin,bounds2.yMin);
bounds.yMax = Math.min(bounds1.yMax,bounds2.yMax);
// set up the image to use:
var img:BitmapData = new BitmapData(bounds.xMax-bounds.xMin,bounds.yMax-bounds.yMin,false);
// draw in the first image:
var mat:Matrix = p_clip1.transform.concatenatedMatrix;
mat.tx -= bounds.xMin;
mat.ty -= bounds.yMin;
img.draw(p_clip1,mat, new ColorTransform(1,1,1,1,255,-255,-255,p_alphaTolerance));
// overlay the second image:
mat = p_clip2.transform.concatenatedMatrix;
mat.tx -= bounds.xMin;
mat.ty -= bounds.yMin;
img.draw(p_clip2,mat, new ColorTransform(1,1,1,1,255,255,255,p_alphaTolerance),"difference");
// find the intersection:
var intersection:Rectangle = img.getColorBoundsRect(0xFFFFFFFF,0xFF00FFFF);
// if there is no intersection, return null:
if (intersection.width == 0) { return null; }
// adjust the intersection to account for the bounds:
intersection.x += bounds.xMin;
intersection.y += bounds.yMin;
return intersection;
}