total reframe with classes

This commit is contained in:
andrea
2026-03-17 23:25:30 +01:00
parent d8efabd6da
commit 3d8881ab3d
14 changed files with 246 additions and 319 deletions

View File

@@ -1,51 +1,46 @@
#include <Arduino.h>
#include <stdint.h>
#include "config.h"
#include "ball.h"
class Ball {
void Ball::_init_directions(int8_t &_direction) {
if (random(2) == 0) _direction= 1;
else _direction= -1;
}
private:
void Ball::move() {
if (!_direction_x) this -> _init_directions(_direction_x);
if (!_direction_y) this -> _init_directions(_direction_y);
uint8_t _x, _y;
int8_t _direction_x, _direction_y;
// if (_x < 0 || _x > MATRIX_WIDTH-1 || _y < 0 || _y > MATRIX_HEIGHT-1) {
// this -> reset_position();
// }
void _init_directions(int8_t &_direction) {
if (random(2) == 0) _direction= 1;
else _direction= -1;
}
if (_x + _direction_x >= 0 && _x + _direction_x < MATRIX_WIDTH)
_x+= _direction_x;
if (_y + _direction_y >= 0 && _y + _direction_y < MATRIX_HEIGHT)
_y+= _direction_y;
}
public:
void Ball::bounce_on_pad() {
_direction_x *= -1;
}
void move() {
if (!_direction_x) _init_directions(_direction_x);
if (!_direction_y) _init_directions(_direction_y);
void Ball::bounce_on_sides() {
_direction_y *= -1;
}
if (_x + _direction_x >= 0 && _x + _direction_x < MATRIX_WIDTH)
_x+= _direction_x;
if (_y + _direction_y >= 0 && _y + _direction_y < MATRIX_HEIGHT)
_y+= _direction_y;
}
void Ball::reset_position () {
_x= BALL_RESET_X;
_y= BALL_RESET_Y;
this -> _init_directions(_direction_x);
this -> _init_directions(_direction_y);
}
void bounce_on_pad() {
_direction_x *= -1;
}
uint8_t Ball::get_x() {
return _x;
}
void bounce_on_sides() {
_direction_y *= -1;
}
void reset_position () {
_x= BALL_RESET_X;
_y= BALL_RESET_Y;
_init_directions(_direction_x);
_init_directions(_direction_y);
}
uint8_t get_x() {
return _x;
}
uint8_t get_y() {
return _y;
}
};
uint8_t Ball::get_y() {
return _y;
}