Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "system.h"
- #include "display.h"
- #include "tinygl.h"
- #include "../fonts/font5x7_1.h"
- #include "ball.h"
- #include "pacer.h"
- #include "ir_uart.h"
- #include "navswitch.h"
- #include "paddle.h"
- #define OFF_BOARD 10
- #define ON_BOARD 11
- #define GAME_LOST 20
- #define GAME_WON 21
- #define LOOP_RATE 500
- #define MESSAGE_RATE 15
- #define PADDLE_RATE 500
- static char row = 3;
- static char col = 4;
- static int rowinc = 1;
- static int colinc = 1;
- static int paddle = 3;
- int starting(void)
- {
- int location = 0;
- bool not_started = true;
- tinygl_text("Push Navswitch to play ");
- while (not_started)
- {
- //Updating compontants
- navswitch_update();
- pacer_wait();
- tinygl_update();
- //If the center button has been pushed, intiating the start of the game on this board
- if (navswitch_push_event_p (NAVSWITCH_PUSH))
- {
- not_started = false;
- ir_uart_putc(OFF_BOARD);
- location = ON_BOARD;
- //Else if signal is being sent to the board, read it
- } else if (ir_uart_read_ready_p()) {
- location = ir_uart_getc();
- not_started = false;
- }
- }
- //Clearing the screen
- tinygl_clear();
- tinygl_update();
- return location;
- }
- int game_play(void)
- {
- row += rowinc;
- col += colinc;
- //If the ball has hit the wall and needs to be reflected
- if (row <= 0 || row >= 7)
- {
- rowinc = -rowinc;
- row = 2 * rowinc;
- }
- //If the ball is in the paddle col
- if (col == 5)
- {
- //When the ball hits the paddle is reflected
- if (row <= --paddle && row >= ++paddle)
- {
- col--;
- colinc = -colinc;
- //When the ball is not reflected
- } else {
- ball_display(row, col);
- return GAME_LOST;
- }
- //The ball is off the board and needs to be transmitted
- } else if (col == 0) {
- ir_uart_putc(row);
- return OFF_BOARD;
- //Is the a way of sending the rowinc as well - talked to Sam (COMSOC) there is and it was confusing
- }
- //Displaying the ball
- pacer_wait(); ///testing
- ball_display(row, col);
- return ON_BOARD;
- }
- int main(void)
- {
- //Initialing all the functions
- system_init();
- navswitch_init();
- display_init();
- ir_uart_init();
- pacer_init(LOOP_RATE);
- tinygl_init(LOOP_RATE);
- tinygl_font_set(&font5x7_1);
- tinygl_text_speed_set(MESSAGE_RATE);
- tinygl_text_mode_set(TINYGL_TEXT_MODE_SCROLL);
- //Initialising the variables
- int location; //If the ball is on or off the board
- int counter = 0;
- //Starting function
- location = starting();
- //Main Run cycle
- while (location != GAME_LOST && location != GAME_WON)
- {
- counter++;
- //When the ball is on the board
- if (location == ON_BOARD)
- {
- if (counter > 80)
- {
- pacer_wait(); ///testing
- location = game_play();
- pacer_wait(); ///testing
- counter = 0;
- }
- pacer_wait(); ///testing
- paddle = paddle_piece(paddle);
- //When the ball is off the board
- } else {
- paddle = paddle_piece(paddle);
- //Checking if there is signal ready to recieve
- if (ir_uart_read_ready_p())
- {
- row = ir_uart_getc();
- col = 0;
- //Checking that this is not the win indicator
- if (row == 21) {
- location = GAME_WON;
- }
- game_play();
- }
- }
- }
- if (location == GAME_LOST)
- {
- tinygl_text("Loser ");
- tinygl_update();
- pacer_wait();
- tinygl_clear();
- } else {
- tinygl_text("Winner ");
- tinygl_update();
- pacer_wait();
- tinygl_clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement