Some random attempts at programming the retro console
Fork of RETRO_Pong_Mod by
Diff: Game.cpp
- Revision:
- 4:84be90860d7c
- Parent:
- 3:2f09c90a732d
- Child:
- 5:8a26ad9d9ea1
diff -r 2f09c90a732d -r 84be90860d7c Game.cpp --- a/Game.cpp Thu Jan 15 12:48:21 2015 +0000 +++ b/Game.cpp Wed Feb 25 22:53:35 2015 +0000 @@ -102,8 +102,6 @@ void Game::initialize() { this->initializeBall(); - - this->paddleX = DisplayN18::WIDTH / 2 - Game::PADDLE_WIDTH / 2; this->pwmTicksLeft = 0; this->lives = 4; this->score = 0; @@ -118,32 +116,22 @@ void Game::initializeBall() { this->ballX = DisplayN18::WIDTH / 2 - Game::BALL_RADIUS; this->ballY = DisplayN18::HEIGHT / 4 - Game::BALL_RADIUS; - - this->ballSpeedX = Game::BALL_STARTING_SPEED; - this->ballSpeedY = Game::BALL_STARTING_SPEED; - - this->ballSpeedX *= (rand() % 2 ? 1 : -1); - this->ballSpeedY *= (rand() % 2 ? 1 : -1); + this->ballSpeedX = 3; + this->ballSpeedY = 5; + this->ballAccelX = 0; + this->ballAccelY = 0; } void Game::tick() { this->checkButtons(); if (this->mode) { - this->clearPaddle(); this->clearBall(); - - this->updatePaddle(); this->updateBall(); - this->checkCollision(); - - this->drawPaddle(); this->drawBall(); - this->checkPwm(); this->checkLives(); - wait_ms(25); } else { @@ -223,22 +211,6 @@ this->disp.clear(); } -void Game::clearPaddle() { - this->disp.fillRect(this->paddleX, DisplayN18::HEIGHT - Game::PADDLE_HEIGHT, Game::PADDLE_WIDTH, Game::PADDLE_HEIGHT, DisplayN18::BLACK); -} - -void Game::drawPaddle() { - this->disp.fillRect(this->paddleX, DisplayN18::HEIGHT - Game::PADDLE_HEIGHT, Game::PADDLE_WIDTH, Game::PADDLE_HEIGHT, DisplayN18::BLUE); -} - -void Game::updatePaddle() { - if (this->left.read()) - this->paddleX += Game::PADDLE_SPEED; - - if (this->right.read()) - this->paddleX -= Game::PADDLE_SPEED; -} - void Game::clearBall() { //this->disp.fillRect(this->ballX - Game::BALL_RADIUS, ballY - Game::BALL_RADIUS, Game::BALL_RADIUS * 2, Game::BALL_RADIUS * 2, DisplayN18::BLACK); //this->disp.fillCircle(this->ballX - Game::BALL_RADIUS, this->ballY - Game::BALL_RADIUS, Game::BALL_RADIUS, DisplayN18::BLACK); @@ -258,30 +230,25 @@ this->ballY += this->ballSpeedY; } -void Game::checkCollision() { - if (this->paddleX < 0) - this->paddleX = 0; - - if (this->paddleX + Game::PADDLE_WIDTH > DisplayN18::WIDTH) - this->paddleX = DisplayN18::WIDTH - Game::PADDLE_WIDTH; - - //if ((this->ballX - Game::BALL_RADIUS < 0 && this->ballSpeedX < 0) || (this->ballX + Game::BALL_RADIUS >= DisplayN18::WIDTH && this->ballSpeedX > 0)) { - if ((this->ballX - Game::BALL_RADIUS < 0 && this->ballSpeedX < 0) || (this->ballX + Game::BALL_RADIUS * 2 >= DisplayN18::WIDTH && this->ballSpeedX > 0)) { +void Game::checkCollision() { + // Does bounds checking first.. + if ((this->ballX - Game::BALL_RADIUS * 2 <= 0 && this->ballSpeedX < 0) || + (this->ballX + Game::BALL_RADIUS * 2 >= DisplayN18::WIDTH && this->ballSpeedX > 0)) { this->ballSpeedX *= -1; if(!this->muted) { this->pwm.period_ms(2); this->pwmTicksLeft = Game::BOUNCE_SOUND_TICKS; } } - - if (this->ballY - Game::BALL_RADIUS < (0 + DisplayN18::CHAR_HEIGHT) && this->ballSpeedY < 0){ + if ((this->ballY - Game::BALL_RADIUS * 2 <= 0 && this->ballSpeedY < 0) || + (this->ballY + Game::BALL_RADIUS * 2 >= DisplayN18::HEIGHT && this->ballSpeedY > 0)){ this->ballSpeedY *= -1; if(!this->muted) { this->pwm.period_ms(2); this->pwmTicksLeft = Game::BOUNCE_SOUND_TICKS; } } - +/* if (this->ballY + Game::BALL_RADIUS >= DisplayN18::HEIGHT - Game::PADDLE_HEIGHT && this->ballSpeedY > 0) { if (this->ballY + Game::BALL_RADIUS >= DisplayN18::HEIGHT) { this->initializeBall(); @@ -317,6 +284,7 @@ } } } +*/ char buf[10]; int a = this->score; sprintf(buf, "%d", a);