Hi, welcome back.
In this lecture, we will complete our game and adding a bouncing poll arcade game like Pong Game are
based on a frame based animation where the screen is refreshed every specific milliseconds and moving
sprites are doing by using X and Y coordinates or axis.
And they have a variety vector V, X and VI, which is specified the Delta and vectors to apply to X
and Y coordinates or position or axis of as between two friends.
So to move the Sprite across the game, display or screen, it will need to bounce against a Sprite
or against the edge of the screen or the game play.
So we will copy the code and the battle module and it in a new file.
And name it as bull, but by then it that last name from bottle to glass bowl with the capital and we
will add after the line of code that draws correct.
Mesud.
Self-taught velocity equals.
A list of rendang between two parenthesis rendang, four and eight, and Ron it.
Minus eight and a close saw, self-taught, wealthy, when Ekwall, a list of two ran, then it off
to table four and eight or minus eight and a so Zahran then, which is part of a random module, will
it chose between four and a four varity Hendrick's zero or minus eight and a four velvety index one.
So we will add this in bold statement from random and bold rond in it.
Now we will add a function that will upgrade the ball.
Velocity has the following and it will take one parameter which is self.
So def update between two parentheses self column.
And inside this function, we will add self-doubt, recht dot x.
Plus, equal self-doubt, first index zero.
And for the movement or the validity of the bowl ads, the X, Y or the Y position will be as the following
self-taught Recht not Y plus equal self-doubt versity between two square brackets, one and X number
one, OK.
Finally, we want to add a function to Zabol class that will make our ball bounce.
And we'll take also self as the only parameter, so Jeff Ball underscored bouncing between two parentheses
self column and inside this function we will add self-doubt.
Where's the index number zero equal minus self see?
And zero and self-taught versity.
Between two square brackets, one equal self-doubt versity.
And that's number one, then we will add the ball to the game that by five and the following using the
object of class, so we will import the class pool as a falling from pole balls ball with B capital.
Then we will add the ball to the ball boy as a foul ball will equal the ball class opposite ball ekwall
ball with capital B between two parentheses Y and Tony and Tony.
This will be the colour and width and the height of the ball rectangle, so ball, dot, dot, x equals
four hundred and ball the dot Y equals two hundred.
Now we will add the sprite of our ball and the following.
So sprites underscored last dot at between two parentheses ball.
Now we will add the ball bouncing algorithm which will control the two methods of the ball class.
But first we will add an after statement which contain event type or another, even the type.
Has the following F even type equal by game dot K down column and inside this F statement, we will
add another nested F statement as the following f even Doti will equal by game the K capital under score
x small column.
So game underscore on equal falls.
Now we can add the ball bouncing algorithm at the following after as bright as update method f statement
ball dot dot x more than or equal seven hundred add column for ball dot t of index zero equal minus
ball.
That was the.
Of Index zero.
So Zabol that wrecked that X.
If equal or more than seven.
Hundred and eighty bexell.
The validity of index zero will equal mine as well as the.
Of Index zero, Zabol will move in another or the opposite position and we will return the X and Y position
of the ball as the following Zabol Lautrec but to be equal 400 and the ball to attract the Y to be two
hundred.
Zabol will return to the position that it was in at the beginning of the game.
And we will copy this statement for time.
OK?
But we change in the second time that the ball got wrecked, that X less than or equal to then add the
column and we will let the rest of the F statement as it is.
Then adding that's her statement as the following involved dot, red dot, why more than five hundred
and eighty so self dot Melasti.
But in here, we will change the index to be.
One.
Then we will add.
Another statement, which is a false statement, if both dot dot, why more than not more than less
than zero collomb.
So the dot was the one equal minus the the one.
And we can change zero to be do.
And check the identity of our good.
And add the fifth statement as a following, if I gave that Sprite Dot Cleide underscore must.
Missile and inside this missile, we will add two parameters, which are bold, bright and better.
One is bright.
Or.
By game dot dot Cleide underscore mask.
Ball and puggle to.
And at Collomb.
Then inside the statement, we will add.
Ball bouncing.
Method which exist inside.
Zable class.
Hold the ball, goodbye.
Five.
As you see.
Now we can build out Rosie to check.
If our game run correctly or not.
So let's build our Rosie.
After building our music, we have an air of.
As you see.
So we will.
Solve this error the following.
The error due to adding self parameter outside the ball.
That by five or Polglase.
So we will add more.
And instead of self so bold that wealthy, not self, not wealthy, we will change all.
They're mistaken.
Or the ad by mistake self-doubt fallacy and change it to Paul Valency.
And run our project again.
We will get another error that we have no attributes of pygame called gay.
Underscore X.
So we will it sends even the time to even dot gay, which contain by game dot gay, underscore X and
run our project again and we get another Aros.
Which as we at gays small, which is incorrect by game dot k capital, underscore X small and run out
again and get other errors, which is an error in moving up and moving down methods of the battles.
So we will head over the battle.
Goodbye file to check this error, which is due to.
Number of bexell.
I'm not.
Assigned to the the threat we by mistake or.
Commit an error.
By adding Bexell.
And instead of number of pics, so we will change it to number of pixels.
And go to bonke dot, buy and build our product again, it will run.
Without re importing the Zabol, so this.
This error is due to we add the position of the ball that wrecked X due time without remembering to
add X and Y, so we will add X and Y and the ball, the track position.
To be X equals four hundred and Y equal two hundred.
Also, we will change the speed of the game or the speed of the ball to be six instead of seven.
But we have another mistake or error.
That's all.
Only.
Balance and one direction without.
Making another angle of the reverse direction, this will be solved and the following year will change
the weight of the middle line, then we will change the method of bouncing self-support velocity of
an X one equal self-taught velocity and X one and build our Brusic to get the following rhythm.
And also, will it change the update method as the following to be said would attract dot y plus equals
self-taught, wealthy and x1 and run our project again.
And our game will run fine without any errors and with the ball, the correct ball movement.
And the correct ball bouncing algorithm, as you see, and we need to change some numbers and battle
Dobi and the weather moving down massive.
So self the track that way, more than four hundred seventy five column.
And inside the statement itself, dot, dot y equals four hundred seventy five and bailed out again
to run our game and it will run correctly without any error.
And with the correct ball movement and bouncing.
We can also change these numbers to four hundred and sixty which more appropriate.
And we will check that by building our project again as the following to run correctly without any error
and with the most and the best ball movement and bouncing.
As you see at this moment.
We reached the end of this lecture.
We enjoyed this lecture and get all of that.
Thank you for watching and thank you for being here.
See you next lecture.