mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-05-15 19:09:47 +00:00
ref #98 "added user structure"
This commit is contained in:
parent
1b4aaf0337
commit
a2ba48e76f
@ -42,6 +42,7 @@ public:
|
|||||||
* @return return path to qml view.
|
* @return return path to qml view.
|
||||||
*/
|
*/
|
||||||
const QString &view() const;
|
const QString &view() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void viewChanged();
|
void viewChanged();
|
||||||
|
|
||||||
|
@ -54,13 +54,20 @@ void IWorld::render(unsigned int tbfMsec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_ItemsMutex.lock();
|
_ItemsMutex.lock();
|
||||||
|
QList<int> toRemove;
|
||||||
for (auto i = _items.begin(); i != _items.end(); ++i) {
|
for (auto i = _items.begin(); i != _items.end(); ++i) {
|
||||||
|
if ((*i)->destroyIsScheduled())
|
||||||
|
toRemove.push_back((*i)->guiId());
|
||||||
|
|
||||||
(*i)->render(tbfMsec);
|
(*i)->render(tbfMsec);
|
||||||
}
|
}
|
||||||
|
|
||||||
_ItemsMutex.unlock();
|
_ItemsMutex.unlock();
|
||||||
|
|
||||||
|
for (int id: toRemove) {
|
||||||
|
removeItem(id);
|
||||||
|
}
|
||||||
|
|
||||||
updateWorld();
|
updateWorld();
|
||||||
|
|
||||||
int waitTime = 1000 / targetFps() - tbfMsec;
|
int waitTime = 1000 / targetFps() - tbfMsec;
|
||||||
|
@ -36,16 +36,7 @@ const IWorldItem *IWorldItem::getPlayer() const {
|
|||||||
void IWorldItem::render(unsigned int) {
|
void IWorldItem::render(unsigned int) {
|
||||||
if (_playerObject->position().distanceToPoint(position()) >
|
if (_playerObject->position().distanceToPoint(position()) >
|
||||||
_world->cameraReleativePosition().z() * 3) {
|
_world->cameraReleativePosition().z() * 3) {
|
||||||
|
respawn();
|
||||||
float dX = _world->cameraReleativePosition().z() * 2 +
|
|
||||||
(rand() % static_cast<int>(_world->cameraReleativePosition().z()));
|
|
||||||
|
|
||||||
setX(_playerObject->position().x() + dX);
|
|
||||||
|
|
||||||
float dY = (rand() % static_cast<int>(_world->cameraReleativePosition().z() * 3)
|
|
||||||
- _world->cameraReleativePosition().z() * 1.5);
|
|
||||||
|
|
||||||
setY(_playerObject->position().y() + dY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,16 +55,36 @@ bool IWorldItem::isSopportEvent(int event) const {
|
|||||||
return (_supportedEvents & event) == event;
|
return (_supportedEvents & event) == event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IWorldItem::destroy() {
|
||||||
|
_fDistroy = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IWorldItem::respawn() {
|
||||||
|
float dX = _world->cameraReleativePosition().z() * 2 +
|
||||||
|
(rand() % static_cast<int>(_world->cameraReleativePosition().z()));
|
||||||
|
|
||||||
|
setX(_playerObject->position().x() + dX);
|
||||||
|
|
||||||
|
float dY = (rand() % static_cast<int>(_world->cameraReleativePosition().z() * 3)
|
||||||
|
- _world->cameraReleativePosition().z() * 1.5);
|
||||||
|
|
||||||
|
setY(_playerObject->position().y() + dY);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IWorldItem::destroyIsScheduled() const {
|
||||||
|
return _fDistroy;
|
||||||
|
}
|
||||||
|
|
||||||
void IWorldItem::setSupportedEvents(int newSupportedEvents) {
|
void IWorldItem::setSupportedEvents(int newSupportedEvents) {
|
||||||
_supportedEvents = newSupportedEvents;
|
_supportedEvents = newSupportedEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IWorldItem::addSupportOfEvent(int newSupportedEvent) {
|
void IWorldItem::addSupportOfEvent(int newSupportedEvent) {
|
||||||
|
_supportedEvents = _supportedEvents | newSupportedEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IWorldItem::dropSupportOfEvent(int depricatedEvent) {
|
void IWorldItem::dropSupportOfEvent(int depricatedEvent) {
|
||||||
|
_supportedEvents = _supportedEvents & (~depricatedEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IWorldItem::isDecorative() const {
|
bool IWorldItem::isDecorative() const {
|
||||||
|
@ -59,6 +59,24 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool isSopportEvent(int event) const;
|
bool isSopportEvent(int event) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief destroy this method will schedule a destroing of this object on the world.
|
||||||
|
* @see IWorldItem::destroyIsScheduled
|
||||||
|
*/
|
||||||
|
virtual void destroy();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief respawn this method will schedule a repawning of this object on the world.
|
||||||
|
*/
|
||||||
|
virtual void respawn();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief destroyIsScheduled This method return true if the current object has been scheduled to destroy.
|
||||||
|
* @return true if the current object has been scheduled to destroy, else false.
|
||||||
|
* @see IWorldItem::destroy
|
||||||
|
*/
|
||||||
|
bool destroyIsScheduled() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,7 +140,7 @@ private:
|
|||||||
const IWorldItem *_playerObject = nullptr;
|
const IWorldItem *_playerObject = nullptr;
|
||||||
|
|
||||||
bool _fDecorative = true;
|
bool _fDecorative = true;
|
||||||
|
bool _fDistroy = false;
|
||||||
int _supportedEvents;
|
int _supportedEvents;
|
||||||
|
|
||||||
friend class IWorld;
|
friend class IWorld;
|
||||||
|
@ -23,6 +23,10 @@ void PlayableObject::render(unsigned int tbfMsec) {
|
|||||||
MovableObject::render(tbfMsec);
|
MovableObject::render(tbfMsec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const IControl *PlayableObject::currentControl() const {
|
||||||
|
return _currentControl;
|
||||||
|
}
|
||||||
|
|
||||||
void PlayableObject::setControl(const IControl *control) {
|
void PlayableObject::setControl(const IControl *control) {
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,6 +57,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void setControl(const IControl* control);
|
virtual void setControl(const IControl* control);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief currentControl This method return pointer to current control
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
const IControl *currentControl() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void render(unsigned int tbfMsec) override;
|
void render(unsigned int tbfMsec) override;
|
||||||
|
|
||||||
|
14
src/Core/Crawl/player.cpp
Normal file
14
src/Core/Crawl/player.cpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
//#
|
||||||
|
//# Copyright (C) 2021-2021 QuasarApp.
|
||||||
|
//# Distributed under the GPLv3 software license, see the accompanying
|
||||||
|
//# Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
//# of this license document, but changing it is not allowed.
|
||||||
|
//#
|
||||||
|
|
||||||
|
#include "player.h"
|
||||||
|
namespace CRAWL {
|
||||||
|
|
||||||
|
Player::Player() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
26
src/Core/Crawl/player.h
Normal file
26
src/Core/Crawl/player.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
//#
|
||||||
|
//# Copyright (C) 2021-2021 QuasarApp.
|
||||||
|
//# Distributed under the GPLv3 software license, see the accompanying
|
||||||
|
//# Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
//# of this license document, but changing it is not allowed.
|
||||||
|
//#
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef PLAYER_H
|
||||||
|
#define PLAYER_H
|
||||||
|
|
||||||
|
#include "icontrol.h"
|
||||||
|
|
||||||
|
namespace CRAWL {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The Player class is main class of users.
|
||||||
|
*/
|
||||||
|
class CRAWL_EXPORT Player: public IControl
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
Player();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif // PLAYER_H
|
16
src/Core/private/user.cpp
Normal file
16
src/Core/private/user.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
//#
|
||||||
|
//# Copyright (C) 2021-2021 QuasarApp.
|
||||||
|
//# Distributed under the GPLv3 software license, see the accompanying
|
||||||
|
//# Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
//# of this license document, but changing it is not allowed.
|
||||||
|
//#
|
||||||
|
|
||||||
|
#include "user.h"
|
||||||
|
namespace CRAWL {
|
||||||
|
|
||||||
|
User::User()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
31
src/Core/private/user.h
Normal file
31
src/Core/private/user.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
//#
|
||||||
|
//# Copyright (C) 2021-2021 QuasarApp.
|
||||||
|
//# Distributed under the GPLv3 software license, see the accompanying
|
||||||
|
//# Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
//# of this license document, but changing it is not allowed.
|
||||||
|
//#
|
||||||
|
|
||||||
|
#include <QSet>
|
||||||
|
|
||||||
|
#ifndef USER_H
|
||||||
|
#define USER_H
|
||||||
|
|
||||||
|
namespace CRAWL {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The User class This is internal class for collection all user data and user state.
|
||||||
|
*/
|
||||||
|
class User
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
User();
|
||||||
|
|
||||||
|
private:
|
||||||
|
int _moneu = 0;
|
||||||
|
int _lvl = 0;
|
||||||
|
QSet<int> _unlockedItems;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // USER_H
|
Loading…
x
Reference in New Issue
Block a user