|
||||||
|
||||||
Flash Tutorial - Collision Detection

Free
Tutorial
Step Five: Creating the Maze
Note: If your Maze drawing is going to very complex I suggest you only draw a small section of the Maze to start with. You can come back and add to the drawing latter. If the walls are too thin or the path (where your blue dot moves) is too narrow you may find that the Player goes straight through the walls. The thicker the Walls and the wider the Paths the faster you can make your Player move so try not to make the walls too thin.
Note: This creates a series of nested Movie Clips one inside another. The Walls Movie Clip is inside the Maze Movie Clip. The Maze Movie Clip is on the Main Stage:
![]()
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);
}
}
}
|
Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates
•
96714 visitors to this page since
Jan 04 •
|
|
|
All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.
|