mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-05-02 12:39:43 +00:00
ref #97 Added description for class and methods.
This commit is contained in:
parent
b1a49bd603
commit
dfa9afca92
src
@ -29,7 +29,7 @@ void Layout::remove(ClasterItem *object) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layout::changeLayout(const Refresh &fig) {
|
void Layout::changeLayout(const LayoutType &fig) {
|
||||||
_shape = fig;
|
_shape = fig;
|
||||||
updatePosition();
|
updatePosition();
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ void Layout::updatePosition() {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
updatePosition();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layout::drawCircle() {
|
void Layout::drawCircle() {
|
||||||
|
@ -14,16 +14,65 @@
|
|||||||
namespace CRAWL {
|
namespace CRAWL {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The Refresh enum Lists the shapes to convert the group object to.
|
* @brief The LayoutType enum Lists the shapes to convert the group object to.
|
||||||
*/
|
*/
|
||||||
enum Refresh {
|
enum LayoutType {
|
||||||
|
/// The circle property calls the drawCircle method, which recalculates and updates
|
||||||
|
/// the coordinates of the passed object's positions.
|
||||||
CIRCLE,
|
CIRCLE,
|
||||||
|
|
||||||
|
/// The square property calls the drawSquare method, which updates the coordinates of
|
||||||
|
/// the objects' positions, giving them the shape of a square.
|
||||||
SQUARE,
|
SQUARE,
|
||||||
|
|
||||||
|
/// The LINE property calls the drawLine method, which updates the coordinates of the
|
||||||
|
/// objects' positions, giving it a line shape.
|
||||||
LINE
|
LINE
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The ControlPos class The class that control position of group objects.
|
* @brief The Layout class The class that control position of group objects.
|
||||||
|
* ### Requried child classes: IWorldItem
|
||||||
|
*
|
||||||
|
* This class overloads the add() and remove() methods, which add objects to the cluster while updating positions according to the selected LayoutType.
|
||||||
|
* Has two public methods for setting the distance to the object and selecting the grouping of objects.
|
||||||
|
*
|
||||||
|
* ## Example of use
|
||||||
|
*
|
||||||
|
* ### For what this object uses
|
||||||
|
* This object is convenient to use if you want to create a cluster object directly, within which subobjects are grouped into a circle or square, depending on the selected property.
|
||||||
|
* For example : snake obstacle.
|
||||||
|
*
|
||||||
|
* ### Example of use
|
||||||
|
*
|
||||||
|
* 1. Create the GroupObjObstacle class.
|
||||||
|
*
|
||||||
|
* ```cpp
|
||||||
|
*
|
||||||
|
* class GroupObjObstacle: public CRAWL::Layout, public CRAWL::IWorldItem {
|
||||||
|
*
|
||||||
|
* // sets the distance to the object from the center.
|
||||||
|
* setDistance(20);
|
||||||
|
*
|
||||||
|
* // Set the property of grouping objects
|
||||||
|
* changeLayout(CRAWL::LayoutType::CIRCLE);
|
||||||
|
*
|
||||||
|
* for(int i(0); i < 20; i++) {
|
||||||
|
* add(new BoxItem);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* };
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @note The added object must inherit from ClasterItem and have a child class required for overloading software renderers.
|
||||||
|
*
|
||||||
|
* All done. Now the added objects will be grouped into a circle shape.
|
||||||
|
*
|
||||||
|
* You can change the center-to-object distance and the shape of a group of objects using the setDistance and changeLayout methods.
|
||||||
|
*
|
||||||
|
* @note This class requried the GuiObject functions as a parent class.
|
||||||
|
* @note This class requires an overload of the render method; The implementation must call the render methods of the parent classes.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
class Layout: public GroupObject {
|
class Layout: public GroupObject {
|
||||||
public:
|
public:
|
||||||
@ -38,7 +87,7 @@ public:
|
|||||||
* @brief changeLayout This method defines the shape of the group object.
|
* @brief changeLayout This method defines the shape of the group object.
|
||||||
* @param fig This is the name of the figure to change the group object.
|
* @param fig This is the name of the figure to change the group object.
|
||||||
*/
|
*/
|
||||||
void changeLayout(const Refresh &fig);
|
void changeLayout(const LayoutType &fig);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief setDistance This method sets, depending on the shape selected, the radius for the circle or the indentation for the square.
|
* @brief setDistance This method sets, depending on the shape selected, the radius for the circle or the indentation for the square.
|
||||||
@ -70,7 +119,7 @@ private:
|
|||||||
void drawLine();
|
void drawLine();
|
||||||
|
|
||||||
int _distance;
|
int _distance;
|
||||||
Refresh _shape;
|
LayoutType _shape;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,28 +13,11 @@ namespace TestLvl {
|
|||||||
GroupObjBox::GroupObjBox(): CRAWL::IWorldItem("GroupObjBox") {
|
GroupObjBox::GroupObjBox(): CRAWL::IWorldItem("GroupObjBox") {
|
||||||
|
|
||||||
setDistance(20);
|
setDistance(20);
|
||||||
changeLayout(CRAWL::Refresh::CIRCLE);
|
changeLayout(CRAWL::LayoutType::CIRCLE);
|
||||||
|
|
||||||
add(new BoxItem);
|
for(int i(0); i < 20; i++) {
|
||||||
add(new BoxItem);
|
add(new BoxItem);
|
||||||
add(new BoxItem);
|
}
|
||||||
add(new BoxItem);
|
|
||||||
add(new BoxItem);
|
|
||||||
add(new BoxItem);
|
|
||||||
add(new BoxItem);
|
|
||||||
add(new BoxItem);
|
|
||||||
add(new BoxItem);
|
|
||||||
add(new BoxItem);
|
|
||||||
add(new BoxItem);
|
|
||||||
add(new BoxItem);
|
|
||||||
add(new BoxItem);
|
|
||||||
add(new BoxItem);
|
|
||||||
add(new BoxItem);
|
|
||||||
add(new BoxItem);
|
|
||||||
add(new BoxItem);
|
|
||||||
add(new BoxItem);
|
|
||||||
add(new BoxItem);
|
|
||||||
add(new BoxItem);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,13 +32,13 @@ CRAWL::WorldRule *World::initWorldRules() {
|
|||||||
using Day = CRAWL::Day<CRAWL::Sun, CRAWL::Moon>;
|
using Day = CRAWL::Day<CRAWL::Sun, CRAWL::Moon>;
|
||||||
|
|
||||||
return new CRAWL::WorldRule {
|
return new CRAWL::WorldRule {
|
||||||
{0, {{registerObject<Box>(), 1},
|
{0, {{registerObject<Box>(), 100},
|
||||||
// {registerObject<CRAWL::Fire>(), 10},
|
{registerObject<CRAWL::Fire>(), 10},
|
||||||
// {registerObject<CRAWL::DynamicWint>(), 1},
|
{registerObject<CRAWL::DynamicWint>(), 1},
|
||||||
|
|
||||||
{registerObject<Background>(), 1},
|
{registerObject<Background>(), 1},
|
||||||
{registerObject<Day>(), 1}}},
|
{registerObject<Day>(), 1}}},
|
||||||
{30,
|
{300,
|
||||||
{
|
{
|
||||||
{registerObject<GroupObjBox>(),5}
|
{registerObject<GroupObjBox>(),5}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user