Tuesday, July 13, 2021

Plinko Game (Part 2)

 



Step I: Create variables score and turn and assign both the values 0.


Step II: Since there will be only one particle while calculating the score, we need to create a variable particle so create a variable particle and assign its value to null and at the same time, remove the array particles we created in last post.


Step III: Display the score at your desire position. In my case, I am placing it at top right corner.



Step IV: In for loop of division in setup() function, change the variable from 5 to 0 the shift the divisions.


Step V:  Specify the points between the divisions using text.



Step VI: Now create a variable gameState and assign its value to play.


Step VII: Then we will use mouseReleased() function to create new particles at the x position similar to mouse x coordinate and y to 10 and assign it to variable particle which we created in step II.


Step VIII: Write the logic given below to determine in which division the particle is. After then, add the scores according to divisions and once the score is calculated, set the particle to null. At the same time, check that if the turn is greater then or equal to 5 or not. If it is greater then or equal to 5 then change the gameState to 'end'.



Step IX: Now, in mouseReleased() function, increase the turn by 1.


Step X: Then, in draw() function, display the text 'Game Over' using if condition when the gameState will be 'end'. Also, write one more if condition inside this if condition which will restart the game when we press 'ENTER' key.


Bug Fixing:

1. When the gameState is 'end', the plinko, divisions, ground and text of score should not be visible. So, for that, write an if condition that if gameState is not end, then inside it, display text of scores, divisions, plinkos and grounds.


2. When you press the mouse button when the particle is visible on screen, that particle goes vanished and new particle falls again or when the game over and you press the mouse button, the particle is created. To fix it, in mouseReleased() function, we have to write condition that if gameState  is not equal to 'end' or the particle is null, then only, a new particle must be created.



Video:-



Previous Post
Next Post

post written by:

0 Comments: