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
All games have interaction with the user, in computing these are known as Interrupt Events.
When a specific event is heard by the Event Listener, an action is then performed by the Event Handler code.
Look in the shell/interpreter window, located in the bottom section of the Thonny window or in the terminal window for Python IDLE.
You might see output like this:
Try holding the CTRL, ALT or SHIFT keys while pushing other keys. The interpreter window output will now change slightly to show that the keys have been modified.
KeyUp and KeyDown are different events. What's the difference?
Look at the example below then copy and paste the lines from the Thonny/Python console in the bottom window which show the events returned for each of the following:
<Event(1025-MouseButtonDown {'pos': (113, 439), 'button': 3, 'window': None})>
<Event(1026-MouseButtonUp {'pos': (113, 439), 'button': 3, 'window': None})>
Lets first make our square we are going to move around we will do this using variables for all its values.
Add this line of code to your program under ## your code starts here
screen.fill(black) pygame.draw.rect(screen, green, (XPos, YPos, squareWidth, SquareHeight))
Now lets put in the values for the variables for our square
XPos = 100 YPos = 100 Speed = 5 squareWidth = 20 SquareHeight = 20
Run your code to make sure it works
In order for us to check if a key has been pressed we need to first look for a KEY DOWN event.
if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: XPos -= Speed
Now press your left arrow key and see what happens
Add some more if statements to your code so that you can move your square up down and right using the key codes pygame.K_RIGHT, pygame.K_UP, pygame.K_DOWN
Just like last week When our square gets to the edge of our screen it disappears.
We want the whole square to stay on the screen To do that we need to check the two different x-cordinates at either side of the screen.
Can we change the value of Speed by using a key press?
Can you also add a moving circle using with the technique we used last lesson?
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