GRADE-11 C2
Object Movement
Activity Flow | Slide No. | Topic | Time |
---|---|---|---|
TA | 3 | Ice-breaker | 1 min |
5-10 | Programming Intro | 2 min | |
11-16 | Object Oriented Programming | 3 min | |
17-22 | Introduction to Python + Spyder + Pygame | 3 min | |
23-28 | TA - Coding | 15 | |
SA | 29-31 | SA | 5 min |
Wrap - Up | 32-36 | Quiz | 1 min |
38 | Additional Activity | 5 min |
Class Structure
Slide No. | Topic |
---|---|
11 | Random number code |
23-25 | Basic pygame code |
31-32 | Making rectangles |
36 | SA Code- Creating enemy rect. |
45 | Additional Activity- Code |
Preparation and Reference
PRE REQUISITES
FOR TEACHER
-
Computer with internet connection
-
Latest browser installed
-
Spyder installed
-
Projector to present screen
FOR STUDENTS
-
Computer with internet connection
-
Latest browser installed
Let's play a game
Human vs Computer
B
Programming Languages
B
Learning Programming
B
Learning Programming
B
Object-Oriented Programming
B
Guess the object in this game!
B
Pac-Man
Four Ghosts
Pac-Dots
Power Pelletes
Can you guess the Properties
and Functions of a car?
B
Properties
Color
Name
Tyres
Functions
Drive()
Break()
Horn()
GREAT!
We will be creating lots of
new and different games
B
Breakout game
B
Complex game! Let's break it down
B
Where and how to write the program?
B
English
Integrated development environment (IDE)
Python + Spyder
B
B
Pygame Library
B
import pygame
Step 1: Download and install the "pygame" library
Step 2: Create a new file in Spyder and save it as "spaceinvaders.py"
Step 3: Import the "pygame" library to your code
B
Step 4: Initialize the "pygame"
Step 5: Use "pygame" to create a window
Output:
import pygame
pygame.init()
import pygame
pygame.init()
screen = pygame.display.set_mode((400,600))
B
Step 6: Add a game loop
Output:
import pygame
pygame.init()
screen = pygame.display.set_mode((400,600))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
B
Coordinate system in pygame
y
x
500
width
height
pygame.Rect(200,500,30,10)
x
y
width
height
0,600
400,0
400,600
0,0
200
(40)
(40)
B
Step 7: Use "pygame.Rect()" to make a rectangle
import pygame
pygame.init()
screen = pygame.display.set_mode((400,600))
player=pygame.Rect(200,500,30,10)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
B
Guess why character
is not displayed?
B
pygame.draw.rect(surface, color, rect)
Drawing !
B
(Red, Green, Blue)
Red color -> (255, 0, 0)
B
Step 8: Draw the rectangle on the screen
Step 9: Update the screen
import pygame
pygame.init()
screen = pygame.display.set_mode((400,600))
player=pygame.Rect(200,500,30,30)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.draw.rect(screen,(23,100,100),player)
pygame.display.update()
B
Output :
B
Output :
B
Step 10: Create another rectangle named "ball" and draw it on the screen
import pygame
pygame.init()
screen = pygame.display.set_mode((400,600))
paddle=pygame.Rect(200,500,30,30)
ball=pygame.Rect(70,50,10,10)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.draw.rect(screen,(23,100,100),paddle)
pygame.draw.rect(screen,(255,255,255),ball)
pygame.display.update()
(WRAP-UP QUIZ)
What will be the correct syntax for pygame.draw.rect(_,_,_)
B
Color,Surface,Rect
Surface,Color,Rect
Rect,Color,Surface
Q.1
A
Surface,Color,Rect
B
C
We first pass the surface, then the color, then the name of the rectangle
Activity | Activity Name | Link |
---|---|---|
Teacher Activity 1 | Paddle creation | tinyurl.com/2ce8cctx |
Student Activity 1 | Ball creation | https://tinyurl.com/fmsuy4pp |
Additional Activity 1- Solution | Ball creation_AA | https://tinyurl.com/ymx5pu7m |
Links Table
Copy of Copy of G11_C1
By Sanjukta Bhattacharya
Copy of Copy of G11_C1
- 86