Publish check : game completion 60%
DESCRIPTION The game: Squash Rally, is a 2-player game intended to be developed as a two-dimensional version of the racket-sport Squash.
- There is one racket on the screen that can be controlled by the joystick on the Gamepad - movement is restricted to the what would be the serving area on an actual squash court. The racket can move in all directions as dictated by the joystick.
- This is a "Rally" version of the game, so every hit on the ball by a racket is counted as one point to the player in play. The first player to score is always numbered as player 1 - the score will not start counting unless a point is scored by hitting the ball and increase in the player 1's score.
- Missing the ball (letting the ball go behind the serving wall) will not cause a penalty to the player score, but will cause a switch over to the opponent.
- This way, the first player to reach 11 points (rallies) will be the winner.
GAMEPLAY
- Press Start on the initial screen.
- Move the racket with the joystick and try to prevent the ball from hitting the right side of the screen (which translates to the out-of-bounds area in the game and defines "missing" a shot).
- Notice that every hit (rally) increases the player's score.
- If a player misses, the opponent player switches in.
- Once a player reaches 11 points in the game, an ending screen declares the winner.
- Press reset to play the game again repeat the entire sequence.
Diff: SquashLogic.h
- Revision:
- 0:0172de3db301
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SquashLogic.h Mon May 18 23:46:45 2020 +0000 @@ -0,0 +1,50 @@ +#ifndef SQUASHLOGIC_H +#define SQUASHLOGIC_H + +#include "mbed.h" +#include "N5110.h" +#include "Gamepad.h" +#include "Ball.h" +#include "Racket.h" + +// gap from edge of screen +#define GAP 2 + +class SquashLogic +{ + +public: + SquashLogic(); + ~SquashLogic(); + + void init(int racket_width,int racket_height,int ball_size,int speed); + void read_input(Gamepad &pad); + void update(Gamepad &pad); + void draw(N5110 &lcd); + +private: + + void check_wall_collision(Gamepad &pad); + void check_racket_collisions(Gamepad &pad); + void check_goal(Gamepad &pad); + void print_scores(N5110 &lcd); + + Racket _player; + + int _racket_width; + int _racket_height; + int _ball_size; + int _speed; + + // x positions of the paddles + int _p1x; + int _p1y; + + Ball _ball; + + Direction _d; + float _mag; + +}; + +#endif \ No newline at end of file