Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

collision detection - adding additional targets 1

Status
Not open for further replies.

Flashoid

Technical User
Dec 11, 2002
163
US
I'd like to add more targets so when a walking character walks into them (collides) it would load a new unique movie or goto a new scene for each. For this game you have a guy you can control with your arrow keys and you can walk into (collide) with a helicopter. I just want to
add additional collision targets, which upon colliding would load a new movie or go to a new scene. I've attached the existing code below:

The walking guy movieclip is labeled Soldier. The helicopter movieclip is labeled heli. This currently only has the ability to load one new movie.


THIS IS IN FRAME 1:

// variable init
hitside = "off";
speed = 4;

// get some values for the x and y position of the soldier


xpos = getProperty(soldier, _x);
ypos = getProperty(soldier, _y);
xpos_right = getProperty(soldier, _x)+(getProperty(soldier, _width)/2);
xpos_left = getProperty(soldier, _x)-(getProperty(soldier, _width)/2);
xpos_top = getProperty(soldier, _y)-(getProperty(soldier, _height)/2);
xpos_bottom = getProperty(soldier, _y)+(getProperty(soldier, _height)/2);

// just for the ending animation

if (heli.hitTest(xpos_left, xpos_bottom, true)) {
soldier._visible = 0;
soldier._x = 0;
soldier._y = 0;
moveup = "true";
}

if (moveup == "true")
{
loadMovieNum ("NEWMOVIE.swf", 1);

{
end = "true";
moveup = "false";
}
}

if (end == "true")
{
soldier._visible = 0;

{
end = "false";
heli._visible = 0;
gotoAndStop(3);
}
}

// check for any hit on the side of the maze movie clip

if (maze.hitTest(xpos_right, xpos_bottom, true)) {
hitside = "off";
} else {
hitside = "on";
soldier._x = oldx;
soldier._y = oldy;
}

if (maze.hitTest(xpos_right, xpos_top, true)) {
hitside = "off";
} else {
hitside = "on";
soldier._x = oldx;
soldier._y = oldy;
}

if (maze.hitTest(xpos_left, xpos_bottom, true)) {
hitside = "off";
} else {
hitside = "on";
soldier._x = oldx;
soldier._y = oldy;
}

if (maze.hitTest(xpos_left, xpos_top, true)) {
hitside = "off";
} else {
hitside = "on";
soldier._x = oldx;
soldier._y = oldy;
}


// check for key press ...

if ((Key.isDown(Key.LEFT) && Key.isDown(Key.UP)) || (Key.isDown(Key.LEFT) && Key.isDown(Key.DOWN))) {
hitside = "on";
}

if ((Key.isDown(Key.RIGHT) && Key.isDown(Key.UP)) || (Key.isDown(Key.RIGHT) && Key.isDown(Key.DOWN))) {
hitside = "on";
}

if (!Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.UP) && !Key.isDown(Key.DOWN)) {
_root.soldier.man.stop();
} else {
_root.soldier.man.play();
}

if (Key.isDown(Key.LEFT) && hitside == "off") {
oldx = soldier._x;
oldy = soldier._y;
soldier._x -= speed;
_root.soldier.gotoAndStop("left");
}

if (Key.isDown(Key.RIGHT) && hitside == "off") {
oldx = soldier._x;
oldy = soldier._y;
soldier._x += speed;
_root.soldier.gotoAndStop("right");
}

if (Key.isDown(Key.UP) && hitside == "off") {
oldx = soldier._x;
oldy = soldier._y;
soldier._y -= speed;
_root.soldier.gotoAndStop("bottom");
}

if (Key.isDown(Key.DOWN) && hitside == "off") {
oldx = soldier._x;
oldy = soldier._y;
soldier._y += speed;
_root.soldier.gotoAndStop("top");
}



THIS IS IN FRAME 2:

// reinit the hit

if ( hitside == "on")
{
hitside = "off";
}



gotoAndPlay (1);


THIS IS IN FRAME 3:

stop();


That is it. I want to add additional collision targets so when you collide with each one it loads a new unique movie.

Thanks!!!


 
That was it!!!!!!!!!!!! Thanks!!!!!!!!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top