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  _random_state_t
 

Macros

#define WINDOW_WIDTH   640
 Pong game ported to the PandA framework by Fabrizio Ferrandi. 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 COMPUTER_Y   30
 
#define PLAYER_Y   430
 
#define PADDLE_WIDTH   32
 
#define PADDLE_HEIGHT   8
 
#define BALL_DIAMETER   8
 
#define PLAYER_SPEED   2
 
#define COMPUTER_SPEED   2
 
#define BALL_SPEED_MODIFIER   4
 
#define BALL_SPEED_Y   2
 
#define LEFT   0
 
#define RIGHT   1
 
#define UP   2
 
#define DOWN   3
 
#define sgn(x)   ((x<0)?-1:((x>0)?1:0))
 
#define rot(x, k)   (((x)<<(k))|((x)>>(32-(k))))
 

Typedefs

typedef struct _obj_description obj_description
 
typedef struct _entity entity
 
typedef struct _random_state_t random_state_t
 

Functions

unsigned int random_number (random_state_t *x)
 
void random_number_init (random_state_t *x, unsigned int seed)
 
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 (entity *paddle)
 
void move_ball ()
 
_Bool manage_player_score ()
 
_Bool manage_computer_score ()
 
void game_initialization ()
 
_Bool get_game_input ()
 
_Bool manage_ball ()
 
void manage_AI ()
 
_Bool game_main_loop ()
 
void main ()
 

Variables

entity computer
 
entity player
 
entity ball
 
unsigned char computer_score
 
unsigned char player_score
 
static int last_speed = 0
 
static int decision = 3
 
int timer
 
static random_state_t random_state
 

Macro Definition Documentation

◆ BALL_DIAMETER

#define BALL_DIAMETER   8

Definition at line 36 of file main.c.

Referenced by game_initialization(), manage_computer_score(), and manage_player_score().

◆ BALL_SPEED_MODIFIER

#define BALL_SPEED_MODIFIER   4

Definition at line 43 of file main.c.

Referenced by manage_ball().

◆ BALL_SPEED_Y

#define BALL_SPEED_Y   2

Definition at line 44 of file main.c.

Referenced by get_game_input(), and manage_AI().

◆ BLACK_COLOR

#define BLACK_COLOR   0

Definition at line 25 of file main.c.

Referenced by game_initialization(), and game_main_loop().

◆ BLUE_COLOR

#define BLUE_COLOR   1

Definition at line 22 of file main.c.

Referenced by game_main_loop().

◆ COMPUTER_SPEED

#define COMPUTER_SPEED   2

Definition at line 40 of file main.c.

Referenced by game_initialization(), and manage_AI().

◆ COMPUTER_Y

#define COMPUTER_Y   30

Definition at line 28 of file main.c.

Referenced by game_initialization().

◆ DOWN

#define DOWN   3

Definition at line 49 of file main.c.

◆ FRAME_RATE

#define FRAME_RATE   1000/FRAMES_PER_SECOND

Definition at line 17 of file main.c.

Referenced by game_main_loop().

◆ FRAMES_PER_SECOND

#define FRAMES_PER_SECOND   60

Definition at line 16 of file main.c.

◆ GREEN_COLOR

#define GREEN_COLOR   2

Definition at line 23 of file main.c.

Referenced by game_main_loop().

◆ LEFT

#define LEFT   0

Definition at line 46 of file main.c.

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

◆ PADDLE_HEIGHT

#define PADDLE_HEIGHT   8

Definition at line 33 of file main.c.

Referenced by game_initialization().

◆ PADDLE_WIDTH

#define PADDLE_WIDTH   32

Definition at line 32 of file main.c.

Referenced by game_initialization().

◆ PLAYER_SPEED

#define PLAYER_SPEED   2

Definition at line 39 of file main.c.

Referenced by game_initialization(), and get_game_input().

◆ PLAYER_Y

#define PLAYER_Y   430

Definition at line 29 of file main.c.

Referenced by check_ball_collisions(), and game_initialization().

◆ RED_COLOR

#define RED_COLOR   4

Definition at line 21 of file main.c.

◆ RIGHT

#define RIGHT   1

Definition at line 47 of file main.c.

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

◆ rot

#define rot (   x,
  k 
)    (((x)<<(k))|((x)>>(32-(k))))

Definition at line 89 of file main.c.

Referenced by random_number().

◆ sgn

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

Definition at line 51 of file main.c.

Referenced by line().

◆ UP

#define UP   2

Definition at line 48 of file main.c.

◆ WHITE_COLOR

#define WHITE_COLOR   7

Definition at line 24 of file main.c.

Referenced by game_main_loop().

◆ WINDOW_HEIGHT

#define WINDOW_HEIGHT   480

◆ WINDOW_WIDTH

#define WINDOW_WIDTH   640

Pong game ported to the PandA framework by Fabrizio Ferrandi.

The original code has been taken from http://www.aaroncox.net/tutorials/arcade/PaddleBattle.html Pong was the first game developed by Atari Inc and was designed and built by Allan Alcorn. Further information can be found at https://en.wikipedia.org/wiki/Pong. Random functions taken from http://burtleburtle.net/bob/rand/smallprng.html

Definition at line 12 of file main.c.

Referenced by check_wall_collisions(), game_initialization(), game_main_loop(), manage_computer_score(), and manage_player_score().

◆ YELLOW_COLOR

#define YELLOW_COLOR   6

Definition at line 20 of file main.c.

Referenced by game_main_loop().

Typedef Documentation

◆ entity

typedef struct _entity entity

◆ obj_description

◆ random_state_t

Function Documentation

◆ check_ball_collisions()

_Bool check_ball_collisions ( entity paddle)

◆ check_wall_collisions()

_Bool check_wall_collisions ( entity entity,
unsigned char  dir 
)

◆ circle()

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

Definition at line 169 of file main.c.

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

Here is the call graph for this function:

◆ convert_char_digit_2_sseg()

unsigned char convert_char_digit_2_sseg ( char  c)

Definition at line 110 of file main.c.

References test_panda::table.

◆ game_initialization()

void game_initialization ( )

◆ game_main_loop()

_Bool game_main_loop ( )

◆ get_game_input()

_Bool get_game_input ( )

◆ line()

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

Definition at line 117 of file main.c.

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

Here is the call graph for this function:

◆ main()

void main ( void  )

Definition at line 526 of file main.c.

References game_initialization(), and game_main_loop().

Here is the call graph for this function:

◆ manage_AI()

void manage_AI ( )

Definition at line 441 of file main.c.

References abs, BALL_SPEED_Y, check_wall_collisions(), COMPUTER_SPEED, decision, last_speed, LEFT, random_number(), RIGHT, _entity::screen_location, _obj_description::w, _obj_description::x, and _entity::x_speed.

Referenced by game_main_loop().

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

◆ manage_ball()

_Bool manage_ball ( )

◆ manage_computer_score()

_Bool manage_computer_score ( )

Definition at line 321 of file main.c.

References BALL_DIAMETER, computer_score, player_score, _entity::screen_location, WINDOW_HEIGHT, WINDOW_WIDTH, _obj_description::x, _entity::x_speed, _obj_description::y, and _entity::y_speed.

Referenced by manage_ball().

Here is the caller graph for this function:

◆ manage_player_score()

_Bool manage_player_score ( )

Definition at line 301 of file main.c.

References BALL_DIAMETER, computer_score, player_score, _entity::screen_location, WINDOW_HEIGHT, WINDOW_WIDTH, _obj_description::x, _entity::x_speed, _obj_description::y, and _entity::y_speed.

Referenced by manage_ball().

Here is the caller graph for this function:

◆ move_ball()

void move_ball ( )

Definition at line 289 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.

Here is the call graph for this function:

◆ output_score()

void output_score ( )

Definition at line 203 of file main.c.

References computer_score, convert_char_digit_2_sseg(), player_score, and sevensegments_ctrl().

Here is the call graph for this function:

◆ random_number()

unsigned int random_number ( random_state_t x)

Definition at line 90 of file main.c.

References _random_state_t::a, _random_state_t::b, _random_state_t::c, _random_state_t::d, and rot.

Referenced by manage_AI(), and random_number_init().

Here is the caller graph for this function:

◆ random_number_init()

void random_number_init ( random_state_t x,
unsigned int  seed 
)

Definition at line 100 of file main.c.

References _random_state_t::a, _random_state_t::b, _random_state_t::c, _random_state_t::d, and random_number().

Referenced by game_initialization().

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 161 of file main.c.

References line().

Here is the call graph for this function:

◆ rect_fill()

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

Definition at line 194 of file main.c.

References line().

Here is the call graph for this function:

Variable Documentation

◆ ball

entity ball

Definition at line 72 of file main.c.

◆ computer

entity computer

Definition at line 70 of file main.c.

Referenced by game_main_loop().

◆ computer_score

unsigned char computer_score

◆ decision

int decision = 3
static

Definition at line 76 of file main.c.

Referenced by game_initialization(), and manage_AI().

◆ last_speed

int last_speed = 0
static

Definition at line 75 of file main.c.

Referenced by game_initialization(), and manage_AI().

◆ player

entity player

Definition at line 71 of file main.c.

◆ player_score

unsigned char player_score

◆ random_state

random_state_t random_state
static

Definition at line 108 of file main.c.

◆ timer

int timer

Definition at line 77 of file main.c.


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