FreeRTOS Tetris
Data Fields
ball Struct Reference

Object to represent a ball that bounces off walls. More...

#include <TUM_Ball.h>

Collaboration diagram for ball:
Collaboration graph

Data Fields

signed short x
 
signed short y
 
float f_x
 
float f_y
 
float dx
 
float dy
 
float max_speed
 
unsigned int colour
 
signed short radius
 
callback_t callback
 
void * args
 

Detailed Description

Object to represent a ball that bounces off walls.

A ball is created with a starting X and Y location (center of the ball), initial X and Y axis speeds (dx and dy respectively), as well as a limiting maximum speed, a colour and a radius. A callback function can be passed to the ball creation function createBall with the form void (*callback)(void), which is called each time the ball collides with a wall.

The absolute location of the ball is stored in the floats f_x and f_y, this is to avoid situation where the ball is moving so slowly that it cannot escape its current pixel as the rounding performed during integer mathematics is causing the ball to become trapped on a pixel.

The colour of the ball is a 24bit hex colour code of the format RRGGBB.

A ball is created with initial speeds (dx and dy) of zero. The speed of the ball must be set to a non-zero value using setBallSpeed before the ball will start to move.

Field Documentation

◆ args

void* ball::args

Collision callback args

◆ callback

callback_t ball::callback

Collision callback

◆ colour

unsigned int ball::colour

Hex RGB colour of the ball

◆ dx

float ball::dx

X axis speed in pixels/second

◆ dy

float ball::dy

Y axis speed in pixels/second

◆ f_x

float ball::f_x

Absolute X location of ball

◆ f_y

float ball::f_y

Absolute Y location of ball

◆ max_speed

float ball::max_speed

Maximum speed the ball is able to achieve in pixels/second

◆ radius

signed short ball::radius

Radius of the ball in pixels

◆ x

signed short ball::x

X pixel coord of ball on screen

◆ y

signed short ball::y

Y pixel coord of ball on screen


The documentation for this struct was generated from the following file: