FreeRTOS Emulator with SDL2 Based Graphics and Input Library  1.0
A POSIX wrapper to run FreeRTOS on an x86 machine with some basic input and output libraries aimed at making teaching FreeRTOS simpler.
gfx_ball.h
Go to the documentation of this file.
1 
25 #ifndef __GFX_BALL_H__
26 #define __GFX_BALL_H__
27 
28 #include "gfx_draw.h"
29 
44 typedef void (*callback_t)(void *args);
45 
66 typedef struct ball {
68 
69  signed short x;
70  signed short y;
72  float f_x;
73  float f_y;
75  float dx;
76  float dy;
78  float max_speed;
81  unsigned int colour;
83  signed short radius;
86  void *args;
88 
113 typedef struct wall {
114  signed short x1;
115  signed short y1;
117  signed short w;
118  signed short h;
120  signed short x2;
121  signed short y2;
123  float dampening;
126  unsigned int colour;
129  void *args;
131 
152 ball_t *gfxCreateBall(signed short initial_x, signed short initial_y,
153  unsigned int colour, signed short radius, float max_speed,
154  callback_t callback, void *args, gfx_image_handle_t sprite);
155 
170 wall_t *gfxCreateWall(signed short x1, signed short y1, signed short w,
171  signed short h, float dampening, unsigned int colour,
172  callback_t callback, void *args);
173 
183 #define SET_WALL_X 0b1
184 
185 #define SET_WALL_Y 0b10
186 
187 #define SET_WALL_WIDTH 0b100
188 
189 #define SET_WALL_HEIGHT 0b1000
190 
191 #define SET_WALL_AXES SET_WALL_X | SET_WALL_Y
192 
193 #define SET_WALL_SIZE SET_WALL_WIDTH | SET_WALL_HEIGHT
194 
195 #define SET_WALL_ALL SET_WALL_AXES | SET_WALL_SIZE
196 
211 void gfxSetWallProperty(wall_t *wall, signed short x, signed short y,
212  signed short width, signed short height,
213  unsigned char flags);
214 
227 #define SET_BALL_SPEED_X 0b1
228 
234 #define SET_BALL_SPEED_Y 0b10
235 
241 #define SET_BALL_SPEED_MAX 0b100
242 
248 #define SET_BALL_SPEED_AXES SET_BALL_SPEED_X | SET_BALL_SPEED_Y
249 
256 #define SET_BALL_SPEED_ALL SET_BALL_SPEED_AXES | SET_BALL_SPEED_MAX
270 void gfxSetBallSpeed(ball_t *ball, float dx, float dy, float max_speed,
271  unsigned char flags);
272 
281 void gfxSetBallLocation(ball_t *ball, signed short x, signed short y);
282 
293 signed char gfxCheckBallCollisions(ball_t *ball, callback_t callback, void *args);
294 
310 void gfxUpdateBallPosition(ball_t *ball, unsigned int milli_seconds);
311 
313 #endif
void gfxSetBallLocation(ball_t *ball, signed short x, signed short y)
Sets the location of the ball.
Definition: gfx_ball.c:143
void gfxSetBallSpeed(ball_t *ball, float dx, float dy, float max_speed, unsigned char flags)
Sets the speed of the ball.
Definition: gfx_ball.c:123
void gfxSetWallProperty(wall_t *wall, signed short x, signed short y, signed short width, signed short height, unsigned char flags)
Sets one or more properties of a wall.
Definition: gfx_ball.c:76
wall_t * gfxCreateWall(signed short x1, signed short y1, signed short w, signed short h, float dampening, unsigned int colour, callback_t callback, void *args)
Creates a wall object.
void(* callback_t)(void *args)
Callback function attached to an object.
Definition: gfx_ball.h:44
struct wall wall_t
Object to represent a wall that balls bounce off of.
void gfxUpdateBallPosition(ball_t *ball, unsigned int milli_seconds)
Updates the position of the ball.
Definition: gfx_ball.c:166
struct ball ball_t
Object to represent a ball that bounces off walls.
signed char gfxCheckBallCollisions(ball_t *ball, callback_t callback, void *args)
Checks if a ball is currently collided with other objects.
ball_t * gfxCreateBall(signed short initial_x, signed short initial_y, unsigned int colour, signed short radius, float max_speed, callback_t callback, void *args, gfx_image_handle_t sprite)
Creates a ball object.
void * gfx_image_handle_t
Handle used to reference loaded images, an invalid image will have a NULL handle.
Definition: gfx_draw.h:130
Object to represent a ball that bounces off walls.
Definition: gfx_ball.h:66
float dx
Definition: gfx_ball.h:75
void * args
Definition: gfx_ball.h:86
float max_speed
Definition: gfx_ball.h:78
signed short y
Definition: gfx_ball.h:70
signed short x
Definition: gfx_ball.h:69
gfx_image_handle_t sprite
Definition: gfx_ball.h:67
float f_y
Definition: gfx_ball.h:73
signed short radius
Definition: gfx_ball.h:83
unsigned int colour
Definition: gfx_ball.h:81
float dy
Definition: gfx_ball.h:76
float f_x
Definition: gfx_ball.h:72
callback_t callback
Definition: gfx_ball.h:85
Object to represent a wall that balls bounce off of.
Definition: gfx_ball.h:113
float dampening
Definition: gfx_ball.h:123
unsigned int colour
Definition: gfx_ball.h:126
signed short y2
Definition: gfx_ball.h:121
signed short y1
Definition: gfx_ball.h:115
signed short x1
Definition: gfx_ball.h:114
signed short w
Definition: gfx_ball.h:117
void * args
Definition: gfx_ball.h:129
callback_t callback
Definition: gfx_ball.h:128
signed short x2
Definition: gfx_ball.h:120
signed short h
Definition: gfx_ball.h:118