To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
bh-badge-animate.hadded wipePaddle() method to remove extra ball that was left on the display after score occurred.plain - 880.00 bytes - 04/05/2016 at 19:12 |
|
|
bh-badge-animate.cvERSION 2, Corrected to use non-blocking time, redesigned game over screen to scroll, as well as be written using the buffer commands as opposed to the for loops and hard coded pixels previously implemented. Also modified scoring to advance the ball, as the non blocking time was causing the score paddle touch conditionals to run multiple times and drive the score up.plain - 8.25 kB - 04/05/2016 at 18:37 |
|
|
project.gifGif of game functionGraphics Interchange Format - 206.94 kB - 04/01/2016 at 16:48 |
|
|
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 »
Create an account to leave a comment. Already have an account? Log In.
I'm reworking the code now to use get time, which is working for the ball and paddle controls, but i cant seem to make it work for the "Game Over" message after the ball goes out of play. I'm going to revamp that whole part anyways, as used for statements to draw the characters instead of buffers(which are much simpler). I'll post up modified code later today
Become a member to follow this project and never miss any updates
I just gave this a try on the badge. It runs but there are a couple of bugs that just need a bit of squashing.
Check out this code to see how non-blocking time is set up. Look at lines 62-66 here:
https://github.com/Hack-a-Day/hackaday-belgrade-badge-MPLABX/blob/master/bh-badge-animate.c
This would work well for calling your moveBall() function.
I made some tweaks to try and get this working and got the ball to move at a reasonable speed, but when it hit the paddle it didn't bounce. Not sure what's up there, but seems like you're really close to an awesome thing here!!