PandA-2024.02
Data Structures | Macros | Typedefs | Functions | Variables
main.c File Reference
#include "plot.h"
#include "btn_ctrl.h"
#include "get_ticks.h"
#include "sevensegments_ctrl.h"
Include dependency graph for main.c:

Go to the source code of this file.

Data Structures

struct  _obj_description
 
struct  _entity
 
struct  _brick
 

Macros

#define WINDOW_WIDTH   640
 Breakout game ported to the PandA framework by Fabrizio Ferrandi on April 11th 2016. More...
 
#define WINDOW_HEIGHT   480
 
#define FRAMES_PER_SECOND   60
 
#define FRAME_RATE   1000/FRAMES_PER_SECOND
 
#define YELLOW_COLOR   6
 
#define RED_COLOR   4
 
#define BLUE_COLOR   1
 
#define GREEN_COLOR   2
 
#define WHITE_COLOR   7
 
#define BLACK_COLOR   0
 
#define BRICK_SCREEN_BUFFER_X   41
 
#define BRICK_SCREEN_BUFFER_Y   30
 
#define NUM_ROWS   6
 
#define NUM_COLS   9
 
#define MAX_BRICKS   NUM_ROWS*NUM_COLS
 
#define PLAYER_Y   430
 
#define BRICK_WIDTH   62
 
#define BRICK_HEIGHT   16
 
#define PADDLE_WIDTH   32
 
#define PADDLE_HEIGHT   8
 
#define BALL_DIAMETER   8
 
#define PLAYER_SPEED   2
 
#define BALL_SPEED_MODIFIER   4
 
#define BALL_SPEED_Y   2
 
#define NUM_LIVES   5
 
#define NUM_LEVELS   3
 
#define LEFT   0
 
#define RIGHT   1
 
#define UP   2
 
#define DOWN   3
 
#define sgn(x)   ((x<0)?-1:((x>0)?1:0))
 

Typedefs

typedef struct _obj_description obj_description
 
typedef struct _entity entity
 
typedef struct _brick brick
 

Functions

unsigned char convert_char_digit_2_sseg (char c)
 
void line (int x1, int y1, int x2, int y2, unsigned int color)
 
void rect (int left, int top, int right, int bottom, unsigned int color)
 
void circle (int x0, int y0, int radius, unsigned int color)
 
void rect_fill (int left, int top, int right, int bottom, unsigned int color)
 
void output_score ()
 
_Bool check_wall_collisions (entity *entity, unsigned char dir)
 
_Bool check_ball_collisions ()
 
void move_ball ()
 
void bricks_initialization ()
 
void game_initialization ()
 
_Bool get_game_input ()
 
_Bool check_point_in_rect (int x, int y, obj_description *rect)
 
_Bool change_level ()
 
_Bool manage_brick_collision (int index)
 
_Bool check_brick_collisions ()
 
void manage_loss ()
 
_Bool manage_ball ()
 
_Bool game_main_loop ()
 
void main ()
 

Variables

entity player
 
entity ball
 
int lives
 
int level
 
int num_bricks
 
brick bricks [MAX_BRICKS]
 
int timer
 
static unsigned char level_hits [NUM_LEVELS][MAX_BRICKS]
 

Macro Definition Documentation

◆ BALL_DIAMETER

#define BALL_DIAMETER   8

Definition at line 48 of file main.c.

Referenced by check_brick_collisions(), and game_initialization().

◆ BALL_SPEED_MODIFIER

#define BALL_SPEED_MODIFIER   4

Definition at line 54 of file main.c.

Referenced by manage_ball().

◆ BALL_SPEED_Y

#define BALL_SPEED_Y   2

Definition at line 55 of file main.c.

Referenced by get_game_input().

◆ BLACK_COLOR

#define BLACK_COLOR   0

◆ BLUE_COLOR

#define BLUE_COLOR   1

Definition at line 21 of file main.c.

Referenced by bricks_initialization(), and game_main_loop().

◆ BRICK_HEIGHT

#define BRICK_HEIGHT   16

Definition at line 41 of file main.c.

Referenced by bricks_initialization().

◆ BRICK_SCREEN_BUFFER_X

#define BRICK_SCREEN_BUFFER_X   41

Definition at line 27 of file main.c.

Referenced by bricks_initialization().

◆ BRICK_SCREEN_BUFFER_Y

#define BRICK_SCREEN_BUFFER_Y   30

Definition at line 28 of file main.c.

Referenced by bricks_initialization().

◆ BRICK_WIDTH

#define BRICK_WIDTH   62

Definition at line 40 of file main.c.

Referenced by bricks_initialization().

◆ DOWN

#define DOWN   3

Definition at line 67 of file main.c.

◆ FRAME_RATE

#define FRAME_RATE   1000/FRAMES_PER_SECOND

Definition at line 16 of file main.c.

Referenced by game_main_loop().

◆ FRAMES_PER_SECOND

#define FRAMES_PER_SECOND   60

Definition at line 15 of file main.c.

◆ GREEN_COLOR

#define GREEN_COLOR   2

Definition at line 22 of file main.c.

Referenced by bricks_initialization(), and manage_brick_collision().

◆ LEFT

#define LEFT   0

Definition at line 64 of file main.c.

Referenced by check_wall_collisions(), get_game_input(), and move_ball().

◆ MAX_BRICKS

#define MAX_BRICKS   NUM_ROWS*NUM_COLS

Definition at line 33 of file main.c.

Referenced by bricks_initialization(), check_brick_collisions(), and game_main_loop().

◆ NUM_COLS

#define NUM_COLS   9

Definition at line 32 of file main.c.

Referenced by bricks_initialization().

◆ NUM_LEVELS

#define NUM_LEVELS   3

Definition at line 61 of file main.c.

Referenced by change_level().

◆ NUM_LIVES

#define NUM_LIVES   5

Definition at line 58 of file main.c.

Referenced by game_initialization(), and manage_loss().

◆ NUM_ROWS

#define NUM_ROWS   6

Definition at line 31 of file main.c.

Referenced by bricks_initialization().

◆ PADDLE_HEIGHT

#define PADDLE_HEIGHT   8

Definition at line 45 of file main.c.

Referenced by game_initialization().

◆ PADDLE_WIDTH

#define PADDLE_WIDTH   32

Definition at line 44 of file main.c.

Referenced by game_initialization().

◆ PLAYER_SPEED

#define PLAYER_SPEED   2

Definition at line 51 of file main.c.

Referenced by game_initialization(), and get_game_input().

◆ PLAYER_Y

#define PLAYER_Y   430

Definition at line 36 of file main.c.

Referenced by game_initialization().

◆ RED_COLOR

#define RED_COLOR   4

Definition at line 20 of file main.c.

Referenced by bricks_initialization(), and manage_brick_collision().

◆ RIGHT

#define RIGHT   1

Definition at line 65 of file main.c.

Referenced by check_wall_collisions(), get_game_input(), and move_ball().

◆ sgn

#define sgn (   x)    ((x<0)?-1:((x>0)?1:0))

Definition at line 69 of file main.c.

Referenced by line().

◆ UP

#define UP   2

Definition at line 66 of file main.c.

◆ WHITE_COLOR

#define WHITE_COLOR   7

Definition at line 23 of file main.c.

Referenced by game_main_loop().

◆ WINDOW_HEIGHT

#define WINDOW_HEIGHT   480

Definition at line 12 of file main.c.

Referenced by change_level(), game_initialization(), game_main_loop(), manage_ball(), and manage_loss().

◆ WINDOW_WIDTH

#define WINDOW_WIDTH   640

Breakout game ported to the PandA framework by Fabrizio Ferrandi on April 11th 2016.

The original code has been taken from http://www.aaroncox.net/tutorials/arcade/BRICKBreaker.html The game was designed by Nolan Bushnell, Steve Wozniak, and Steve Bristow. History of Breakout game can be found at this link: https://en.wikipedia.org/wiki/Breakout_%28video_game%29

Definition at line 11 of file main.c.

Referenced by change_level(), check_wall_collisions(), game_initialization(), game_main_loop(), manage_ball(), and manage_loss().

◆ YELLOW_COLOR

#define YELLOW_COLOR   6

Definition at line 19 of file main.c.

Referenced by bricks_initialization(), game_main_loop(), and manage_brick_collision().

Typedef Documentation

◆ brick

typedef struct _brick brick

◆ entity

typedef struct _entity entity

◆ obj_description

Function Documentation

◆ bricks_initialization()

void bricks_initialization ( )

◆ change_level()

_Bool change_level ( )

Definition at line 431 of file main.c.

References bricks_initialization(), _obj_description::h, level, num_bricks, NUM_LEVELS, _entity::screen_location, _obj_description::w, WINDOW_HEIGHT, WINDOW_WIDTH, _obj_description::x, _entity::x_speed, _obj_description::y, and _entity::y_speed.

Referenced by manage_brick_collision().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_ball_collisions()

_Bool check_ball_collisions ( )

Definition at line 242 of file main.c.

References _obj_description::h, _entity::screen_location, _obj_description::w, _obj_description::x, _obj_description::y, and _entity::y_speed.

Referenced by manage_ball().

Here is the caller graph for this function:

◆ check_brick_collisions()

_Bool check_brick_collisions ( )

Definition at line 508 of file main.c.

References BALL_DIAMETER, BLACK_COLOR, check_point_in_rect(), _obj_description::h, manage_brick_collision(), MAX_BRICKS, _entity::screen_location, top(), _obj_description::w, _obj_description::x, _entity::x_speed, _obj_description::y, and _entity::y_speed.

Referenced by manage_ball().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_point_in_rect()

_Bool check_point_in_rect ( int  x,
int  y,
obj_description rect 
)

Definition at line 422 of file main.c.

References _obj_description::h, _obj_description::w, _obj_description::x, and _obj_description::y.

Referenced by check_brick_collisions().

Here is the caller graph for this function:

◆ check_wall_collisions()

_Bool check_wall_collisions ( entity entity,
unsigned char  dir 
)

Definition at line 216 of file main.c.

References LEFT, RIGHT, _entity::screen_location, _obj_description::w, WINDOW_WIDTH, _obj_description::x, and _entity::x_speed.

Referenced by get_game_input(), manage_AI(), and move_ball().

Here is the caller graph for this function:

◆ circle()

void circle ( int  x0,
int  y0,
int  radius,
unsigned int  color 
)

Definition at line 162 of file main.c.

References plot(), _obj_description::x, and _obj_description::y.

Referenced by game_main_loop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convert_char_digit_2_sseg()

unsigned char convert_char_digit_2_sseg ( char  c)

Definition at line 103 of file main.c.

References test_panda::table.

Referenced by output_score().

Here is the caller graph for this function:

◆ game_initialization()

void game_initialization ( )

◆ game_main_loop()

_Bool game_main_loop ( )

◆ get_game_input()

_Bool get_game_input ( )

Definition at line 394 of file main.c.

References BALL_SPEED_Y, btn_ctrl(), BUTTON_DOWN, BUTTON_LEFT, BUTTON_RIGHT, BUTTON_UP, check_wall_collisions(), LEFT, PLAYER_SPEED, RIGHT, _entity::screen_location, _obj_description::x, and _entity::y_speed.

Referenced by game_main_loop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ line()

void line ( int  x1,
int  y1,
int  x2,
int  y2,
unsigned int  color 
)

◆ main()

void main ( void  )

Definition at line 670 of file main.c.

References game_initialization(), and game_main_loop().

Here is the call graph for this function:

◆ manage_ball()

_Bool manage_ball ( )

◆ manage_brick_collision()

_Bool manage_brick_collision ( int  index)

Definition at line 454 of file main.c.

References BLACK_COLOR, change_level(), _brick::color, GREEN_COLOR, index, num_bricks, _brick::num_hits, RED_COLOR, and YELLOW_COLOR.

Referenced by check_brick_collisions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ manage_loss()

void manage_loss ( )

Definition at line 577 of file main.c.

References bricks_initialization(), _obj_description::h, level, lives, num_bricks, NUM_LIVES, _entity::screen_location, _obj_description::w, WINDOW_HEIGHT, WINDOW_WIDTH, _obj_description::x, _entity::x_speed, _obj_description::y, and _entity::y_speed.

Referenced by manage_ball().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ move_ball()

void move_ball ( )

Definition at line 266 of file main.c.

References check_wall_collisions(), LEFT, RIGHT, _entity::screen_location, _obj_description::x, _entity::x_speed, _obj_description::y, and _entity::y_speed.

Referenced by manage_ball().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ output_score()

void output_score ( )

Definition at line 196 of file main.c.

References convert_char_digit_2_sseg(), level, lives, and sevensegments_ctrl().

Referenced by game_main_loop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rect()

void rect ( int  left,
int  top,
int  right,
int  bottom,
unsigned int  color 
)

Definition at line 154 of file main.c.

References line().

Referenced by game_main_loop(), tree_helper::GetRecordTypeName(), tree_helper::GetTemplateTypeName(), and tree_helper::GetTypeName().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rect_fill()

void rect_fill ( int  left,
int  top,
int  right,
int  bottom,
unsigned int  color 
)

Definition at line 187 of file main.c.

References line().

Referenced by game_initialization(), and game_main_loop().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ball

entity ball

Definition at line 96 of file main.c.

Referenced by game_main_loop().

◆ bricks

brick bricks[MAX_BRICKS]

Definition at line 100 of file main.c.

◆ level

int level

◆ level_hits

unsigned char level_hits[NUM_LEVELS][MAX_BRICKS]
static
Initial value:
= {
{
0, 3, 3, 3, 3, 3, 3, 3, 0,
2, 0, 3, 3, 3, 3, 3, 0, 2,
2, 2, 0, 3, 3, 3, 0, 2, 2,
2, 2, 2, 0, 3, 0, 2, 2, 2,
2, 2, 2, 2, 0, 2, 2, 2, 2,
2, 2, 2, 0, 4, 0, 2, 2, 2
}, {
3, 3, 3, 3, 3, 3, 3, 3, 3,
0, 4, 0, 4, 0, 4, 0, 4, 0,
2, 2, 2, 2, 2, 2, 2, 2, 2,
0, 4, 0, 4, 0, 4, 0, 4, 0,
3, 3, 3, 3, 3, 3, 3, 3, 3,
0, 4, 0, 4, 0, 4, 0, 4, 0
}, {
1, 2, 1, 2, 1, 2, 1, 2, 1,
1, 2, 1, 2, 1, 2, 1, 2, 1,
1, 2, 1, 2, 1, 2, 1, 2, 1,
1, 2, 1, 1, 1, 2, 1, 2, 1,
1, 2, 1, 2, 1, 2, 1, 2, 1,
1, 2, 1, 2, 1, 2, 1, 2, 1
}
}

Definition at line 278 of file main.c.

Referenced by bricks_initialization().

◆ lives

int lives

Definition at line 97 of file main.c.

Referenced by game_initialization(), manage_ball(), manage_loss(), and output_score().

◆ num_bricks

int num_bricks

Definition at line 99 of file main.c.

Referenced by bricks_initialization(), change_level(), manage_brick_collision(), and manage_loss().

◆ player

entity player

Definition at line 95 of file main.c.

Referenced by game_main_loop().

◆ timer

int timer

Definition at line 101 of file main.c.

Referenced by game_initialization(), and game_main_loop().


Generated on Mon Feb 12 2024 13:03:05 for PandA-2024.02 by doxygen 1.8.13