mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-04-27 18:24:41 +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.
|
||||
*/
|
||||
const QString &view() const;
|
||||
|
||||
signals:
|
||||
void viewChanged();
|
||||
|
||||
|
@ -54,13 +54,20 @@ void IWorld::render(unsigned int tbfMsec) {
|
||||
}
|
||||
|
||||
_ItemsMutex.lock();
|
||||
|
||||
QList<int> toRemove;
|
||||
for (auto i = _items.begin(); i != _items.end(); ++i) {
|
||||
if ((*i)->destroyIsScheduled())
|
||||
toRemove.push_back((*i)->guiId());
|
||||
|
||||
(*i)->render(tbfMsec);
|
||||
}
|
||||
|
||||
_ItemsMutex.unlock();
|
||||
|
||||
for (int id: toRemove) {
|
||||
removeItem(id);
|
||||
}
|
||||
|
||||
updateWorld();
|
||||
|
||||
int waitTime = 1000 / targetFps() - tbfMsec;
|
||||
|
@ -36,16 +36,7 @@ const IWorldItem *IWorldItem::getPlayer() const {
|
||||
void IWorldItem::render(unsigned int) {
|
||||
if (_playerObject->position().distanceToPoint(position()) >
|
||||
_world->cameraReleativePosition().z() * 3) {
|
||||
|
||||
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);
|
||||
respawn();
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,16 +55,36 @@ bool IWorldItem::isSopportEvent(int event) const {
|
||||
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) {
|
||||
_supportedEvents = newSupportedEvents;
|
||||
}
|
||||
|
||||
void IWorldItem::addSupportOfEvent(int newSupportedEvent) {
|
||||
|
||||
_supportedEvents = _supportedEvents | newSupportedEvent;
|
||||
}
|
||||
|
||||
void IWorldItem::dropSupportOfEvent(int depricatedEvent) {
|
||||
|
||||
_supportedEvents = _supportedEvents & (~depricatedEvent);
|
||||
}
|
||||
|
||||
bool IWorldItem::isDecorative() const {
|
||||
|
@ -59,6 +59,24 @@ public:
|
||||
*/
|
||||
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:
|
||||
|
||||
/**
|
||||
@ -122,7 +140,7 @@ private:
|
||||
const IWorldItem *_playerObject = nullptr;
|
||||
|
||||
bool _fDecorative = true;
|
||||
|
||||
bool _fDistroy = false;
|
||||
int _supportedEvents;
|
||||
|
||||
friend class IWorld;
|
||||
|
@ -23,6 +23,10 @@ void PlayableObject::render(unsigned int tbfMsec) {
|
||||
MovableObject::render(tbfMsec);
|
||||
}
|
||||
|
||||
const IControl *PlayableObject::currentControl() const {
|
||||
return _currentControl;
|
||||
}
|
||||
|
||||
void PlayableObject::setControl(const IControl *control) {
|
||||
|
||||
|
||||
|
@ -57,6 +57,12 @@ public:
|
||||
*/
|
||||
virtual void setControl(const IControl* control);
|
||||
|
||||
/**
|
||||
* @brief currentControl This method return pointer to current control
|
||||
* @return
|
||||
*/
|
||||
const IControl *currentControl() const;
|
||||
|
||||
protected:
|
||||
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