2023-03-22 21:26:13 +05:30
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This code is based on the CRAB engine
|
|
|
|
*
|
|
|
|
* Copyright (c) Arvind Raja Yadav
|
|
|
|
*
|
|
|
|
* Licensed under MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-03-22 22:15:28 +05:30
|
|
|
#ifndef CRAB_SHAPE_H
|
|
|
|
#define CRAB_SHAPE_H
|
2023-03-21 17:19:09 +05:30
|
|
|
|
2023-03-22 23:12:06 +05:30
|
|
|
#include "crab/Polygon.h"
|
|
|
|
#include "crab/vectors.h"
|
2023-03-21 17:19:09 +05:30
|
|
|
|
2023-03-29 19:09:23 +05:30
|
|
|
namespace Crab {
|
|
|
|
|
2023-03-22 10:13:33 +05:30
|
|
|
// The kind of shape
|
2023-07-20 09:53:18 +05:30
|
|
|
enum ShapeType {
|
|
|
|
SHAPE_RECT,
|
|
|
|
SHAPE_POLYGON,
|
|
|
|
SHAPE_ELLIPSE
|
|
|
|
};
|
2023-03-21 17:19:09 +05:30
|
|
|
|
2023-03-22 10:13:33 +05:30
|
|
|
struct CollisionData {
|
|
|
|
// Store the type of shape
|
2023-07-20 09:53:18 +05:30
|
|
|
ShapeType _type;
|
2023-03-21 17:19:09 +05:30
|
|
|
|
2023-03-22 10:13:33 +05:30
|
|
|
// Do the two shapes intersect?
|
2023-07-20 09:53:18 +05:30
|
|
|
bool _intersect;
|
2023-03-21 17:19:09 +05:30
|
|
|
|
2023-03-22 10:13:33 +05:30
|
|
|
// If Shape is Polygon, the .x and .y of this rectangle contain the minimum translation vector
|
|
|
|
// If Shape is Rectangle, this contains the colliding rectangle
|
2023-07-20 09:53:18 +05:30
|
|
|
Rect _data;
|
2023-03-21 17:19:09 +05:30
|
|
|
|
2023-03-22 10:13:33 +05:30
|
|
|
CollisionData() {
|
2023-07-20 09:53:18 +05:30
|
|
|
_type = SHAPE_RECT;
|
|
|
|
_intersect = false;
|
2023-03-22 10:13:33 +05:30
|
|
|
}
|
2023-03-21 17:19:09 +05:30
|
|
|
};
|
|
|
|
|
2023-03-22 10:13:33 +05:30
|
|
|
class Shape {
|
2023-03-21 17:19:09 +05:30
|
|
|
public:
|
2023-03-22 10:13:33 +05:30
|
|
|
// The type of shape
|
2023-07-20 09:53:18 +05:30
|
|
|
ShapeType _type;
|
2023-03-21 17:19:09 +05:30
|
|
|
|
2023-03-22 10:13:33 +05:30
|
|
|
// This stores both the ellipse and rectangle data
|
2023-07-20 09:53:18 +05:30
|
|
|
Rect _rect;
|
2023-03-21 17:19:09 +05:30
|
|
|
|
2023-03-22 10:13:33 +05:30
|
|
|
// This stores the polygon data
|
2023-07-20 09:53:18 +05:30
|
|
|
Polygon2D _poly;
|
|
|
|
|
|
|
|
Shape() {
|
|
|
|
_type = SHAPE_RECT;
|
|
|
|
}
|
2023-03-21 17:19:09 +05:30
|
|
|
|
2023-03-22 10:13:33 +05:30
|
|
|
~Shape() {}
|
2023-03-21 17:19:09 +05:30
|
|
|
|
2023-07-10 11:49:00 +05:30
|
|
|
void load(rapidxml::xml_node<char> *node, const bool &echo = true);
|
2023-08-05 21:47:15 +05:30
|
|
|
CollisionData collide(Rect box) const;
|
2023-03-21 17:19:09 +05:30
|
|
|
|
2023-07-20 09:53:18 +05:30
|
|
|
bool contains(const Vector2i &pos);
|
2023-03-21 17:19:09 +05:30
|
|
|
|
2023-07-20 09:53:18 +05:30
|
|
|
void draw(const int &xOffset = 0, const int &yOffset = 0,
|
2023-03-31 13:56:41 +05:30
|
|
|
const uint8 &r = 0, const uint8 &g = 0, const uint8 &b = 0, const uint8 &a = 255);
|
2023-03-21 17:19:09 +05:30
|
|
|
};
|
2023-03-22 22:15:28 +05:30
|
|
|
|
2023-03-29 19:09:23 +05:30
|
|
|
} // End of namespace Crab
|
|
|
|
|
2023-03-22 22:15:28 +05:30
|
|
|
#endif // CRAB_SHAPE_H
|