top of page
Search
  • mziegen

Matthew's Coding Blog: Bouncing Ball


Picture of the game board


For this assignment, I've decided to go another way in a sense. I've created four corner pockets and a hockey puck (which is my ball) that once it hits the corner directly you can score a point. It is a blueprint for a virtual nok and air hockey game. I still intend to include a clock, a stoppage once a corner is hit directly, a goal lights up the corner and adds a point to the board for that corner's bettor, and several other small pieces that can make this a fun game to play with friends. Eventually, maybe some user interaction can come as a result of this. Perhaps the person who scores the last goal can launch the puck from center ice to wherever they please, as long as it is not directly to your own goal. If you send it to your own goal, you will lose a point.


What I've done to create this was set my canvas to 600x600. Next, the background was set to 30 so it wasn't too dark. Before function setup, I've created variables for ballX, ballY, speedX, speedY, r, g, and b. In setup, ballX and Y were set to 300 while speedX was set to 6 and speedY was set to 9. I've come to realize that making speedX 2/3 of speedY has allowed the puck to bounce around without knowledge of which corner will get hit by the puck first.


In draw settings, I've created six conditionals. If ballX is greater than the width and/or is less than or equal to 0, then the puck will change its direction and head back in the opposite direction. If ballY is greater than the height and/or less than or equal to 0, then the puck will change its direction and head in the opposite direction as well. This allows for continuation of the game without stopping.


Outside of that formula and bracket, I've equaled ballX and ballY to the itself + speedX/Y. Because this was done, now the puck is doing its job and consistently moving around the board searching for a goal rather than just moving horizontally or vertically. It moves in all directions. For the rest of the conditionals, I've created my borders for which the puck can stay inside the board. For example, ballX is greater than 560 and less than 40, the puck is set to change direction and reflect off the sides at that certain point. If ballY is greater than 560 and less than 40, the same rules apply for those sides of the square board. After hitting one of the side walls (under ballX) the puck can be changed from any variation of red from 90-255. This is so the puck can still be visible.


From this point forward, I just created the corner pockets made with four different colors (red, blue, green, and yellow so that you can call or play as a color of your choosing. Lastly, I created a neon-like center ice piece made of different color strokes while the fill color matches the background's 30 color.


To view the game, click this link. Remember...the game is not finished nor is completely designed to perfection.



To see the coding, view this link:




5 views0 comments

Recent Posts

See All

Matthew's Coding Blog: Final

Unfortunately, I am mere inches away from finishing the product. This month has set my life into what feels like an irreversible tailspin. With that being said, I did my best to get the point across a

Matthew's Coding Blog: Final Brainstorm

For the final project, I would like to create a basketball game. It will be viewed from a first person's point of view. Not sure how I will go about it, coding-wise; However I have certain ideas I wou

Matthew's Coding Blog: Algorithmic Bias

There is biasness in the online recruitment tools used there is a discovery made in Amazon that more than half of the percentage were male workers and that they held over more than 70% of the company

Post: Blog2_Post
bottom of page