mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-04-26 17:54:42 +00:00
render fix
This commit is contained in:
parent
8a80d0d29b
commit
58c4c7db90
@ -33,14 +33,10 @@ void Head::render(){
|
||||
time = QDateTime::currentMSecsSinceEpoch();
|
||||
}
|
||||
|
||||
double Head::getSpeed() const {
|
||||
return *speed;
|
||||
}
|
||||
|
||||
Head::Head(double *spead) {
|
||||
this->speed = spead;
|
||||
}
|
||||
|
||||
Head::~Head() {
|
||||
|
||||
|
||||
}
|
||||
|
@ -23,14 +23,13 @@ public:
|
||||
|
||||
double getX() const;
|
||||
void setX(double x);
|
||||
|
||||
double getSpeed() const;
|
||||
void setSpeed(double *value);
|
||||
|
||||
void render();
|
||||
|
||||
~Head();
|
||||
|
||||
bool getIsHead() const;
|
||||
void setIsHead(bool value);
|
||||
};
|
||||
|
||||
#endif // HEAD_H
|
||||
|
@ -2,30 +2,41 @@
|
||||
|
||||
|
||||
Snake::Snake() :
|
||||
_speed(SPEEDSNAKE){
|
||||
speed(SPEEDSNAKE){
|
||||
}
|
||||
|
||||
const QVector<Head *> &Snake::getItems() const {
|
||||
return _items;
|
||||
return items;
|
||||
}
|
||||
|
||||
void Snake::render() {
|
||||
// зздесь должна быть реализация рендера змейки
|
||||
// for (auto i : _items) {
|
||||
// i->render();
|
||||
// }
|
||||
for (auto i = items.rbegin(); i != items.rend(); ++i) {
|
||||
if(i==items.rend()-1){
|
||||
if(isClick){
|
||||
if(countClick & 1){
|
||||
(*i)->setAngle(45);
|
||||
}else{
|
||||
(*i)->setAngle(315);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
|
||||
}
|
||||
(*i)->render();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool Snake::init(int size, double spead) {
|
||||
bool Snake::init(int size, double speed) {
|
||||
|
||||
if (size < 0 || spead <= 0) {
|
||||
if (size < 0 || speed <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
_speed = spead;
|
||||
this->speed = speed;
|
||||
|
||||
for ( int i = size; i >= 0; --i ) {
|
||||
_items.push_back( new Head(&_speed));
|
||||
items.push_back( new Head(&this->speed));
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -33,9 +44,9 @@ bool Snake::init(int size, double spead) {
|
||||
}
|
||||
|
||||
Snake::~Snake() {
|
||||
for (auto i : _items) {
|
||||
for (auto i : items) {
|
||||
delete i;
|
||||
}
|
||||
_items.clear();
|
||||
items.clear();
|
||||
|
||||
}
|
||||
|
@ -10,14 +10,15 @@
|
||||
class Snake : public BaseClass
|
||||
{
|
||||
private:
|
||||
QVector<Head*> _items;
|
||||
double _speed;
|
||||
bool _isClick;
|
||||
QVector<Head*> items;
|
||||
double speed;
|
||||
bool isClick;
|
||||
int countClick;
|
||||
public:
|
||||
Snake();
|
||||
~Snake() override;
|
||||
void render() override;
|
||||
bool init(int size, double spead);
|
||||
bool init(int size, double speed);
|
||||
const QVector<Head*>& getItems() const;
|
||||
void setSpeedHead (void);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user