4
1
mirror of https://github.com/QuasarApp/Snake.git synced 2025-05-10 00:19:45 +00:00

ref move code of the tests lvl to main repository

This commit is contained in:
Andrei Yankovich 2021-07-03 20:02:21 +03:00
parent c3a8acc73f
commit 6c3e8408ff
18 changed files with 475 additions and 0 deletions

@ -118,10 +118,20 @@ void ClientApp::start(const QString &lvl) {
QList<QFileInfo> ClientApp::availablePlugins() const {
QDir dir(QCoreApplication::applicationDirPath() + "/modules");
auto list = dir.entryInfoList(QStringList() << "*.so" << "*.dll", QDir::Files);
#ifdef Q_OS_ANDROID
dir.setPath(QCoreApplication::applicationDirPath());
list += dir.entryInfoList(registeredLvls(), QDir::Files);
#endif
return list;
}
QList<QString> ClientApp::registeredLvls() const {
return {
"*TestLvl.*"
};
}
bool ClientApp::init(QQmlApplicationEngine *engine) {
qputenv("QT_QUICK_CONTROLS_MATERIAL_THEME", initTheme());

@ -67,6 +67,12 @@ private:
*/
QList<QFileInfo> availablePlugins() const;
/**
* @brief registeredLvls This method should be return names of the lvl plugins. This method prepare data for loading plugins on android platform.
* @return list of the plugins names.
*/
QList<QString> registeredLvls() const;
QHash<QString, WordlData> _availableLvls;
MainMenuModel *_menu = nullptr;
Engine *_engine = nullptr;

@ -0,0 +1,30 @@
#
# 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.
#
cmake_minimum_required(VERSION 3.14)
set(CURRENT_PROJECT "TestLvl")
add_definitions(-DCRAWL_LIBRARY)
file(GLOB SOURCE_CPP
"*.cpp"
"private/*.cpp"
"*.qrc"
"private/*.qrc"
)
set(PUBLIC_INCUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(PRIVATE_INCUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/private")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ../Client/modules)
add_library(${CURRENT_PROJECT} ${SOURCE_CPP})
target_link_libraries(${CURRENT_PROJECT} PUBLIC ${PROJECT_NAME}Core)
target_include_directories(${CURRENT_PROJECT} PUBLIC ${PUBLIC_INCUDE_DIR})
target_include_directories(${CURRENT_PROJECT} PRIVATE ${PRIVATE_INCUDE_DIR})

@ -0,0 +1,6 @@
# CrawlTestLvl
# ![CRAWL_BANNER](res/hdr/testHDR.jpg)
This is test lvl of the crawl game

@ -0,0 +1,74 @@
import QtQuick 2.15
import CrawlModule 1.0
import QtQuick.Layouts 1.15
import QtQuick.Controls.Material 2.15
import QtQuick.Controls 2.15
DefaultMenu {
columns: 2
rows: 2
Button {
text: "🌀"
onClicked: {
model.userTap()
}
}
MouseArea {
property bool track: false
property real oldX: 0
property real oldY: 0
cursorShape: Qt.DragMoveCursor
Layout.fillHeight: true
Layout.fillWidth: true
Layout.columnSpan: 2
Layout.rowSpan: 2
onPressed: {
track = true
oldX = mouse.x
oldY = mouse.y
}
onReleased: {
track = false
}
onMouseXChanged: {
if (!model) {
return;
}
if (!track) {
return;
}
const delta = mouse.x - oldX;
const radianDelta = (delta / (parent.width / 2)) * 45
model.xChanged(radianDelta)
oldX = mouse.x;
}
onMouseYChanged: {
if (!model) {
return;
}
if (!track) {
return;
}
const delta = mouse.y - oldY;
const radianDelta = (delta / (parent.height / 2)) * 45
model.yChanged(radianDelta)
oldY = mouse.y;
}
}
}

@ -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 "Crawl/iworld.h"
#include "world.h"
inline void initResources() { Q_INIT_RESOURCE(Empty); }
extern "C" IWorld* worldInstance() {
initResources();
return new World();
}

@ -0,0 +1,30 @@
//#
//# 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 "box.h"
#include <QColor>
Box::Box(): IWorldItem("Box") {
setMash("qrc:/mesh/res/meshes/cube.mesh");
setSize({2,2,2});
setColor(QColor::fromRgb(rand()).name());
setRatation(QQuaternion::fromEulerAngles(
rand() % 360 ,
rand() % 360,
rand() % 360));
setposition({static_cast<float>(rand() % 100) - 50,
static_cast<float>(rand() % 100) - 50,
0 });
}
void Box::onIntersects(const IWorldItem *item) {
Q_UNUSED(item);
}

@ -0,0 +1,22 @@
//#
//# 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 BOX_H
#define BOX_H
#include "Crawl/iworlditem.h"
class Box: public IWorldItem {
public:
Box();
// IWorldItem interface
protected:
void onIntersects(const IWorldItem *item) override;
};
#endif // BOX_H

@ -0,0 +1,19 @@
//#
//# 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 "plate.h"
Plate::Plate(): IGround("plate")
{
setMash("qrc:/mesh/res/meshes/cube.mesh");
setSize({100,100,0});
setZ(0);
}
void Plate::onIntersects(const IWorldItem *item) {
Q_UNUSED(item)
}

@ -0,0 +1,21 @@
//#
//# 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 PLATE_H
#define PLATE_H
#include "Crawl/iground.h"
class Plate: public IGround {
public:
Plate();
// IWorldItem interface
protected:
void onIntersects(const IWorldItem *item) override;
};
#endif // PLATE_H

@ -0,0 +1,9 @@
#include "testcontrol.h"
TestControl::TestControl() {
}
QString TestControl::initQmlView() const {
return "qrc:/qml/TestControl.qml";
}

@ -0,0 +1,20 @@
#ifndef TESTCONTROL_H
#define TESTCONTROL_H
#include "Crawl/defaultcontrol.h"
/**
* @brief The TestControl class This controll support custom camera-ratation functions.
*/
class TestControl: public DefaultControl
{
Q_OBJECT
public:
TestControl();
QString initQmlView() const override;
signals:
void xChanged(double);
void yChanged(double);
};
#endif // TESTCONTROL_H

@ -0,0 +1,25 @@
//#
//# 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 "testsnake.h"
#include <testsnakeitem.h>
TestSnake::TestSnake(): Snake("Snake") {
setBreakingForce(50);
setAngularVelocity(100);
setColor("#90faaa");
setMash("qrc:/mesh/res/meshes/cube.mesh");
setSize({2,1,1});
registerBodyitem<TestSnakeItem>();
}
void TestSnake::onIntersects(const IWorldItem *item) {
Q_UNUSED(item);
}

@ -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 TESTSNAKE_H
#define TESTSNAKE_H
#include "Crawl/snake.h"
class TestSnake : public Snake {
Q_OBJECT
public:
TestSnake();
// IWorldItem interface
protected:
void onIntersects(const IWorldItem *item) override;
};
#endif // TESTSNAKE_H

@ -0,0 +1,21 @@
//#
//# 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 "testsnakeitem.h"
TestSnakeItem::TestSnakeItem() {
setMash("qrc:/mesh/res/meshes/cube.mesh");
setColor("#20aa9a");
setSize({1,1,1});
}
void TestSnakeItem::onIntersects(const IWorldItem *item) {
Q_UNUSED(item);
}

@ -0,0 +1,25 @@
//#
//# 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 TESTSNAKEITEM_H
#define TESTSNAKEITEM_H
#include "Crawl/snakeitem.h"
class TestSnakeItem: public SnakeItem
{
Q_OBJECT
public:
TestSnakeItem();
// IWorldItem interface
protected:
void onIntersects(const IWorldItem *item) override;
};
#endif // TESTSNAKEITEM_H

@ -0,0 +1,78 @@
//#
//# 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 "box.h"
#include "plate.h"
#include "testcontrol.h"
#include "world.h"
#include <testsnake.h>
#include "Crawl/iworlditem.h"
World::World() {
setCameraReleativePosition({0,0,100});
setCameraRatation(QQuaternion::fromEulerAngles({0,0,-90}));
}
WorldRule *World::initWorldRules() {
return new WorldRule {
{0, {{registerObject<Box>(), 1000}}}
};
}
QString World::initHdrBackGround() const {
return "qrc:/hdr/res/hdr/testHDR.hdr";
}
QString World::description() const {
return "This a test lvl";
}
QString World::imagePreview() const {
return "qrc:/hdr/res/hdr/testHDR.jpg";
}
QString World::name() const {
return "Test";
}
int World::costToUnlock() const {
return 0;
}
IControl *World::initUserInterface() const {
return new TestControl();
}
void World::initPlayerControl(IControl *control) {
if (auto test = dynamic_cast<TestControl*>(control)) {
connect(test, &TestControl::xChanged, this, &World::handleXViewChanged);
connect(test, &TestControl::yChanged, this, &World::handleYViewChanged);
}
return IWorld::initPlayerControl(control);
}
IPlayer *World::initPlayer() const {
return new TestSnake();
}
IAI *World::initBackGroundAI() const {
return IWorld::initBackGroundAI();
}
void World::handleXViewChanged(double dx) {
auto eilorRatation = cameraRatation().toEulerAngles();
eilorRatation.setX(eilorRatation.x() + dx);
setCameraRatation(QQuaternion::fromEulerAngles(eilorRatation));
}
void World::handleYViewChanged(double dy) {
auto eilorRatation = cameraRatation().toEulerAngles();
eilorRatation.setY(eilorRatation.y() + dy );
setCameraRatation(QQuaternion::fromEulerAngles(eilorRatation));
}

@ -0,0 +1,37 @@
//#
//# 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 WORLD_H
#define WORLD_H
#include "Crawl/iworld.h"
class World : public IWorld {
// IWorld interface
public:
World();
WorldRule *initWorldRules() override;
QString initHdrBackGround() const override;
QString description() const override;
QString imagePreview() const override;
QString name() const override;
int costToUnlock() const override;
IControl *initUserInterface() const override;
void initPlayerControl(IControl *control) override;
IPlayer *initPlayer() const override;
IAI *initBackGroundAI() const override;
private slots:
void handleXViewChanged(double dx);
void handleYViewChanged(double dy);
};
#endif // WORLD_H