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.c File Reference

API to create balls and walls that interact with each other on a 2D plane. More...

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "gfx_ball.h"
#include "gfx_sound.h"

Classes

struct  walls
 

Macros

#define SET_BALL_COORD(AXIS, VAL)
 
#define HORIZONTAL   0b1
 
#define VERTICAL   0b10
 
#define COLLIDE_WALL   1
 
#define COLLIDE_BALL   2
 
#define COLLIDE_WALL_TOP   1
 
#define COLLIDE_WALL_BOTTOM   2
 
#define COLLIDE_WALL_LEFT   3
 
#define COLLIDE_WALL_RIGHT   4
 
#define BALL_LEFT_POINT_X   ball->f_x - ball->radius
 
#define BALL_LEFT_POINT_Y   ball->f_y
 
#define BALL_RIGHT_POINT_X   ball->f_x + ball->radius
 
#define BALL_RIGHT_POINT_Y   ball->f_y
 
#define BALL_TOP_POINT_X   ball->f_x
 
#define BALL_TOP_POINT_Y   ball->f_y - ball->radius
 
#define BALL_BOTTOM_POINT_X   ball->f_x
 
#define BALL_BOTTOM_POINT_Y   ball->f_y + ball->radius
 
#define WALL   ((wall_t *)object)
 
#define BALL   ((ball_t *)object)
 

Typedefs

typedef struct walls walls_t
 

Functions

wall_tgfxCreateWall (signed short x1, signed short y1, signed short w, signed short h, float dampening, unsigned int colour, void(*callback)(void *), void *args)
 
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. More...
 
ball_tgfxCreateBall (signed short initial_x, signed short initial_y, unsigned int colour, signed short radius, float max_speed, void(*callback)(void *), void *args, gfx_image_handle_t sprite)
 
void gfxSetBallSpeed (ball_t *ball, float dx, float dy, float max_speed, unsigned char flags)
 Sets the speed of the ball. More...
 
void gfxSetBallLocation (ball_t *ball, signed short x, signed short y)
 Sets the location of the ball. More...
 
void gfxUpdateBallPosition (ball_t *ball, unsigned int milli_seconds)
 Updates the position of the ball. More...
 
void _changeBallDirection (ball_t *ball, signed char direction, float dampening)
 
signed char _collideWall (ball_t *ball, wall_t *wall, unsigned char collision_type, void(*callback)(void *), void *args)
 
signed char _handleCollision (ball_t *ball, void *object, unsigned char flag, void(*callback)(void *), void *args)
 
signed char _checkBallCollisionsWithWalls (ball_t *ball, void(*callback)(void *), void *args)
 
unsigned char _checkBallCollisionsWithBalls (ball_t *ball)
 
signed char gfxCheckBallCollisions (ball_t *ball, void(*callback)(void *), void *args)
 

Variables

walls_t walls = { 0 }
 

Detailed Description

API to create balls and walls that interact with each other on a 2D plane.

Author
Alex Hoffman
Date
27 August 2019
----------------------------------------------------------------------
Copyright (C) Alexander Hoffman, 2019
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------

Macro Definition Documentation

◆ BALL

#define BALL   ((ball_t *)object)

◆ BALL_BOTTOM_POINT_X

#define BALL_BOTTOM_POINT_X   ball->f_x

◆ BALL_BOTTOM_POINT_Y

#define BALL_BOTTOM_POINT_Y   ball->f_y + ball->radius

◆ BALL_LEFT_POINT_X

#define BALL_LEFT_POINT_X   ball->f_x - ball->radius

◆ BALL_LEFT_POINT_Y

#define BALL_LEFT_POINT_Y   ball->f_y

◆ BALL_RIGHT_POINT_X

#define BALL_RIGHT_POINT_X   ball->f_x + ball->radius

◆ BALL_RIGHT_POINT_Y

#define BALL_RIGHT_POINT_Y   ball->f_y

◆ BALL_TOP_POINT_X

#define BALL_TOP_POINT_X   ball->f_x

◆ BALL_TOP_POINT_Y

#define BALL_TOP_POINT_Y   ball->f_y - ball->radius

◆ COLLIDE_BALL

#define COLLIDE_BALL   2

◆ COLLIDE_WALL

#define COLLIDE_WALL   1

◆ COLLIDE_WALL_BOTTOM

#define COLLIDE_WALL_BOTTOM   2

◆ COLLIDE_WALL_LEFT

#define COLLIDE_WALL_LEFT   3

◆ COLLIDE_WALL_RIGHT

#define COLLIDE_WALL_RIGHT   4

◆ COLLIDE_WALL_TOP

#define COLLIDE_WALL_TOP   1

◆ HORIZONTAL

#define HORIZONTAL   0b1

◆ SET_BALL_COORD

#define SET_BALL_COORD (   AXIS,
  VAL 
)
Value:
ball->AXIS = VAL; \
ball->f_##AXIS = VAL;
Object to represent a ball that bounces off walls.
Definition: gfx_ball.h:66

◆ VERTICAL

#define VERTICAL   0b10

◆ WALL

#define WALL   ((wall_t *)object)

Typedef Documentation

◆ walls_t

typedef struct walls walls_t

Function Documentation

◆ _changeBallDirection()

void _changeBallDirection ( ball_t ball,
signed char  direction,
float  dampening 
)

◆ _checkBallCollisionsWithBalls()

unsigned char _checkBallCollisionsWithBalls ( ball_t ball)

◆ _checkBallCollisionsWithWalls()

signed char _checkBallCollisionsWithWalls ( ball_t ball,
void(*)(void *)  callback,
void *  args 
)

◆ _collideWall()

signed char _collideWall ( ball_t ball,
wall_t wall,
unsigned char  collision_type,
void(*)(void *)  callback,
void *  args 
)

◆ _handleCollision()

signed char _handleCollision ( ball_t ball,
void *  object,
unsigned char  flag,
void(*)(void *)  callback,
void *  args 
)

◆ gfxCheckBallCollisions()

signed char gfxCheckBallCollisions ( ball_t ball,
void(*)(void *)  callback,
void *  args 
)

◆ gfxCreateBall()

ball_t* gfxCreateBall ( signed short  initial_x,
signed short  initial_y,
unsigned int  colour,
signed short  radius,
float  max_speed,
void(*)(void *)  callback,
void *  args,
gfx_image_handle_t  sprite 
)

◆ gfxCreateWall()

wall_t* gfxCreateWall ( signed short  x1,
signed short  y1,
signed short  w,
signed short  h,
float  dampening,
unsigned int  colour,
void(*)(void *)  callback,
void *  args 
)

Variable Documentation

◆ walls

walls_t walls = { 0 }