Dragonfly 4.20
A text-based game engine
Box.h
1///
2/// A 2-d bounding box
3///
4
5#ifndef __BOX_H__
6#define __BOX_H__
7
8// System includes.
9#include <sstream>
10
11// Game includes.
12#include "Vector.h"
13
14namespace df {
15
16class Box {
17
18 private:
19 Vector m_corner; ///< Upper left corner of box.
20 float m_horizontal; ///< Horizontal dimension.
21 float m_vertical; ///< Vertical dimension.
22
23 public:
24 /// Create box with upper-left corner, horiz and vert sizes.
25 Box(Vector init_corner, float init_horizontal, float init_vertical);
26
27 /// Create box with (0,0) for corner, and 0 for horiz and vert.
28 Box();
29
30 /// Set upper left corner of box.
31 void setCorner(Vector new_corner);
32
33 /// Get upper left corner of box.
35
36 /// Set horizontal size of box.
37 void setHorizontal(float new_horizontal);
38
39 /// Get horizontal size of box.
40 float getHorizontal() const;
41
42 /// Set vertical size of box.
43 void setVertical(float new_vertical);
44
45 /// Get vertical size of box.
46 float getVertical() const;
47
48 /// Return attributes as string.
49 std::string toString() const;
50
51 /// Compare two boxes.
52 bool operator==(const Box &other) const;
53 bool operator!=(const Box &other) const;
54
55 /// Draw box outline in pixels.
56 void draw();
57
58 /// Serialize attributes to stream.
59 /// Return 0 if ok, else -1.
60 int serialize(std::stringstream *p_ss) const;
61
62 /// Deserialize attributes from stream.
63 /// Return 0 if ok, else -1.
64 int deserialize(std::stringstream *p_ss);
65};
66
67
68} // end of namespace df
69#endif //__BOX_H__
Definition: Box.h:16
int serialize(std::stringstream *p_ss) const
Serialize attributes to stream.
void setVertical(float new_vertical)
Set vertical size of box.
std::string toString() const
Return attributes as string.
float getVertical() const
Get vertical size of box.
Vector getCorner() const
Get upper left corner of box.
Box(Vector init_corner, float init_horizontal, float init_vertical)
Create box with upper-left corner, horiz and vert sizes.
Vector m_corner
Upper left corner of box.
Definition: Box.h:19
void draw()
Draw box outline in pixels.
float m_vertical
Vertical dimension.
Definition: Box.h:21
float getHorizontal() const
Get horizontal size of box.
void setCorner(Vector new_corner)
Set upper left corner of box.
int deserialize(std::stringstream *p_ss)
Deserialize attributes from stream.
float m_horizontal
Horizontal dimension.
Definition: Box.h:20
void setHorizontal(float new_horizontal)
Set horizontal size of box.
Box()
Create box with (0,0) for corner, and 0 for horiz and vert.
bool operator==(const Box &other) const
Compare two boxes.
Definition: Vector.h:12
An animation for a sprite.
Definition: Animation.h:15