To finish off my game I had to create different speeds for my squares.
The middle square – which is controlled by the users click of the control button, moves faster than the right and left squares.
The left square – chases the middle square at a slower speed than the middle and right square.
The right square – chases the middle square at a faster speed than the left square but slower than the middle square.
In order to not have my squares get stuck on top of each other I had to set a timer which starts off the squares at different times.
The slow square is the left square. Here is the code that I used to chase the middle square. The timer sets off the square to move, this time period gives the user some time to move the middle square and give it a “head start”.
For the right square I did the same thing but changed the starting time higher than the left square.
The Final game looks something like this.
With the next version I was able to make the square bounce when it hits the edge of the screen.
Now that I had the first square working correctly, I added the rest of my squares. The left and right square. The user only controls the middle square.
In the first 3 versions of my myGame I have been able to change the colors of my game screen, buttons, and also the color of my first square. I also made this square move by having the user use the control buttons. The middle button changes the square color, while the left button makes the square move left, the right button makes the square move right, the up button makes the square move up and the down button makes the square move down.
Though the square is moving with the right buttons, the square does not bounce when it hits the edge of the game screen.
In this game, there will be a ray of 3 squares who follow each other. If a square hits the edge of the screen then the squares will bounce
A picture on how my game will look on the screen
- Is powered by the button controls
- The buttons control the squares direction
The numbers in parenthesis show how many variables needed
- Square (3)
- Square size (1)
- Square width
- Square height
- Color of Square (3)
- Motion of Square (3)
- Square speed (1)
- Window size (1)
- Button size (1)
bounce.pde is code that was added onto control.pde