Sunday, 30 August 2015

Week 5 Prac B

In todays prac, we learnt to make the game "Pong" by following the step by step instruction.
First in the main class, its basically the controller, its the middle platform for communicating with the view and model. In main class, I created two players and the ball to the stage. I also add eventListenter for the player to move up and down.
After that, i created another class called player. In this class, I set the player's height and width as Players will be represented in rectangle. After setting the rectangle, there is a draw function that draws player so that they able to display on the stage. In order to track where the player move to, I also created functions setY and getY. In the game "Pong", players are only allowed to move up and down so it only requires to track Y position.

I also needed a class to control the ball. In that class, the ball will always starts in the middle so i had to set the starting position. Next, the ball has to move and the speed will get faster and faster. Therefore, i had to set a original timer and add the speed. Then, the ball has to bounce back when player hit it so, i created a function checkForBounce().

After this practical, i leant the basic structure of how to make a game. Main is the controller where it control and communicates with View and Model. View is the stage, its game interface where users sees. Model has logic of the game. A game will be divided in elements, like "Pong" there is player and ball. And each element has its own class. The class will basically control how this particular element works, what does it do etc.


No comments:

Post a Comment