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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tutorial onClipEvent Question

Status
Not open for further replies.

ksbigfoot

Programmer
Apr 15, 2002
856
CA
I am trying to understand Collision detection from this code I downloaded. I have a player that moves through a maze.
The following code is placed on the maze movie clip.
I am wondering how to stop the player from moving after it hits the end movie clip when the user hits the arrow keys.
Code:
onClipEvent (enterFrame) {
	with (_root.player) {
		// Controls Player Speed
		mySpeed = 3;
		// Controls how far the Player bounces off the wall after impact 
		myBounce = 3;
		// keyboard controls
		if (Key.isDown(Key.DOWN)) {
				_y += mySpeed;
		}
		if (Key.isDown(Key.UP)) {
				_y -= mySpeed;
		}
		if (Key.isDown(Key.LEFT)) {
				_x -= mySpeed;
		}
		if (Key.isDown(Key.RIGHT)) {
				_x += mySpeed;
		}
		// detect if edges of the player is colliding with the Maze Walls 
		if (walls.hitTest(getBounds(_root).xMax, _y, true)) {
			_x -= myBounce;
		}
		if (walls.hitTest(getBounds(_root).xMin, _y, true)) {
			_x += myBounce;
		}
		if (walls.hitTest(_x, getBounds(_root).yMax, true)) {
			_y -= myBounce;
		}
		if (walls.hitTest(_x, getBounds(_root).yMin, true)) {
			_y += myBounce;
		}
		// detect if Maze is finished 
		if (_root.end.hitTest(_x, getBounds(_root).yMax, true)) {
			_root.gotoAndStop(3);
		}
	}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top