SANDAL2
A SDL2 Wrapper in C
Classes | Typedefs | Functions
Clickable.h File Reference

Generic hitboxes either polygonial, elliptic or a mixe of both. More...

#include <math.h>
#include <stdlib.h>
Include dependency graph for Clickable.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Line
 Represente a line which delimitate a hittable surface from a none hittable one. More...
 
struct  Circle
 Represente a hittable ellipse. More...
 
struct  Clickable
 Represente a hit boxe which is a collection of Line (defining a convexe polygon) and Circle. More...
 
struct  ListClickable
 Collection of hit boxes. More...
 

Typedefs

typedef struct Line Line
 
typedef struct Circle Circle
 
typedef struct Clickable Clickable
 

Functions

Clickable * initClickable ()
 Generate an empty hitbox. More...
 
int addLine (Clickable *hb, double a, double b, double c, int side)
 add a line to the hitbox side*(ax+by) > side*c More...
 
int addCircle (Clickable *hb, double x, double y, double rX, double rY, double theta)
 add an ellipse to the hitbox More...
 
int delLine (Clickable *hb, double a, double b, double c, int side)
 remove a line from the hitbox More...
 
int delCircle (Clickable *hb, double x, double y, double rX, double rY, double theta)
 remove an ellipse from the hitbox More...
 
int hitClickable (Clickable *hb, double x, double y)
 tells if (x,y) touch the hitbox More...
 
Clickable * rectangleClickable (double x1, double y1, double x2, double y2)
 generate a rectangulare shapped Clickable More...
 
Clickable * ellipseClickable (double x, double y, double rX, double rY, double theta)
 generate an ellipse shapped Clickable More...
 
void freeClickable (Clickable *hb)
 free a hit boxe's memory More...
 
void freeListClickable (ListClickable *l)
 free the memory of a list of hit boxe More...
 
ListClickable * initListClickable ()
 initialise an empty list of hit boxes More...
 
int addClickable (ListClickable *l, Clickable *hb, int blocking)
 add a hit boxe to a list of hit boxes More...
 
int delClickable (ListClickable *l, Clickable *hb, int blocking)
 remove a hit boxe to a list of hit boxes More...
 
int initIteratorListClickable (ListClickable *l)
 initialise the iterator of the list of non blocking hit boxes More...
 
Clickable * nextClickable (ListClickable *l)
 getter of the current non blocking element of the iterator and setter of the next element More...
 
int initIteratorListClickableBlocking (ListClickable *l)
 initialise the iterator of the list of blocking hit boxes More...
 
Clickable * nextClickableBlocking (ListClickable *l)
 getter of the current blocking element of the iterator and setter of the next element More...
 
int hitListClickable (ListClickable *l, double x, double y)
 tells if (x,y) touch one of the hitboxes More...
 

Detailed Description

Generic hitboxes either polygonial, elliptic or a mixe of both.

Author
Baptiste PRUNIER (KLEVH)

Function Documentation

◆ addCircle()

int addCircle ( Clickable *  hb,
double  x,
double  y,
double  rX,
double  rY,
double  theta 
)

add an ellipse to the hitbox

Parameters
hb: hit boxe to which the line will be added
x: abscissa coordinate of the center of the ellipse
y: ordinate coordinate of the center of the ellipse
rX: size of the radius parallel to the abscissa axis
rY: size of the radius parallel to the ordinate axis
theta: rotation of the ellipse (in degree)
Returns
0 if the ellipse was correctly added, 1 in the other case

◆ addClickable()

int addClickable ( ListClickable *  l,
Clickable *  hb,
int  blocking 
)

add a hit boxe to a list of hit boxes

Parameters
l: list of hit boxes
hb: hit boxe
Returns
0 if the hit boxe was succesfully added, 1 if not

◆ addLine()

int addLine ( Clickable *  hb,
double  a,
double  b,
double  c,
int  side 
)

add a line to the hitbox side*(ax+by) > side*c

Parameters
hb: hit boxe to which the line will be added
a: a in the equation of the line ax+by=c
b: b in the equation of the line ax+by=c
c: c in the equation of the line ax+by=c
side: indicator of the side of the line which is hittable (-1 : ax+by<c, 1 : ax+by>c)
Returns
0 if the line was correctly added, 1 in the other case

◆ delCircle()

int delCircle ( Clickable *  hb,
double  x,
double  y,
double  rX,
double  rY,
double  theta 
)

remove an ellipse from the hitbox

Parameters
hb: hit boxe to which the line will be removed
x: abscissa coordinate of the center of the ellipse
y: ordinate coordinate of the center of the ellipse
rX: size of the radius parallel to the abscissa axis
rY: size of the radius parallel to the ordinate axis
theta: rotation of the ellipse (in degree)
Returns
0 if the ellipse was correctly removed, 1 in the other case

◆ delClickable()

int delClickable ( ListClickable *  l,
Clickable *  hb,
int  blocking 
)

remove a hit boxe to a list of hit boxes

Parameters
l: list of hit boxes
hb: hit boxe
blocking: 0 if the hit boxe is hittable, 1 if it block other hit boxes
Returns
0 if the hit boxe was succesfully removed, 1 if not

◆ delLine()

int delLine ( Clickable *  hb,
double  a,
double  b,
double  c,
int  side 
)

remove a line from the hitbox

Parameters
hb: hit boxe to which the line will be removed
a: a in the equation of the line ax+by=c
b: b in the equation of the line ax+by=c
c: c in the equation of the line ax+by=c
side: indicator of the side of the line which is hittable (-1 : ax+by<c, 1 : ax+by>c)
Returns
0 if the line was correctly removed, 1 in the other case

◆ ellipseClickable()

Clickable* ellipseClickable ( double  x,
double  y,
double  rX,
double  rY,
double  theta 
)

generate an ellipse shapped Clickable

Parameters
x: abscissa coordinate of the center of the ellipse
y: ordinate coordinate of the center of the ellipse
rX: size of the radius parallel to the abscissa axis
rY: size of the radius parallel to the ordinate axis
theta: rotation of the ellipse (in degree)
Returns
An elliptical hit boxe

◆ freeClickable()

void freeClickable ( Clickable *  hb)

free a hit boxe's memory

Parameters
hb: hit boxe to be freed

◆ freeListClickable()

void freeListClickable ( ListClickable *  l)

free the memory of a list of hit boxe

Parameters
l: list of hit boxe to be freed

◆ hitClickable()

int hitClickable ( Clickable *  hb,
double  x,
double  y 
)

tells if (x,y) touch the hitbox

Parameters
hb: hit boxe that you are trying to touch
x: abscissa coordinate of the point trying to touch the hit boxe
y: ordinate coordinate of the point trying to touch the hit boxe
Returns
1 if the hit boxe is hit, 0 in the other case

◆ hitListClickable()

int hitListClickable ( ListClickable *  l,
double  x,
double  y 
)

tells if (x,y) touch one of the hitboxes

Parameters
l: list of hit boxes
x: abscissa coordinate of the point trying to touch the hit boxe
y: ordinate coordinate of the point trying to touch the hit boxe
Returns
1 if one of the hit boxes was hit, 0 if not

◆ initClickable()

Clickable* initClickable ( )

Generate an empty hitbox.

Returns
return an empty hitbox

◆ initIteratorListClickable()

int initIteratorListClickable ( ListClickable *  l)

initialise the iterator of the list of non blocking hit boxes

Parameters
l: list of hit boxes
Returns
1 if the iterator was succesfully initialised, 0 if not

◆ initIteratorListClickableBlocking()

int initIteratorListClickableBlocking ( ListClickable *  l)

initialise the iterator of the list of blocking hit boxes

Parameters
l: list of hit boxes
Returns
1 if the iterator was succesfully initialised, 0 if not

◆ initListClickable()

ListClickable* initListClickable ( )

initialise an empty list of hit boxes

Returns
an empty list of hit boxes

◆ nextClickable()

Clickable* nextClickable ( ListClickable *  l)

getter of the current non blocking element of the iterator and setter of the next element

Returns
the current hit boxes

◆ nextClickableBlocking()

Clickable* nextClickableBlocking ( ListClickable *  l)

getter of the current blocking element of the iterator and setter of the next element

Returns
the current hit boxes

◆ rectangleClickable()

Clickable* rectangleClickable ( double  x1,
double  y1,
double  x2,
double  y2 
)

generate a rectangulare shapped Clickable

Parameters
x1: abscissa coordinate of the top left point of the rectangle
y1: ordinate coordinate of the top left point of the rectangle
x2: abscissa coordinate of the bottom right point of the rectangle
y2: ordinate coordinate of the bottom right point of the rectangle
Returns
A rectangulare hit boxe defined by the points (x1,y1) and (x2,y2)