mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-05-14 02:19:44 +00:00
move all game engine to qt6 and Quick 3d
This commit is contained in:
parent
2995397e81
commit
e7253c4edc
@ -9,7 +9,7 @@ BackGround::BackGround(double x, double y): ItemWorld (x, y) {
|
||||
void BackGround::render() {
|
||||
auto wPart = w() / 2;
|
||||
|
||||
if (m_x + wPart < 200) {
|
||||
if (_x + wPart < 200) {
|
||||
setX(wPart);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <QColor>
|
||||
|
||||
Box::Box(double x, double y):
|
||||
ItemWorld (x, y) {
|
||||
ItemWorld (x, y, "3dPrimitive") {
|
||||
|
||||
this->setSize(10, 10);
|
||||
|
||||
|
@ -2,71 +2,29 @@
|
||||
|
||||
GuiObject::GuiObject(const QString &viewTempalte, QObject *ptr):
|
||||
QObject (ptr) {
|
||||
m_viewTemplate = viewTempalte;
|
||||
_viewTemplate = viewTempalte;
|
||||
generateId();
|
||||
|
||||
}
|
||||
|
||||
double GuiObject::angle() const {
|
||||
return m_angle;
|
||||
}
|
||||
|
||||
QString GuiObject::texture() const {
|
||||
return m_texture;
|
||||
}
|
||||
|
||||
void GuiObject::render() {
|
||||
}
|
||||
|
||||
QRectF GuiObject::rect() const {
|
||||
return QRectF(m_x - m_w / 2, m_y - m_h / 2, m_w, m_h);
|
||||
}
|
||||
|
||||
void GuiObject::setAngle(double angle) {
|
||||
m_angle = angle;
|
||||
emit angleChanged(m_angle);
|
||||
}
|
||||
|
||||
int GuiObject::guiId() const {
|
||||
return m_guiId;
|
||||
}
|
||||
|
||||
QString GuiObject::color() const {
|
||||
return m_color;
|
||||
return _color;
|
||||
}
|
||||
|
||||
void GuiObject::setColor(QString color) {
|
||||
if (m_color == color)
|
||||
if (_color == color)
|
||||
return;
|
||||
|
||||
m_color = color;
|
||||
emit colorChanged(m_color);
|
||||
}
|
||||
|
||||
double GuiObject::x() const {
|
||||
return m_x;
|
||||
}
|
||||
|
||||
double GuiObject::y() const {
|
||||
return m_y;
|
||||
}
|
||||
|
||||
double GuiObject::w() const {
|
||||
return m_w;
|
||||
}
|
||||
|
||||
double GuiObject::h() const {
|
||||
return m_h;
|
||||
_color = color;
|
||||
emit colorChanged(_color);
|
||||
}
|
||||
|
||||
void GuiObject::generateId() {
|
||||
static int id = 0;
|
||||
m_guiId = id++;
|
||||
}
|
||||
|
||||
void GuiObject::setH(double h) {
|
||||
m_h = h;
|
||||
emit hChanged();
|
||||
_guiId = id++;
|
||||
}
|
||||
|
||||
void GuiObject::reset() {
|
||||
@ -74,43 +32,134 @@ void GuiObject::reset() {
|
||||
setY(-1);
|
||||
}
|
||||
|
||||
int GuiObject::radius() const {
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
QString GuiObject::viewTemplate() const {
|
||||
return m_viewTemplate;
|
||||
return _viewTemplate;
|
||||
}
|
||||
|
||||
void GuiObject::setRadius(int radius) {
|
||||
if (m_radius == radius)
|
||||
int GuiObject::guiId() const {
|
||||
return _guiId;
|
||||
}
|
||||
|
||||
void GuiObject::setGuiId(int guiId) {
|
||||
if (guiId == _guiId)
|
||||
return;
|
||||
|
||||
m_radius = radius;
|
||||
emit radiusChanged(m_radius);
|
||||
_guiId = guiId;
|
||||
emit guiIdChanged(guiId);
|
||||
}
|
||||
|
||||
void GuiObject::setW(double w) {
|
||||
m_w = w;
|
||||
emit wChanged();
|
||||
|
||||
float GuiObject::x() const {
|
||||
return _x;
|
||||
}
|
||||
|
||||
void GuiObject::setY(double y) {
|
||||
m_y = y;
|
||||
emit yChanged();
|
||||
|
||||
}
|
||||
|
||||
void GuiObject::setX(double x) {
|
||||
m_x = x;
|
||||
void GuiObject::setX(float newX) {
|
||||
if (qFuzzyCompare(_x, newX))
|
||||
return;
|
||||
_x = newX;
|
||||
emit xChanged();
|
||||
|
||||
}
|
||||
|
||||
void GuiObject::setTexture(const QString &texture) {
|
||||
m_texture = texture;
|
||||
emit textureChanged(m_texture);
|
||||
float GuiObject::y() const {
|
||||
return _y;
|
||||
}
|
||||
|
||||
void GuiObject::setY(float newY) {
|
||||
if (qFuzzyCompare(_y, newY))
|
||||
return;
|
||||
_y = newY;
|
||||
emit yChanged();
|
||||
}
|
||||
|
||||
float GuiObject::z() const {
|
||||
return _z;
|
||||
}
|
||||
|
||||
void GuiObject::setZ(float newZ) {
|
||||
if (qFuzzyCompare(_z, newZ))
|
||||
return;
|
||||
_z = newZ;
|
||||
emit zChanged();
|
||||
}
|
||||
|
||||
float GuiObject::dx() const {
|
||||
return _dx;
|
||||
}
|
||||
|
||||
void GuiObject::setDx(float newDx) {
|
||||
if (qFuzzyCompare(_dx, newDx))
|
||||
return;
|
||||
_dx = newDx;
|
||||
emit dxChanged();
|
||||
}
|
||||
|
||||
float GuiObject::dy() const {
|
||||
return _dy;
|
||||
}
|
||||
|
||||
void GuiObject::setDy(float newDy) {
|
||||
if (qFuzzyCompare(_dy, newDy))
|
||||
return;
|
||||
_dy = newDy;
|
||||
emit dyChanged();
|
||||
}
|
||||
|
||||
float GuiObject::dz() const {
|
||||
return _dz;
|
||||
}
|
||||
|
||||
void GuiObject::setDz(float newDz) {
|
||||
if (qFuzzyCompare(_dz, newDz))
|
||||
return;
|
||||
_dz = newDz;
|
||||
emit dzChanged();
|
||||
}
|
||||
|
||||
float GuiObject::rx() const {
|
||||
return _rx;
|
||||
}
|
||||
|
||||
void GuiObject::setRx(float newRx) {
|
||||
if (qFuzzyCompare(_rx, newRx))
|
||||
return;
|
||||
_rx = newRx;
|
||||
emit rxChanged();
|
||||
}
|
||||
|
||||
float GuiObject::ry() const {
|
||||
return _ry;
|
||||
}
|
||||
|
||||
void GuiObject::setRy(float newRy) {
|
||||
if (qFuzzyCompare(_ry, newRy))
|
||||
return;
|
||||
_ry = newRy;
|
||||
emit ryChanged();
|
||||
}
|
||||
|
||||
float GuiObject::rz() const {
|
||||
return _rz;
|
||||
}
|
||||
|
||||
void GuiObject::setRz(float newRz) {
|
||||
if (qFuzzyCompare(_rz, newRz))
|
||||
return;
|
||||
_rz = newRz;
|
||||
emit rzChanged();
|
||||
}
|
||||
|
||||
const QString &GuiObject::baseColorMap() const {
|
||||
return _baseColorMap;
|
||||
}
|
||||
|
||||
const QString &GuiObject::roughnessMap() const {
|
||||
return _roughnessMap;
|
||||
}
|
||||
|
||||
const QString &GuiObject::normalMap() const {
|
||||
return _normalMap;
|
||||
}
|
||||
|
||||
const QString &GuiObject::emissiveMap() const {
|
||||
return _emissiveMap;
|
||||
}
|
||||
|
@ -11,81 +11,128 @@ class GuiObject:public QObject, public BaseClass
|
||||
Q_OBJECT
|
||||
// @todo: add color
|
||||
Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
|
||||
Q_PROPERTY(double angle READ angle NOTIFY angleChanged)
|
||||
Q_PROPERTY(QString texture READ texture NOTIFY textureChanged)
|
||||
Q_PROPERTY(int guiId READ guiId NOTIFY guiIdChanged)
|
||||
Q_PROPERTY(QString viewTemplate READ viewTemplate NOTIFY viewTemplateChanged)
|
||||
Q_PROPERTY(int radius READ radius WRITE setRadius NOTIFY radiusChanged)
|
||||
|
||||
Q_PROPERTY(double x READ x NOTIFY xChanged)
|
||||
Q_PROPERTY(double y READ y NOTIFY yChanged)
|
||||
Q_PROPERTY(double w READ w NOTIFY wChanged)
|
||||
Q_PROPERTY(double h READ h NOTIFY hChanged)
|
||||
Q_PROPERTY(float x READ x WRITE setX NOTIFY xChanged)
|
||||
Q_PROPERTY(float y READ y WRITE setY NOTIFY yChanged)
|
||||
Q_PROPERTY(float z READ z WRITE setZ NOTIFY zChanged)
|
||||
|
||||
private:
|
||||
void generateId();
|
||||
QString m_viewTemplate;
|
||||
// size of object for each axis
|
||||
Q_PROPERTY(float dx READ dx WRITE setDx NOTIFY dxChanged)
|
||||
Q_PROPERTY(float dy READ dy WRITE setDy NOTIFY dyChanged)
|
||||
Q_PROPERTY(float dz READ dz WRITE setDz NOTIFY dzChanged)
|
||||
|
||||
protected:
|
||||
int m_guiId = -1;
|
||||
double m_angle = 0;
|
||||
QString m_texture = "";
|
||||
QString m_color = "";
|
||||
int m_radius = 0;
|
||||
// rotation foeach axis
|
||||
Q_PROPERTY(float rx READ rx WRITE setRx NOTIFY rxChanged)
|
||||
Q_PROPERTY(float ry READ ry WRITE setRy NOTIFY ryChanged)
|
||||
Q_PROPERTY(float rz READ rz WRITE setRz NOTIFY rzChanged)
|
||||
|
||||
double m_x = 0;
|
||||
double m_y = 0;
|
||||
double m_w = 0;
|
||||
double m_h = 0;
|
||||
|
||||
void setTexture(const QString &texture);
|
||||
// textures
|
||||
Q_PROPERTY(QString baseColorMap READ baseColorMap NOTIFY baseColorMapChanged)
|
||||
Q_PROPERTY(QString roughnessMap READ roughnessMap NOTIFY roughnessMapChanged)
|
||||
Q_PROPERTY(QString normalMap READ normalMap NOTIFY normalMapChanged)
|
||||
Q_PROPERTY(QString emissiveMap READ emissiveMap NOTIFY emissiveMapChanged)
|
||||
|
||||
|
||||
public:
|
||||
GuiObject(const QString& viewTempalte = "GraphicItem", QObject *ptr = nullptr);
|
||||
|
||||
double angle() const;
|
||||
QString texture() const;
|
||||
|
||||
void render() override;
|
||||
|
||||
QRectF rect() const;
|
||||
virtual void setAngle(double angle);
|
||||
int guiId() const;
|
||||
|
||||
QString color() const;
|
||||
|
||||
void setColor(QString color);
|
||||
|
||||
double x() const;
|
||||
double y() const;
|
||||
double w() const;
|
||||
double h() const;
|
||||
|
||||
void setX(double x);
|
||||
void setY(double y);
|
||||
void setW(double w);
|
||||
void setH(double h);
|
||||
|
||||
virtual void reset();
|
||||
int radius() const;
|
||||
QString viewTemplate() const;
|
||||
|
||||
int guiId() const;
|
||||
void setGuiId(int guiId);
|
||||
|
||||
float x() const;
|
||||
void setX(float newX);
|
||||
|
||||
float y() const;
|
||||
void setY(float newY);
|
||||
|
||||
float z() const;
|
||||
void setZ(float newZ);
|
||||
|
||||
float dx() const;
|
||||
void setDx(float newDx);
|
||||
|
||||
float dy() const;
|
||||
void setDy(float newDy);
|
||||
|
||||
float dz() const;
|
||||
void setDz(float newDz);
|
||||
|
||||
float rx() const;
|
||||
void setRx(float newRx);
|
||||
|
||||
float ry() const;
|
||||
void setRy(float newRy);
|
||||
|
||||
float rz() const;
|
||||
void setRz(float newRz);
|
||||
|
||||
const QString &baseColorMap() const;
|
||||
|
||||
const QString &roughnessMap() const;
|
||||
|
||||
const QString &normalMap() const;
|
||||
|
||||
const QString &emissiveMap() const;
|
||||
|
||||
public slots:
|
||||
|
||||
void setRadius(int radius);
|
||||
|
||||
signals:
|
||||
void angleChanged(double angle);
|
||||
void textureChanged(QString texture);
|
||||
void guiIdChanged(int guiId);
|
||||
void colorChanged(QString color);
|
||||
void viewTemplateChanged(QString viewTemplate);
|
||||
|
||||
void xChanged();
|
||||
void yChanged();
|
||||
void wChanged();
|
||||
void hChanged();
|
||||
void radiusChanged(int radius);
|
||||
void viewTemplateChanged(QString viewTemplate);
|
||||
void zChanged();
|
||||
void dxChanged();
|
||||
void dyChanged();
|
||||
void dzChanged();
|
||||
void rxChanged();
|
||||
void ryChanged();
|
||||
void rzChanged();
|
||||
void baseColorMapChanged();
|
||||
void roughnessMapChanged();
|
||||
void normalMapChanged();
|
||||
void emissiveMapChanged();
|
||||
|
||||
protected:
|
||||
int _guiId = -1;
|
||||
QString _color = "";
|
||||
|
||||
float _x;
|
||||
float _y;
|
||||
float _z;
|
||||
float _dx;
|
||||
float _dy;
|
||||
float _dz;
|
||||
float _rx;
|
||||
float _ry;
|
||||
float _rz;
|
||||
|
||||
void setTexture(const QString &texture);
|
||||
|
||||
private:
|
||||
void generateId();
|
||||
|
||||
|
||||
QString _baseColorMap;
|
||||
QString _roughnessMap;
|
||||
QString _normalMap;
|
||||
QString _emissiveMap;
|
||||
QString _viewTemplate;
|
||||
|
||||
};
|
||||
|
||||
#endif // GUIOBJECT_H
|
||||
|
@ -1,54 +0,0 @@
|
||||
#include "guiobject3d.h"
|
||||
|
||||
|
||||
GuiObject3D::GuiObject3D(const QString &viewTempalte, QObject *ptr):
|
||||
GuiObject(viewTempalte, ptr) {
|
||||
|
||||
}
|
||||
|
||||
double GuiObject3D::z() const {
|
||||
return _z;
|
||||
}
|
||||
|
||||
double GuiObject3D::scaleZ() const {
|
||||
return _scaleZ;
|
||||
}
|
||||
|
||||
void GuiObject3D::setZ(double z) {
|
||||
if (z == _z){
|
||||
return;
|
||||
}
|
||||
|
||||
_z = z;
|
||||
emit zChanged();
|
||||
}
|
||||
|
||||
void GuiObject3D::setScaleZ(double scaleFactor) {
|
||||
if (scaleFactor == _scaleZ){
|
||||
return;
|
||||
}
|
||||
|
||||
_scaleZ = scaleFactor;
|
||||
emit scaleZChanged();
|
||||
}
|
||||
|
||||
void GuiObject3D::setMash(const QString &mash) {
|
||||
if (mash == _mash){
|
||||
return;
|
||||
}
|
||||
|
||||
_mash = mash;
|
||||
emit mashChanged();
|
||||
}
|
||||
|
||||
QString GuiObject3D::mash() const {
|
||||
return _mash;
|
||||
}
|
||||
|
||||
double GuiObject3D::scaleX() const {
|
||||
return h();
|
||||
}
|
||||
|
||||
double GuiObject3D::scaleY() const {
|
||||
return w();
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
#ifndef GUIOBJECT3D_H
|
||||
#define GUIOBJECT3D_H
|
||||
|
||||
#include "guiobject.h"
|
||||
|
||||
/**
|
||||
* @brief The GuiObject3D class This is 3d implementation of the Qt Quick 3d engine objects.
|
||||
*/
|
||||
class GuiObject3D : public GuiObject {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(double z READ z NOTIFY zChanged)
|
||||
Q_PROPERTY(double scaleZ READ scaleZ NOTIFY scaleZChanged)
|
||||
Q_PROPERTY(double scaleX READ scaleX NOTIFY hChanged)
|
||||
Q_PROPERTY(double scaleY READ scaleY NOTIFY wChanged)
|
||||
|
||||
Q_PROPERTY(QString mash READ mash NOTIFY mashChanged)
|
||||
|
||||
public:
|
||||
GuiObject3D(const QString& viewTempalte = "GraphicItem", QObject *ptr = nullptr);
|
||||
|
||||
/**
|
||||
* @brief z this is z axis
|
||||
* @return return z position of the object.
|
||||
*/
|
||||
double z() const;
|
||||
|
||||
/**
|
||||
* @brief scaleZ This is size object of the z axis.
|
||||
* @return return size of z axis
|
||||
*/
|
||||
double scaleZ() const;
|
||||
|
||||
/**
|
||||
* @brief mash This method return path to mash of the 3d object.
|
||||
* @return Path of the mash object.
|
||||
* @note for preparew mash use the obj file in Blender and convert obj files to mash using **balsam** tool.
|
||||
*/
|
||||
QString mash() const;
|
||||
|
||||
/**
|
||||
* @brief setZ This method sets new z point of object.
|
||||
* @param z this is new oint of z
|
||||
*/
|
||||
void setZ(double z);
|
||||
|
||||
/**
|
||||
* @brief setScaleZ This method sets new scale fcator of object.
|
||||
* @param scaleFactor new value of the scale factor.
|
||||
*/
|
||||
void setScaleZ(double scaleFactor);
|
||||
|
||||
/**
|
||||
* @brief setMash This method sets new path to mash object. For create mash object use the balsam tool.
|
||||
* @param mash This is path to mash object.
|
||||
*/
|
||||
void setMash(const QString& mash);
|
||||
|
||||
/**
|
||||
* @brief scaleX This method is simple wraper of the w property.
|
||||
* @return width of the object.
|
||||
*/
|
||||
double scaleX() const;
|
||||
|
||||
/**
|
||||
* @brief scaleY This metthod is simple wraper of the h proprty.
|
||||
* @return return height of the object.
|
||||
*/
|
||||
double scaleY() const;
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief zChanged This signal emmited when z point changed.
|
||||
*/
|
||||
void zChanged();
|
||||
|
||||
/**
|
||||
* @brief scaleZChanged This signale emited when sale factor of the z axis are changed.
|
||||
*/
|
||||
void scaleZChanged();
|
||||
|
||||
/**
|
||||
* @brief mashChanged
|
||||
*/
|
||||
void mashChanged();
|
||||
|
||||
private:
|
||||
double _z = 0;
|
||||
double _scaleZ = 1;
|
||||
QString _mash = "#Cube";
|
||||
};
|
||||
|
||||
#endif // GUIOBJECT3D_H
|
@ -8,8 +8,8 @@ void Head::render() {
|
||||
qint64 tempTime = QDateTime::currentMSecsSinceEpoch() - time;
|
||||
time = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
double my = (m_y + (*speed * 0.55) * sin(m_angle * TO_RADIAN));
|
||||
m_y += (my - m_y) / 1000 * tempTime;
|
||||
double my = (_y + (*speed * 0.55) * sin(m_angle * TO_RADIAN));
|
||||
_y += (my - _y) / 1000 * tempTime;
|
||||
|
||||
if (*speed < 1) {
|
||||
setColor(generalSpeadColor);
|
||||
|
@ -22,7 +22,7 @@ private:
|
||||
|
||||
public:
|
||||
Head(double x , double y, double h, double w, double *speed);
|
||||
void setAngle(double angle) override;
|
||||
void setAngle(double angle);
|
||||
void render() override;
|
||||
void reset() override;
|
||||
void unPause();
|
||||
|
@ -7,7 +7,7 @@
|
||||
#define POINT 100
|
||||
|
||||
ItemWorld::ItemWorld(double x, double y, const QString& guiTemplate):
|
||||
GuiObject (guiTemplate) {
|
||||
GuiObject3D (guiTemplate) {
|
||||
setLoc(x, y);
|
||||
}
|
||||
|
||||
@ -26,16 +26,16 @@ void ItemWorld::setLoc(double x, double y) {
|
||||
}
|
||||
|
||||
void ItemWorld::render() {
|
||||
if (m_x + w() < 0) {
|
||||
m_x = (rand() % 400) + 200;
|
||||
m_y = rand() % 100;
|
||||
if (_x + w() < 0) {
|
||||
_x = (rand() % 400) + 200;
|
||||
_y = rand() % 100;
|
||||
emit xChanged();
|
||||
emit yChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool ItemWorld::move(const GuiObject *snakeRiger, double dx) {
|
||||
m_x -= dx;
|
||||
_x -= dx;
|
||||
emit xChanged();
|
||||
|
||||
return snakeRiger->rect().intersects(rect()) && !beckGroundObject;
|
||||
|
@ -6,13 +6,7 @@
|
||||
|
||||
class ItemWorld : public GuiObject
|
||||
{
|
||||
private:
|
||||
bool beckGroundObject = false;
|
||||
protected:
|
||||
virtual void setSize(double h, double w);
|
||||
virtual void setLoc(double x, double y);
|
||||
void setBeckGroundObject(bool value);
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
ItemWorld(double x, double y, const QString& GuiTemplate = "GraphicItem");
|
||||
|
||||
@ -21,6 +15,16 @@ public:
|
||||
bool isBeckGroundObject();
|
||||
|
||||
~ItemWorld();
|
||||
|
||||
|
||||
protected:
|
||||
void setSize(double h, double w);
|
||||
void setLoc(double x, double y);
|
||||
void setBeckGroundObject(bool value);
|
||||
|
||||
|
||||
private:
|
||||
bool beckGroundObject = false;
|
||||
};
|
||||
|
||||
#endif // ITEMWORLD_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user