i have done a rough class diagram, will be using c++.
// this class will contain all game logic
- level: int // for determine speed of game and width of paddle
- blockmap: int // 2-d array to keep track of the block
- ball:Ball // class Ball contains location and states of ball
-paddle: Paddle // contains state and location of Paddle
+checkCollision(): bool // check for collision
+ updateBall():void // function to update direction of moving ball after collision
// will be using a shrunken rect to represent round ball
-shrunkenX:double // coord of top left corner of shrunken rect
-shrunkenY:double // in pixel
-x: double // coord of top left corner of rect that contain
-y:double // ball
-angle: double // angle(rad) is use to keep track of direction that
// ball is moving
-y:double // coord of paddle in pixel
-width:int // width of paddle determined by level
Please tell me i am going in the right direction. It seems most logical to use 2d array to represent the blocks.
I believe i wont have problem checking for the rect overlap. However, I am not too sure how should i determine the deflection.
The attribute angle in class Ball is the angle displacement from y-axis. Suppose an collision occur, i just increment the angle displacement by 90 degrees. Does it sound right?