mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-05 02:49:57 +00:00
window functions to draw basic 2D shapes
This commit is contained in:
@@ -5,16 +5,33 @@
|
||||
** Pixel
|
||||
*/
|
||||
|
||||
#ifndef PIXEL_HPP_
|
||||
#define PIXEL_HPP_
|
||||
#ifndef CIRCLE_HPP_
|
||||
#define CIRCLE_HPP_
|
||||
|
||||
#include <raylib.h>
|
||||
#include "Drawables/Drawable.hpp"
|
||||
|
||||
namespace Ray {
|
||||
struct Circle: public Drawable
|
||||
class Circle: public Drawable
|
||||
{
|
||||
int radius;
|
||||
public:
|
||||
Circle(Vector2 topLeftPos, int radius, Color);
|
||||
Circle(int topLeftX, int topLeftY, int radius, Color);
|
||||
Circle(const Circle &);
|
||||
|
||||
Circle &operator=(const Circle &);
|
||||
|
||||
~Circle() = default;
|
||||
|
||||
int getRadius(void) const;
|
||||
|
||||
bool collide(const Rectangle &);
|
||||
bool collide(const Line &);
|
||||
bool collide(const Point &);
|
||||
bool collide(const Circle &);
|
||||
|
||||
private:
|
||||
int radius;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -5,16 +5,37 @@
|
||||
** Pixel
|
||||
*/
|
||||
|
||||
#ifndef PIXEL_HPP_
|
||||
#define PIXEL_HPP_
|
||||
#ifndef LINE_HPP_
|
||||
#define LINE_HPP_
|
||||
|
||||
#include <raylib.h>
|
||||
#include "Drawables/Drawable.hpp"
|
||||
|
||||
namespace Ray {
|
||||
struct Line: public Drawable
|
||||
class Line: public Drawable
|
||||
{
|
||||
Vector2 dimensions;
|
||||
public:
|
||||
Line(Vector2 position, int length, Color);
|
||||
Line(int x, int y, int length, Color);
|
||||
Line(const Line &);
|
||||
|
||||
Line &operator=(const Line &);
|
||||
|
||||
~Line() = default;
|
||||
|
||||
int getLength(void) const;
|
||||
int getRotation(void) const;
|
||||
|
||||
Line &setLength(int);
|
||||
Line &setRotation(int);
|
||||
|
||||
bool collide(const Rectangle &);
|
||||
bool collide(const Line &);
|
||||
bool collide(const Point &);
|
||||
bool collide(const Circle &);
|
||||
private:
|
||||
int _length;
|
||||
int _rotation;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2021
|
||||
** Bomberman
|
||||
** File description:
|
||||
** Pixel
|
||||
*/
|
||||
|
||||
#ifndef PIXEL_HPP_
|
||||
#define PIXEL_HPP_
|
||||
|
||||
#include <raylib.h>
|
||||
#include "Drawables/Drawable.hpp"
|
||||
|
||||
namespace Ray {
|
||||
struct Point: public Drawable
|
||||
{
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* !PIXEL_HPP_ */
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2021
|
||||
** Bomberman
|
||||
** File description:
|
||||
** Pixel
|
||||
*/
|
||||
|
||||
#ifndef PIXEL_HPP_
|
||||
#define PIXEL_HPP_
|
||||
|
||||
#include <raylib.h>
|
||||
#include "Drawables/Drawable.hpp"
|
||||
|
||||
namespace Ray {
|
||||
class Point: public Drawable
|
||||
{
|
||||
public:
|
||||
Point(Vector2 position, Color);
|
||||
Point(int x, int y, Color);
|
||||
Point(const Point &);
|
||||
|
||||
Point &operator=(const Point &);
|
||||
|
||||
~Point() = default;
|
||||
|
||||
bool collide(const Rectangle &);
|
||||
bool collide(const Line &);
|
||||
bool collide(const Point &);
|
||||
bool collide(const Circle &);
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* !PIXEL_HPP_ */
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2021
|
||||
** Bomberman
|
||||
** File description:
|
||||
** Pixel
|
||||
*/
|
||||
|
||||
#ifndef RECTANGLE_HPP_
|
||||
#define RECTANGLE_HPP_
|
||||
|
||||
#include <raylib.h>
|
||||
#include "Drawables/Drawable.hpp"
|
||||
|
||||
namespace Ray {
|
||||
class Rectangle: public Drawable
|
||||
{
|
||||
public:
|
||||
Rectangle(Vector2 position, Vector2 dimensions,int length, Color);
|
||||
Rectangle(int x, int y, int width, int height, int length, Color);
|
||||
Rectangle(const Rectangle &);
|
||||
|
||||
Rectangle &operator=(const Rectangle &);
|
||||
|
||||
~Rectangle() = default;
|
||||
|
||||
const Vector2 &getDimensions(void);
|
||||
|
||||
Rectangle &setDimensions(const Vector2 &position);
|
||||
Rectangle &setDimensions(int x, int y);
|
||||
|
||||
bool collide(const Rectangle &);
|
||||
bool collide(const Line &);
|
||||
bool collide(const Point &);
|
||||
bool collide(const Circle &);
|
||||
private:
|
||||
Vector2 _dimensions;
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* !PIXEL_HPP_ */
|
||||
@@ -10,16 +10,36 @@
|
||||
|
||||
#include <raylib.h>
|
||||
#include <Vector.hpp>
|
||||
#include "Drawables/Basic/Circle.hpp"
|
||||
#include "Drawables/Basic/Line.hpp"
|
||||
#include "Drawables/Basic/Rectangle.hpp"
|
||||
#include "Drawables/Basic/Point.hpp"
|
||||
|
||||
namespace Ray {
|
||||
struct Drawable
|
||||
class Drawable
|
||||
{
|
||||
//top-left position
|
||||
Vector2 position;
|
||||
public:
|
||||
Drawable(Vector2 position, Color color);
|
||||
Drawable(int x, int y, Color color);
|
||||
virtual ~Drawable() = 0;
|
||||
|
||||
Color color;
|
||||
const Vector2 &getPosition(void) const;
|
||||
const Color &getColor(void) const;
|
||||
|
||||
Drawable &setPosition(const Vector2 &position);
|
||||
Drawable &setPosition(int x, int y);
|
||||
Drawable &setColor(const Color &color) const;
|
||||
|
||||
virtual bool collide(const Rectangle &) = 0;
|
||||
virtual bool collide(const Line &) = 0;
|
||||
virtual bool collide(const Point &) = 0;
|
||||
virtual bool collide(const Circle &) = 0;
|
||||
|
||||
private:
|
||||
//top-left position
|
||||
Vector2 _position;
|
||||
Color _color;
|
||||
|
||||
virtual ~Drawable() = 0;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <string>
|
||||
#include "Vector.hpp"
|
||||
#include "Keyboard.hpp"
|
||||
#include "Drawable.hpp"
|
||||
|
||||
namespace Ray {
|
||||
class Window {
|
||||
@@ -66,6 +67,11 @@ class Window {
|
||||
// Must be called after last draw of iteration
|
||||
void endDrawing(void);
|
||||
|
||||
void drawRectangle(const Rectangle &);
|
||||
void drawLine(const Line &);
|
||||
void drawPoint(const Point &);
|
||||
void drawCircle(const Circle &);
|
||||
|
||||
private:
|
||||
Ray::Vector2 _dimensions;
|
||||
std::string _title;
|
||||
|
||||
Reference in New Issue
Block a user