You are going to screenshot all of your work into a Powerpoint file.
To save your powerpoint go to:
Save the Powerpoint file: as your name
If you remember from our last lesson in order for us to draw a square we only need the co-ordinates for the top left hand corner of the square and then the height and width in pixels. For a square the height and width should be the same.
Les's draw a square whose corner starts at (x100,y100) and whose width and height is 50px using the code below:
pygame.draw.rect(screen, green, (100,100,50,50))
If we want our square to move accross our screen we have to do two things:
If we want to redraw our square each time we need to make the x co-ordinate a variable.
How can we keep increasing the value of our variable xposition so that it gets bigger each time we go through our while loop?
We could create another variable called squarespeed and make it equal to say 4 and then add it to our variable xposition
Let's try it
Does it look like this when you run it?
When our square gets to the edge of our screen it disappears. This is not much use to us in a game.
Lets try and first work out where the edge of the screen is and then maybe reset our position so that we go back to the start.
We know the screen width because we create it with this line of code
SCREENWIDTH = 640 # sets the width of the screen/window
So in our code we could check if our xposition was greater or equal to our SCREENWIDTH and if it was reset it to 0
if xposition >= SCREENWIDTH: xposition = 0
We could do that by making the value of squareSpeed a negative number.
Can you now make a moving circle using the same technique you did for the square?
Can you change it's movement so it also moves in in our y axis?
Lets look at the learning outcomes and decide which one best describes our current level of understanding :
Tick the one you feel is closest to your level