Dragonfly 4.20
A text-based game engine
Shape.h
1///
2/// A single-space, 2d shape for drawing.
3///
4
5#ifndef __SHAPE_H__
6#define __SHAPE_H__
7
8// System includes.
9#include <SFML/Graphics/CircleShape.hpp>
10
11// Engine includes.
12#include "Color.h"
13#include "Vector.h"
14
15namespace df {
16
17enum ShapeType {
18 UNDEFINED_SHAPE = -1,
19 CIRCLE,
20 SQUARE,
21 TRIANGLE,
22};
23
24class Shape {
25
26 private:
27 Color m_color; ///< Shape color.
28 unsigned char m_r,m_g,m_b; ///< RGB colors used if color is CUSTOM.
29 ShapeType m_type; ///< Type of shape.
30 float m_size; ///< Radius size (in pixels).
31 unsigned char m_opacity; ///< Opacity (transparent) 0 to 255 (opaque).
32
33 public:
34
35 /// Default is Circle, df::WHITE, size 1 character.
37
38 /// Set size (in pixels).
39 void setSize(float new_size);
40
41 /// Get size (in pixels).
42 float getSize() const;
43
44 /// Set type.
45 void setType(ShapeType new_type);
46
47 /// Get type.
48 ShapeType getType() const;
49
50 /// Set color, where input is Dragonfly Color.
51 void setColor(Color new_color);
52
53 /// Set color, where input is RGB.
54 void setColor(unsigned char r, unsigned char g, unsigned char b);
55
56 /// Get color. Returns Dragonfly Color.
57 Color getColor() const;
58
59 /// Set opacity (0 is transparent, 255 is opaque).
60 void setOpacity(unsigned char new_opacity);
61
62 /// Get opacity (0 is transparent, 255 is opaque).
63 unsigned char getOpacity() const;
64
65 /// Draw self at given world position.
66 void draw(Vector world_pos);
67
68 // Serialize attributes to stream.
69 // Return 0 if ok, else -1.
70 int serialize(std::stringstream *p_ss) const;
71
72 // Deserialize attributes from stream.
73 // Return 0 if ok, else -1.
74 int deserialize(std::stringstream *p_ss);
75
76 /// Compare two Shapes.
77 bool operator==(const Shape &s);
78 bool operator!=(const Shape &s);
79
80 // Return attributes as string.
81 std::string toString() const;
82};
83
84} // end of namespace df
85#endif //__SHAPE_H__
Definition: Shape.h:24
float getSize() const
Get size (in pixels).
unsigned char m_opacity
Opacity (transparent) 0 to 255 (opaque).
Definition: Shape.h:31
void setType(ShapeType new_type)
Set type.
float m_size
Radius size (in pixels).
Definition: Shape.h:30
Shape()
Default is Circle, df::WHITE, size 1 character.
unsigned char m_b
RGB colors used if color is CUSTOM.
Definition: Shape.h:28
void draw(Vector world_pos)
Draw self at given world position.
unsigned char getOpacity() const
Get opacity (0 is transparent, 255 is opaque).
bool operator==(const Shape &s)
Compare two Shapes.
Color getColor() const
Get color. Returns Dragonfly Color.
void setColor(unsigned char r, unsigned char g, unsigned char b)
Set color, where input is RGB.
void setColor(Color new_color)
Set color, where input is Dragonfly Color.
void setOpacity(unsigned char new_opacity)
Set opacity (0 is transparent, 255 is opaque).
Color m_color
Shape color.
Definition: Shape.h:27
void setSize(float new_size)
Set size (in pixels).
ShapeType getType() const
Get type.
ShapeType m_type
Type of shape.
Definition: Shape.h:29
Definition: Vector.h:12
An animation for a sprite.
Definition: Animation.h:15
Color
Colors Dragonfly recognizes.
Definition: Color.h:11