Flash dodge ball game part 4 make walls
In this tutorial we will make walls around the game so eighter our character or any other object can get out of the stage if we don't want to.
1.
So start by making some graphic, drag 4 rectangles on the stage as in the image below, then right click them seperatly and convert them to movie clips.
2.
Now name them bottom_wall, top_wall, right_wall and left_wall so we can refere to them later on in code.
3.
Now we will use the hittest function to work so our character joe cant go through the walls.
Click joe and go to the actionscript panel.
in the onClipEvent (enterFrame) {
make some room for coding, and type in the following
if (hitTest(_root.bottom_wall)==true)
{
_y=_root.bottom_wall._y - _root.joe._height
}
Now what this does is to repeatly test if joe is crossing over the bottom wall we made just before, if it does touch the wall then, we give joe a new posision, in the y axis (_y) we give it the posistion of the bottom wall + the height of the joe movie clip, so it will get placed just above the bottom wall.
4.
Now we have to repeat this for the left, right and top walls, I'm not going to make a description for them all, because its kind of the same as above, but here is the code.
//wall boundaries START
if (hitTest(_root.bottom_wall)==true)
{
_y=_root.bottom_wall._y - _root.joe._height
}
if (hitTest(_root.top_wall)==true)
{
_y=_root.top_wall._y + 16 // 16 is just the width of the wall
}
if (hitTest(_root.left_wall)==true)
{
_x=_root.left_wall._x + 20 // 20 is just the width of the wall
}
if (hitTest(_root.right_wall)==true)
{
_x=_root.right_wall._x - _root.joe._width
}
//wall boundareis END
Now you can test your game, you should not be able to move the joe character out the the stage.
Part 1
Part 2
Part 3
Part 4
Part 5
Part 6
Part 7