Craig Evans
/
ELEC2645_Pong2021
Pong game for ELEC1620 board.
Embed:
(wiki syntax)
Show/hide line numbers
Paddle.cpp
00001 #include "Paddle.h" 00002 00003 // nothing doing in the constructor and destructor 00004 Paddle::Paddle() { } 00005 00006 void Paddle::init(int x,int height,int width) { 00007 printf("Paddle: Init\n"); 00008 _x = x; // x value on screen is fixed 00009 _y = HEIGHT/2 - height/2; // y depends on height of screen and height of paddle 00010 _height = height; 00011 _width = width; 00012 _speed = 1; // default speed 00013 _score = 0; // start score from zero 00014 } 00015 00016 void Paddle::draw(N5110 &lcd) { 00017 printf("Paddle: Draw\n"); 00018 lcd.drawRect(_x,_y,_width,_height,FILL_BLACK); 00019 } 00020 00021 void Paddle::update(UserInput input) { 00022 printf("Paddle: Update\n"); 00023 _speed = 2; 00024 // update y value depending on direction of movement 00025 // North is decrement as origin is at the top-left so decreasing moves up 00026 if (input.d == N) { _y-=_speed; } 00027 else if (input.d == S) { _y+=_speed; } 00028 00029 // check the y origin to ensure that the paddle doesn't go off screen 00030 if (_y < 1) { _y = 1; } 00031 if (_y > HEIGHT - _height - 1) { _y = HEIGHT - _height - 1; } 00032 } 00033 00034 void Paddle::add_score() { _score++; } 00035 00036 int Paddle::get_score() { return _score; } 00037 00038 Position2D Paddle::get_pos() { return {_x,_y}; } 00039 00040 int Paddle::get_height() { return _height; } 00041 00042 int Paddle::get_width() { return _width; }
Generated on Thu Jul 14 2022 15:46:36 by 1.7.2