Computer Science LearnITWithMrC ⛯ Year 7 Year 8 Year 9 GCSE
Responsive image

Move it

What am I Learning today?

I am learning how to draw squares and other shapes using co-ordinates and dimensions
I am learning how to change variables to change the state (position, colour etc) of a game object
I am learning how to create game animation by using repetition and changing game object states.

Knowledge Organiser

×

Lesson

Task 1 - Getting Started Click to see more

You are going to screenshot all of your work into a Powerpoint file.

To download the PowerPoint by clicking on the image below

To save your powerpoint go to:

  • File explorer
  • -> Year 9 Common Area :S
  • -> You can save here
  • -> Computer Science
  • -> Term 3
  • -> Lesson 2
  • Save the Powerpoint file: as your name


  • Complete Task 1 in your Powerpoint


  • Task 2 - Drawing a Square Click to see more

    Drawing a square:

    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))

    Task

    1. Change the x co-ordinate so that we are at the edge of the screen
    2. Change the width and height so that it is 25px

  • When you are finished screenshot your working code into your Learning Journal


  • Task 3 - Redrawing our square Click to see more

    Redrawing our square

    If we want our square to move accross our screen we have to do two things:

    1. Change the x co-ordinate value.
    2. Redraw the square

    If we want to redraw our square each time we need to make the x co-ordinate a variable.

    Activity

    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

    Task: Redrawing a square

    Does it look like this when you run it?

    Task: Removing the old image

  • When we want to keep drawing something in pygame we need to clear the old image away we can do that using our screen variable and the .fill() function
  • Add this code to the line above where you draw your square.
  • screen.fill(black)
  • Now run your code again

  • When you are finished screenshot your working code into your Learning Journal



  • Can you change the speed of the square?
  • Can you change the direction of the square?
  • Can you stop it disappearing off of the edge of the screen?

  • When you are done screenshot your working code into your Learning Journal


  • Task 4 - Adding some boundaries Click to see more

    Finding the edges of the screen

    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



  • Can you make the square go backwards when it gets to the edge of the screen?

  • When you are finished screenshot your working code into your Learning Journal


  • Task 5 - Changing Direction Click to see more

    We want the square to not only stay on the screen but to bounce off either edge. To do that we need to check the two different x-cordinates at either side of the screen.

  • We have already done this once. Rather than reset our xposition to 0, what about if we made our block move backwards?
  • We could do that by making the value of squareSpeed a negative number.

    Task

    1. Change the value of squareSpeed to a negative number whenever our x-cordinate is greater than the SREENWIDTH.
    2. Change the value of squareSpeed back to a positive number whenever our x-cordinate is less than 0.

  • When you are finished screenshot your working code into your Learning Journal


  • Task 6 - Moving circles Click to see more

    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?


  • When you are finished screenshot your working code into your Learning Journal


  • Task 7 - Lesson Review/Homework Click to see more


    Summing it all up

    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

    Learning Outcomes I need to learn how to change variables to change the state (position, colour etc) of a game object

    • I have a basic understanding of how I can change variables to change the state (position, colour etc) of a game object with a little help from my teacher
    • I can show my teacher that I can change variables to change the state (position, colour etc) of a game object without their help.
    • I can change variables to change the state (position, colour etc) of a game object independently and I can also explain it to others and can complete any extension tasks I am given.

    🠜 Now update your learning objectivesClick on the Assessment image



    My Notes: Game Development

    Student_Comment_3 not found

    Task Notes/Comments - Add here Click to see more

    Comments/Notes