mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-05-07 23:19:43 +00:00
add beta world
This commit is contained in:
parent
ddf41639cd
commit
73d43cdbbf
7
back-end/box.cpp
Normal file
7
back-end/box.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include "box.h"
|
||||
|
||||
Box::Box()
|
||||
{
|
||||
|
||||
}
|
||||
|
17
back-end/box.h
Normal file
17
back-end/box.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef BOX_H
|
||||
#define BOX_H
|
||||
|
||||
#include "itemworld.h"
|
||||
|
||||
class Box
|
||||
{
|
||||
private:
|
||||
double sizeX, sizeY, radius;
|
||||
QString texture;
|
||||
public:
|
||||
Box();
|
||||
void setSize(double sizeX, double sizeY, double radius);
|
||||
|
||||
};
|
||||
|
||||
#endif // BOX_H
|
@ -27,9 +27,6 @@ public:
|
||||
void render();
|
||||
|
||||
~Head();
|
||||
|
||||
bool getIsHead() const;
|
||||
void setIsHead(bool value);
|
||||
};
|
||||
|
||||
#endif // HEAD_H
|
||||
|
40
back-end/itemworld.cpp
Normal file
40
back-end/itemworld.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include "itemworld.h"
|
||||
#include <cmath>
|
||||
#include <QDateTime>
|
||||
|
||||
double ItemWorld::getX() const
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
void ItemWorld::setX(double value)
|
||||
{
|
||||
x = value;
|
||||
}
|
||||
|
||||
double ItemWorld::getY() const
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
void ItemWorld::setY(double value)
|
||||
{
|
||||
y = value;
|
||||
}
|
||||
|
||||
void ItemWorld::render(){
|
||||
qint64 tempTime = QDateTime::currentMSecsSinceEpoch() - time;
|
||||
double mx = x + *speed;
|
||||
x += (mx - x) / 1000 * tempTime;
|
||||
time = QDateTime::currentMSecsSinceEpoch();
|
||||
}
|
||||
|
||||
QString *ItemWorld::getTexture() const
|
||||
{
|
||||
return texture;
|
||||
}
|
||||
|
||||
void ItemWorld::setTexture(QString *value)
|
||||
{
|
||||
texture = value;
|
||||
}
|
35
back-end/itemworld.h
Normal file
35
back-end/itemworld.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef ITEMWORLD_H
|
||||
#define ITEMWORLD_H
|
||||
|
||||
|
||||
#include "baseclass.h"
|
||||
#include <QString>
|
||||
|
||||
class ItemWorld : BaseClass
|
||||
{
|
||||
private:
|
||||
double x, y;
|
||||
QString *texture;
|
||||
double sizeX, sizeY, radius;
|
||||
qint64 time;
|
||||
double *speed;
|
||||
public:
|
||||
ItemWorld(double *speed);
|
||||
|
||||
double getX() const;
|
||||
void setX(double value);
|
||||
|
||||
double getY() const;
|
||||
void setY(double value);
|
||||
|
||||
virtual void setSize();
|
||||
|
||||
void render();
|
||||
|
||||
QString *getTexture() const;
|
||||
void setTexture(QString *value);
|
||||
|
||||
~ItemWorld();
|
||||
};
|
||||
|
||||
#endif // ITEMWORLD_H
|
@ -20,7 +20,6 @@ public:
|
||||
void render() override;
|
||||
bool init(int size, double speed);
|
||||
const QVector<Head*>& getItems() const;
|
||||
void setSpeedHead (void);
|
||||
};
|
||||
|
||||
#endif // SNAKE_H
|
||||
|
24
back-end/world.cpp
Normal file
24
back-end/world.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "world.h"
|
||||
|
||||
World::World() :
|
||||
speed(SPEEDWORLD) {
|
||||
|
||||
}
|
||||
|
||||
World::~World() {
|
||||
for (auto i : items) {
|
||||
delete i;
|
||||
}
|
||||
items.clear();
|
||||
}
|
||||
|
||||
void World::render()
|
||||
{
|
||||
for (int i = items.length(); i >= 0; --i) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
const QVector<ItemWorld *> &World::getItems() const {
|
||||
return items;
|
||||
}
|
23
back-end/world.h
Normal file
23
back-end/world.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef WORLD_H
|
||||
#define WORLD_H
|
||||
|
||||
#define SPEEDWORLD 10
|
||||
|
||||
#include <QVector>
|
||||
#include "itemworld.h"
|
||||
#include "baseclass.h"
|
||||
|
||||
class World : BaseClass
|
||||
{
|
||||
private:
|
||||
QVector<ItemWorld*> items;
|
||||
double speed;
|
||||
QString background;
|
||||
public:
|
||||
World();
|
||||
~World() override;
|
||||
void render() override;
|
||||
const QVector<ItemWorld*>& getItems() const;
|
||||
};
|
||||
|
||||
#endif // WORLD_H
|
@ -5,5 +5,5 @@ Window {
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: qsTr("SnakeOfTheRoad")
|
||||
title: qsTr("SnakeOnTheRoad")
|
||||
}
|
||||
|
10
snake.pro
10
snake.pro
@ -17,7 +17,10 @@ SOURCES += \
|
||||
back-end/baseclass.cpp \
|
||||
back-end/head.cpp \
|
||||
back-end/snake.cpp \
|
||||
back-end/controller.cpp
|
||||
back-end/controller.cpp \
|
||||
back-end/world.cpp \
|
||||
back-end/itemworld.cpp \
|
||||
back-end/box.cpp
|
||||
|
||||
RESOURCES += qml.qrc
|
||||
|
||||
@ -36,4 +39,7 @@ HEADERS += \
|
||||
back-end/baseclass.h \
|
||||
back-end/head.h \
|
||||
back-end/snake.h \
|
||||
back-end/controller.h
|
||||
back-end/controller.h \
|
||||
back-end/world.h \
|
||||
back-end/itemworld.h \
|
||||
back-end/box.h
|
||||
|
Loading…
x
Reference in New Issue
Block a user