|
|
Flash dodge ball game part 5 the ballIn this tutorial we will make an enemy for our small dodge ball game, so we will be making a ball, that bounces on the walls and kills our character when it touches him. 1. In the properties panel name it ball, so we can refere to it later in code. 2. onClipEvent (load) { first of we make it create to variables when the flash movie is loaded, xspeed and yspeed they are going to be a random number between 5 + 11. then in the onclipevent (this event is raised repeatly) what this will do is to tell flash to move this._x and this._y (our ball) to its original posistion + the x,y speed variables. try to test your movie now and you should see that the ball is moving, but we have one problem, it moves out of the stage, so we need to change its direction when it hits a wall, luckly we made walls in part 4. 3. So in the onClipEvent(enterFrame) type the following. if (hitTest(_root.right_wall)==true) What this does it to repeatly check if the ball is touctching the right wall, and if it does then change the x direction via xspeed /= -1; test the movie and see what happens when the ball hits the right wall. Now here is the code for all the walls -------------------------------------- } 4. if (hitTest(_root.joe)==true) Now test the movie. Tip: you could change the x_ and _y to some random positions for the ball when it hits our charector. if (hitTest(_root.joe)==true) Part 1 Part 2 Part 3 Part 4 Part 5 Part 6 Part 7 |




