G12_C2_For Teacher Reference
True
False
Activity Flow | Slide no | Topic | Time |
---|---|---|---|
TA | 4 | Last class revision + quiz | 1 min |
5-12 | Class Introduction | 2 mins | |
11-16 | Variable activity on console | 3 mins | |
17-22 | Game loop | 3 mins | |
23-28 | TA | 15 mins | |
SA | 29-31 | SA | 5 mins |
Wrap-Up | 32-36 | Quiz | 1mins |
38 | Additional Activity | 5 mins |
Slide no | Topic |
---|---|
23-25 | Basic pygame code |
31-32 | Making rectangles |
36 | SA Code - Creating enemy rect. |
45 | Additional Activity - Code |
Here, red and blue are given '0' value, so the only color left is green.
B
B
B
B
name
color
age
String type <----- type( )
Teacher Activity - Variables and operations in console
Addition of two numbers
Changing sign of a number
Multiplying two numbers
import pygame, random, sys
pygame.init()
clock=pygame.time.Clock()
screen = pygame.display.set_mode((400,600))
pygame.display.set_caption("Astroid")
background_image = pygame.image.load("bg2.jpg").convert()
BLUE=(0,0,255)
player=pygame.Rect(200,200,30,30)
WHITE=(255,255,255)
enemy=pygame.Rect(100,100,30,30)
while True:
screen.blit(background_image,[0,0])
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
pygame.draw.rect(screen,BLUE,player)
pygame.draw.rect(screen,WHITE,enemy)
pygame.display.update()
clock.tick(30)
Game loop
1. Define a variable to hold velocity in x-axis
2. Update x-axis value to move astroid/enemy to left
B
0
400
x
600
-250
Changing velocity to change direction
enemy.x =enemy.x + xvel
B
Game loop
Change velocity when reading left edge
Change velocity when reaching right edge
B
Use "or" to combine both if conditions as we have to change xvel in both.
B
Hint: We can update both x and y axis values to make asteroid move in diagonal.
1. Define a variable to hold velocity in x-axis
Update Y-axis value by adding yvel
Hint: We can change yvel (as we did for x-axis) also to make asteroid move back and forth on y-axis.
marks =79
x=10
y=20
type(x)
type(y)
y="20"
y = int(y)
type(y)
ACTIVITY | ACTIVITY NAME | LINKS |
---|---|---|
Teacher Activity 1 | Asteroids 1.1 | |
Teacher Activity 2 | Asteroids 2 | |
Student Activity 1 | Asteroids 1.5 |