Game designed for project

Dependencies:   mbed Gamepad2

Committer:
vaib
Date:
Tue May 19 09:51:13 2020 +0000
Revision:
2:e67ca889c81b
The game I planned to make is based heavily on the game Breakout. The main elements of the game include the paddle at the bottom of the screen a ball and blocks that need to be destroyed. I am currently creating a class for the paddle

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vaib 2:e67ca889c81b 1
vaib 2:e67ca889c81b 2 #include "PaddleControl.h"
vaib 2:e67ca889c81b 3
vaib 2:e67ca889c81b 4
vaib 2:e67ca889c81b 5 void Paddle::init(int y,int length,int height)
vaib 2:e67ca889c81b 6 {
vaib 2:e67ca889c81b 7 _y = y; // x value on screen is fixed
vaib 2:e67ca889c81b 8 _x = WIDTH/2 - length/2; // y depends on height of screen and height of paddle
vaib 2:e67ca889c81b 9 _height = height;
vaib 2:e67ca889c81b 10 _length = length;
vaib 2:e67ca889c81b 11 _speed = 1; // default speed
vaib 2:e67ca889c81b 12 }
vaib 2:e67ca889c81b 13
vaib 2:e67ca889c81b 14 void Paddle::print_lcd(N5110 &lcd)
vaib 2:e67ca889c81b 15 {
vaib 2:e67ca889c81b 16 lcd.drawRect(_x,_y,_width,_height,FILL_BLACK);
vaib 2:e67ca889c81b 17 }
vaib 2:e67ca889c81b 18
vaib 2:e67ca889c81b 19 void Paddle::update(char direction)
vaib 2:e67ca889c81b 20 {
vaib 2:e67ca889c81b 21 if (direction == 'R') {
vaib 2:e67ca889c81b 22 _x-=_speed;
vaib 2:e67ca889c81b 23 } else if (direction == 'L') {
vaib 2:e67ca889c81b 24 _x+=_speed;
vaib 2:e67ca889c81b 25 }
vaib 2:e67ca889c81b 26
vaib 2:e67ca889c81b 27 if (_x < 1) {
vaib 2:e67ca889c81b 28 _x = 1;
vaib 2:e67ca889c81b 29 }
vaib 2:e67ca889c81b 30 if (_x > WIDTH - _length - 1) {
vaib 2:e67ca889c81b 31 _x = WIDTH - _length - 1;
vaib 2:e67ca889c81b 32 }
vaib 2:e67ca889c81b 33 }
vaib 2:e67ca889c81b 34
vaib 2:e67ca889c81b 35 Vector2D Paddle::get_pos() {
vaib 2:e67ca889c81b 36 Vector2D p = {_x,_y};
vaib 2:e67ca889c81b 37 return p;
vaib 2:e67ca889c81b 38 }