• Pong V2

    solinsna04/05/2016 at 19:11 0 comments

    Big change#1: Converted the code to use non-blocking time. Previously I had used a series of for loops to stall the methods (i guess these are methods, I'm assuming this is coded in C?). These methods worked on the emulator, but not on the badge, as they relied on actual program execution speed, not the clock.

    Big Change#2: Modified existing character generation code to use buffer[x] writing instead of for loops and hard coded pixels that I had previously implemented. This saved me ~3.4Kb off of the bh-badge-animate.c file. This leads us to Big change No.3!

    Big Change#3: Because of the change in No.2, and No.1 above, I could now easily implement scrolling text for my "Game Over" sequence. After the ball moves off of the screen, a message scrolls from 0 to 15 that states "GAME OVER!", and then player 1, followed by player 2 scores are shown on the badge. Previously, due to my timing and delay's consisting of for loops, I was unable to reliably time the scrolling of text, so I omitted that feature, and instead displayed 3 to 4 characters at a time on the display, which was not graphically appealing.

    In all, I only added one method to my program to implement these changes, and replaced poorly designed code to achieve the rest. Here's some documentation;

    uint8_t ballX = 4; //X position of the ball

    uint8_t ballY = 9; //y position of the ball

    int p1 = 1; // player 1 (nearest 0,0) paddle position

    int p2= 1; //player 2 (opposite 0,0) paddle position

    uint8_t angle = 0; //angle of the ball. When looking at emulator, -1 moves the ball left,decreasing along the axis, while 1 moves right, increasing along the axis. 0 has no change in axis position. values: -1,0,1

    uint8_t direction = -1; //direction that the ball is heading, -1 decreases along the axis, +1 increases along the axis. values: 1, -1

    int c; // unused variable

    uint8_t d; //unused variable

    int i; //doubly declared incremental variable

    int bumpers = 0; //unused variable. would have enabled a hidden game mode that would not allow the ball to go off of the screen, and made the game play like air hockey.

    int p1Score = 0; //player 1 score

    int p2Score =0; //player2 score

    int speed = 1000; //unused speed variable. written in to allow game play to increase speed with more successive ball hits. did not work as planned, caused the ball to lose control.

    void eraseBall(void); //method that deletes the pixel located at ballX, ballY

    void moveLeft(void); //method to move p1 paddle left

    void moveRight(void); //method to move p2 paddle right

    void moveUp(void); //method to move p1 paddle right

    void moveDown(void); //method to move p2 paddle left

    void drawPaddle(uint8_t x); //method to draw paddle. input values: 0, 1. Accepts an integer and draws the paddle on either end of the screen, 1 for p1, 0 for p2

    void erasePaddle(uint8_t x); //method to erase paddle. input values: 0,1. Accepts an integer and erases the paddle on either end of the screen, 1 for p1, 0 for p2

    void ballMover(void); // method that increments the ball in the correct x and y directions, and then redraws ball.

    void gameOver(void); //method that draws the game over message and displays p1 and p2 scores on the screen

    void drawG(uint8_t x); //method to draw the letter g at relative to y axis location. accepts integer 0-15.

    void drawA(uint8_t x); //method to draw the letter a at relative to y axis location. accepts integer 0-15.

    void drawM(uint8_t x);//method to draw the letter m at relative to y axis location. accepts integer 0-15.

    void drawE(uint8_t x);//method to draw the letter e at relative to y axis location. accepts integer 0-15.

    void drawO(uint8_t x);//method to draw the letter o at relative to y axis location. accepts integer 0-15.

    void drawV(uint8_t x); //method to draw the letter v at relative to y axis location. accepts integer 0-15.

    void drawR(uint8_t x);//method to draw the letter r at relative to y axis location. accepts integer 0-15.

    void drawP(uint8_t x);//method to draw the letter p at relative to y axis location. accepts integer 0-15.

    void drawEX(uint8_t...

    Read more »