Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
BrickBreaker_Engine/BrickBreakerEngine.cpp
- Committer:
- JamesCummins
- Date:
- 2019-04-21
- Revision:
- 25:b52aa23df120
- Parent:
- 23:61fa82f76808
- Child:
- 26:0dc10374546f
File content as of revision 25:b52aa23df120:
#include "BrickBreakerEngine.h" #include <cmath> //Constructor BrickBreakerEngine::BrickBreakerEngine(){ } //Destructor BrickBreakerEngine::~BrickBreakerEngine(){ } //Initialiser void BrickBreakerEngine::init(int radius, Ball &ball){ _ball_radius = radius; ball.init(_ball_radius); srand(time(NULL)); _square_coord.x = 2 + rand()%80; _square_coord.y = 8 + rand()%36; } //Method for rendering void BrickBreakerEngine::brickbreaker_draw(N5110 &lcd, Ball &ball){ ball.draw(lcd); lcd.drawRect(_square_coord.x, _square_coord.y, 5, 5, FILL_BLACK); print_score(lcd); } /////////////Brickbreaker functionality///////////////////// void BrickBreakerEngine::set_score(int score){ _score = score; } void BrickBreakerEngine::generate_rand_square(AnalogIn &randnoise){ int rand = randnoise.read_u16(); Vector2D square_coords = {rand % 80, 8 + rand % 36}; _square_coord = square_coords; } void BrickBreakerEngine::check_square_collision(AnalogIn &randnoise, Ball &ball){ int radius = ball.get_radius(); Vector2D position = ball.get_position(); if (abs(position.x - (_square_coord.x + 2)) <= (radius + 2) and abs(position.y - (_square_coord.y + 2)) <= (radius + 2)) { _score++; generate_rand_square(randnoise); } } void BrickBreakerEngine::print_score(N5110 &lcd){ char buffer[2]; int score = _score; sprintf(buffer, "%d", score); lcd.printString(buffer, 72, 0); } void BrickBreakerEngine::check_high_score(SDFileSystem &sd){ sd.disk_read( }