G11_C2_For TeacherReference
Activity Flow | Slide No. | Topic | Time |
---|---|---|---|
TA | 5-6 | Warm-up Quiz | 1 min |
7 | Recap | 1 min | |
8-11 | Understanding variables | 5 min | |
12 | Arithmetic operations | 3 min | |
13-15 | TA - Coding (ball movement) | 3 min | |
SA | 16-19 | SA-coding (ball movement) | 4 min |
TA | 20-24 | Decision Making | 5 min |
25-27 | TA - Coding (ball movement with restriction) | 3 min | |
28-31 | SA - Coding (ball movement with restriction) | 5 min | |
Wrap - Up | 32-34 | Quiz | 2 min |
35 | Additional Activity | 10 min |
Slide No. | Topic |
---|---|
14 | TA Code- Ball movement |
18 | SA Code- Ball movement |
26 | TA Code- Ball movement with restrictions |
30 | SA Code- Ball movement with restrictions |
37 | Additional Activity 1- Code |
39 | Additional Activity 2- Code |
1. Computer with an Internet connection.
2. The latest browser installed.
3. Spyder IDE.
4. Projector to present the screen
1. Computer with an Internet connection.
2. The latest browser installed.
Option B is the correct syntax for creating a rectangle. We pass the x-position followed by the y-position, then the width and the height of the rectangle.
Choose the correct command for creating a rectangle in python.
What is the correct order to see a rectangle on screen?
A. Draw the rectangle on the screen.
B. Create a rectangle object
C. Pass the x coordinate , y coordinate, width and height.
Option B is the correct. We first create the rectangle object using the pygame.Rect() command. Then we pass the required parameters. Finally to see the rectangle, we need to draw the rectangle on the screen
import pygame
pygame.init()
WHITE = (255,255,255)
DARKBLUE = (36,90,190)
LIGHTBLUE = (0,176,240)
size=(600,600)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Breakout Game")
paddle=pygame.Rect(300,500,60,10)
ball=pygame.Rect(200,250,10,10)
ballx=1
bally=1
carryOn = True
while carryOn:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
carryOn = False # Flag that we are done so we exit this loop
screen.fill(DARKBLUE)
pygame.draw.rect(screen,LIGHTBLUE,paddle)
ball.x=ball.x+ballx
ball.y=ball.y+bally
pygame.draw.rect(screen,WHITE ,ball)
pygame.time.wait(20)
pygame.display.flip()
pygame.quit()
paddle=pygame.Rect(300,500,60,10)
ball=pygame.Rect(200,250,10,10)
ballx=1
bally=1
import pygame
pygame.init()
WHITE = (255,255,255)
DARKBLUE = (36,90,190)
LIGHTBLUE = (0,176,240)
size=(600,600)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Breakout Game")
paddle=pygame.Rect(300,500,60,10)
ball=pygame.Rect(200,250,10,10)
ballx=-1
bally=-1
carryOn = True
while carryOn:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
carryOn = False # Flag that we are done so we exit this loop
screen.fill(DARKBLUE)
pygame.draw.rect(screen,LIGHTBLUE,paddle)
ball.x=ball.x+ballx
ball.y=ball.y+bally
pygame.draw.rect(screen,WHITE ,ball)
pygame.time.wait(20)
pygame.display.flip()
pygame.quit()
> 60?
tab space
colon
Syntax:
import pygame
pygame.init()
WHITE = (255,255,255)
DARKBLUE = (36,90,190)
LIGHTBLUE = (0,176,240)
size=(600,600)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Breakout Game")
paddle=pygame.Rect(300,500,60,10)
ball=pygame.Rect(200,250,10,10)
ballx=-1
bally=-1
carryOn = True
while carryOn:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
carryOn = False # Flag that we are done so we exit this loop
screen.fill(DARKBLUE)
pygame.draw.rect(screen,LIGHTBLUE,paddle)
ball.x=ball.x+ballx
ball.y=ball.y+bally
if ball.x>=590:
ballx=-ballx
if ball.x<=10:
ball.x=-ballx
pygame.draw.rect(screen,WHITE ,ball)
pygame.time.wait(20)
pygame.display.flip()
pygame.quit()
import pygame
pygame.init()
WHITE = (255,255,255)
DARKBLUE = (36,90,190)
LIGHTBLUE = (0,176,240)
size=(600,600)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Breakout Game")
paddle=pygame.Rect(300,500,60,10)
ball=pygame.Rect(200,250,10,10)
ballx=-1
bally=-1
carryOn = True
while carryOn:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
carryOn = False # Flag that we are done so we exit this loop
screen.fill(DARKBLUE)
pygame.draw.rect(screen,LIGHTBLUE,paddle)
ball.x=ball.x+ballx
ball.y=ball.y+bally
if ball.x>=590:
ballx=-ballx
if ball.x<=10:
ball.x=-ballx
if ball.y>=590:
bally=-bally
if ball.y<=10:
ball.y=-bally
pygame.draw.rect(screen,WHITE ,ball)
pygame.time.wait(20)
pygame.display.flip()
pygame.quit()
x=5
if x<10:
print(x+4*10)
Option B is correct. There is an indentation error as the if statement should be followed by a tab space before each statement under the loop
x=10
x=x+6/3
if x==12:
print("True")
According to Bodmas division will be executed first before addition, so the equation will be solved as:
x=10+2 x=12
Hence the logical check will print True.
So option B is correct.
- Paddle will only move in x direction.
-Create "paddlex" variable
-Increment the paddle's x coordinate.
paddlex=2
paddle.x+=paddlex
import pygame
ballx=-1
bally=-1
paddlex=1
carryOn = True
while carryOn:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
carryOn = False # Flag that we are done so we exit this loop
screen.fill(DARKBLUE)
paddle.x=paddle.x+paddlex
pygame.draw.rect(screen,LIGHTBLUE,paddle)
ball.x=ball.x+ballx
ball.y=ball.y+bally
-Screen ranges from 0 to 600 in width.
-Paddle length is 60.
-So paddlex coordinate should be between 0 and 540.
-Similarly:
if paddle.x<0:
paddlex=-paddlex
if paddle.x>540:
paddlex=-paddlex
import pygame
pygame.init()
WHITE = (255,255,255)
DARKBLUE = (36,90,190)
LIGHTBLUE = (0,176,240)
size=(600,600)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Breakout Game")
paddle=pygame.Rect(300,500,60,10)
ball=pygame.Rect(200,250,10,10)
ballx=-1
bally=-1
paddlex=1
carryOn = True
while carryOn:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
carryOn = False # Flag that we are done so we exit this loop
screen.fill(DARKBLUE)
paddle.x=paddle.x+paddlex
if paddle.x>=540:
paddlex=-paddlex
if paddle.x<=60:
paddlex=-paddlex
pygame.draw.rect(screen,LIGHTBLUE,paddle)
ball.x=ball.x+ballx
ball.y=ball.y+bally
if ball.x>=590:
ballx=-ballx
if ball.x<=10:
ball.x=-ballx
if ball.y>=590:
bally=-bally
if ball.y<=10:
ball.y=-bally
pygame.draw.rect(screen,WHITE ,ball)
pygame.time.wait(20)
pygame.display.flip()
pygame.quit()
Activity | Activity Name | Link |
---|---|---|
Teacher Activity 1 | Ball Movement | |
Teacher Activity 2 | Ball Movement with restrictions | |
Teacher Activity 2(S) | Teacher Activity 2 solution | |
Student Activity 1 | Ball Movement | |
Teacher activity 3 | Ball Movement with restrictions | |
Teacher Activity 3(S) | Teacher Activity 3 solution | |
Student Additional Activity 1 | Paddle Movement | |
Teacher activity 4 | Paddle Movement (Student Additional Activity 1-Solution) |
|
Teacher activity 3 | Paddle Movement with restrictions (Student Additional Activity 2-Solution) |