Dragonfly 4.19
A text-based game engine
utility.h
1//
2// Utility functions to support Dragonfly and its games.
3//
4// Functions here do not use any attributes of any classes, so
5// can stand alone.
6//
7
8#ifndef __UTILITY_H__
9#define __UTILITY_H__
10
11// Engine includes
12#include "Box.h"
13#include "Circle.h"
14#include "EventKeyboard.h"
15#include "Line.h"
16#include "Object.h"
17#include "Particle.h"
18#include "Precipitation.h"
19#include "Vector.h"
20
21namespace df {
22
23/// Return true if value is between min and max (inclusive).
24bool valueInRange(float value, float min, float max);
25
26/// Convert relative bounding Box for Object to absolute world Box.
28
29/// Convert relative bounding Box for Object to absolute world Box
30/// at postion where.
31Box getWorldBox(const Object *p_o, Vector where);
32
33/// Return distance between any two positions.
34float distance(Vector p1, Vector p2);
35
36/// Return distance between any two Objects.
37/// Return -1.0 if error.
38float distance(Object *p_o1, Object *p_o2);
39
40/// Return true of position is within Box.
42
43/// Return true if Box 1 completely contains Box 2.
44bool boxContainsBox(Box b1, Box b2);
45
46/// Return true if Line segments intersect.
47/// (Parallel line segments don't intersect).
48/// (Co-linear lines will NOT intersect).
49bool lineIntersectsLine(Line line1, Line line2);
50
51/// Return true if Line segment intersects Box.
53
54/// Return true if Boxes intersect.
55bool boxIntersectsBox(Box box1, Box box2);
56
57/// Return true if Circle intersects or contains Box.
59
60/// Launch splash screen. Return 0 if ok, else -1.
61int splash();
62
63/// Returns pretty-formatted time as char * string.
65
66/// Convert world position to view position.
68
69/// Convert view position to world position.
71
72/// Convert integer to string, returning string.
73std::string toString(int i);
74
75/// Convert float to string, returning string.
76std::string toString(float f);
77
78/// Convert character to string, returning string.
79std::string toString(char c);
80
81/// Convert boolean to string, returning string.
82std::string toString(bool b);
83
84/// Convert Dragonfly Shape to string, returning string.
85std::string toString(Shape shape);
86
87/// Convert Dragonfly Color to string, returning string.
88std::string toString(Color color);
89
90/// Convert Path nodes (not index) to string, returning string.
91std::string toString(Path path);
92
93/// Convert Dragonfly key to string, returning string.
94std::string toString(Keyboard::Key key_val);
95
96/// Match key:value pair in string in str, returning value.
97/// Pairs separated by commas (,).
98/// If str is empty, use previously parsed string str.
99/// All whitespace is ignored.
100/// Return empty string if no match.
101std::string match(std::string str, std::string find);
102
103/// Add particles. Each parameter has average and spread.
104/// count - number to add
105/// position - location
106/// direction - direction to move [(0,0) for random]
107/// size - size (pixels)
108/// speed - speed (spaces/tick)
109/// age - age (ticks)
110/// opacity - how "see through" [0-255, 0 is transparent]
111/// r, g, b - color in RGB values
112/// Particle class - class to add (default is PARTICLE).
113/// Return 0 if ok, else -1.
114int addParticles(int count, int count_spread,
115 Vector position, float position_spread,
116 Vector direction, float direction_spread,
117 float size, float size_spread,
118 float speed, float speed_spread,
119 int age, int age_spread,
120 unsigned char opacity, char opacity_spread,
121 unsigned char r, unsigned char g, unsigned char b,
122 unsigned char color_spread,
123 ParticleClass particle_class=PARTICLE);
124
125/// Add particles of specific type.
126/// type - type of particle: SMOKE, SPARKS, RINGS, FIREWORKS.
127/// position - location
128/// scale - scale size (default 1.0)
129/// color - dragonfly color to use (default 'built-in')
130/// Return 0 if ok, else -1.
132 float scale=1.0, Color color=CUSTOM);
133
134/// Add environment particles of specific type.
135/// type - type of particle: RAIN, SNOW, STARFIELD.
136/// direction - direction particle travels: UP, DOWN, LEFT, RIGHT.
137/// scale - scale size (default 1.0)
138/// color - dragonfly color to use (default 'built-in')
139/// Return 0 if ok, else -1.
140int addParticles(PrecipitationType type, Direction direction, float scale=1.0,
141 Color color=CUSTOM);
142
143/// Set RGB color based on DF color.
144void colorToRGB(Color color, unsigned char &r, unsigned char &g,
145 unsigned char &b);
146
147/// Return SFML color based on DF color.
148sf::Color colorToSFML(Color color);
149
150/// Return normal between two colliding Objects.
151/// Object 1 caused collision with Object 2.
152/// Return (0,0) if no normal (no collision or
153/// Object 1 inside Object 2).
154Vector getNormal(const Object *p_o1, const Object *p_o2);
155
156
157
158} // end of namespace df
159#endif // __UTILITY_H__
Definition: Box.h:12
Definition: Circle.h:12
Definition: Line.h:12
Definition: Object.h:59
Definition: Path.h:17
Definition: Shape.h:24
Definition: Vector.h:12
Key
Keys Dragonfly recognizes.
Definition: EventKeyboard.h:25
An animation for a sprite.
Definition: Animation.h:15
Vector getNormal(const Object *p_o1, const Object *p_o2)
Return normal between two colliding Objects.
bool valueInRange(float value, float min, float max)
Return true if value is between min and max (inclusive).
bool circleIntersectsBox(Circle circle, Box b)
Return true if Circle intersects or contains Box.
int splash()
Launch splash screen. Return 0 if ok, else -1.
std::string match(std::string str, std::string find)
Match key:value pair in string in str, returning value.
int addParticles(int count, int count_spread, Vector position, float position_spread, Vector direction, float direction_spread, float size, float size_spread, float speed, float speed_spread, int age, int age_spread, unsigned char opacity, char opacity_spread, unsigned char r, unsigned char g, unsigned char b, unsigned char color_spread, ParticleClass particle_class=PARTICLE)
Add particles.
bool boxContainsPosition(Box b, Vector p)
Return true of position is within Box.
sf::Color colorToSFML(Color color)
Return SFML color based on DF color.
void colorToRGB(Color color, unsigned char &r, unsigned char &g, unsigned char &b)
Set RGB color based on DF color.
Color
Colors Dragonfly recognizes.
Definition: Color.h:11
std::string toString(int i)
Convert integer to string, returning string.
Vector viewToWorld(Vector view_pos)
Convert view position to world position.
bool boxContainsBox(Box b1, Box b2)
Return true if Box 1 completely contains Box 2.
bool lineIntersectsBox(Line line, Box b)
Return true if Line segment intersects Box.
char * getTimeString()
Returns pretty-formatted time as char * string.
ParticleClass
Particle classes.
Definition: Particle.h:26
ParticleType
Particle types.
Definition: Particle.h:17
bool lineIntersectsLine(Line line1, Line line2)
Return true if Line segments intersect.
Direction
Directions.
Definition: Particle.h:33
float distance(Vector p1, Vector p2)
Return distance between any two positions.
Box getWorldBox(const Object *p_o)
Convert relative bounding Box for Object to absolute world Box.
bool boxIntersectsBox(Box box1, Box box2)
Return true if Boxes intersect.
Vector worldToView(Vector world_pos)
Convert world position to view position.
PrecipitationType
Precipitation types.
Definition: Precipitation.h:14