G12_C8
Boundary Definition and Score Update
Activity Flow | Slide No. | Topic | Time |
---|---|---|---|
4-10 | Warm up Quiz+Revision | 5 min | |
TA1 | 11-16 | Teacher Activity 1 | 7 min |
TA2 | 17-19 | Teacher Activity 2 | 6 min |
SA1 | 20-25 | Student Activity 1 | 7 min |
SAA 1 | 26 | Student Additional Activity 1 | 3 min |
SAA 2 | 27 | Student Additional Activity 2 | 3 min |
28-30 | Post Class Quiz | 4 min |
Slide No. | Topic |
---|---|
18 | TA1 solution |
21 | TA2 solution |
25 | SA1 solution |
29 | SAA1 solution |
30 | SAA2 solution |
Class Structure
Preparation and Reference
Pre-Requisites
FOR TEACHER
FOR STUDENTS
1. Computer with an Internet connection.
2. The latest browser installed.
3. Spyder installed.
1. Computer with an Internet connection.
2. The latest browser installed.
3. Spyder installed.
4. Projector to present the screen
(WARM-UP QUIZ)
When do the objects collide ?
Q.1
B
When the x-axis if the objects matches, they collide
C
When the y-axis of the objects matches, they collide
D
None of these
When the x-axis and y-axis of the objects matches, they collide
A
Which of the following functions, you used to detect, whether the bullet hit the enemy or not ?
D
colliderect()
Q.2
C
pygame.quit()
B
screen.blit()
A
pygame.Rect()
Revise!!
- Display game window
- Draw blue and white rectangle
...
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,69,0), ball)
...
- Study of Game loop
- Moving the enemy in x direction
...
xvel=2
if event.type == pygame.QUIT:
pygame.quit()
enemy.x=enemy.x+xvel
...
- Events and rotating the player in left and right direction.
...
if event.type == pygame.KEYUP:
if event.key ==pygame.K_LEFT or event.key == pygame.K_RIGHT:
change= 0
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
change =3
if event.key ==pygame.K_RIGHT:
change = -3
...
def newxy(oldx,oldy,distance,angle):
angle=math.radians(angle+90)
nx=oldx+(distance*math.cos(angle))
ny=oldy-(distance*math.sin(angle))
return nx,ny
newimg=pygame.transform.rotate(player_image,angle)
- Flying of the spaceship across x and y axis and updating the distance covered by it
for enemy in enemies:
enemy.x+=xvel[i]
enemy.y+=yvel[i]
if enemy.x < -250 or enemy.x > 650:
xvel[i] = -1*xvel[i]
if enemy.y < -250 or enemy.y > 850:
yvel[i]=-1*yvel[i]
if bulletState == "ready":
bullet.x=player.x+15
bullet.y=player.y+15
if bulletState=="fired":
bullet.x ,bullet.y = newxy(bullet.x, bullet.y, 20 , angle)
if bullet.y<0 or bullet.x<0 or bullet.y>600 or bullet.x>400:
bulletState="ready"
if bullet.colliderect(enemy):
enemy.x=1000
enemy.y=1000
- Implementing Lists and assigning velocities to enemies in x and y direction
- Adding bullets to the spacecraft and implementing firing feature
- Once the bullet hit the asteroid/enemy, the enemy will be removed from the screen
Objective of today's class: Game features that are yet to be added
- Defining game boundary and reassigning position of the spacecraft
- Update player scores and display them on game window
- Game Over text to be added into the game
This slide should be removed
Teacher Activity 1:
We are re-assigning the coordinates of the spaceship, once the spaceship crosses the game boundary
...
if player.x < 0 :
player.x = 400
elif player.x > 400 :
player.x =0
elif player.y < 0 :
player.y = 600
elif player.y > 600 :
player.y =0
...
Output Teacher Activity 1:
Objective of today's class: Game features that are yet to be added
- Defining game boundary and reassigning position of the spacecraft
- Update player scores and display them on game window
- Game Over text to be added into the game
English
Mathematics
Science
Social Science
Computers
This slide should be removed
Teacher Activity 2:
We are going to display the score, at the top left corner of the game window.
...
if bullet.colliderect(enemy):
enemy.y=random.choice([random.randint(-250,0),random.randint(600,840)])
print(enemy.y)
enemy.x=random.choice([random.randint(-250,0),random.randint(400,640)])
print(enemy.x)
score+=1
...
scoretext=game_font.render("Score : " + str(score),False,(200,200,200))
screen.blit(scoretext,(10,10))
...
Output Teacher Activity 2:
Objective of today's class: Game features that are yet to be added
- Defining game boundary and reassigning position of the spacecraft
- Update player scores and display them on game window
- Game Over text to be added into the game
*** Note to Illustrators ***
Add a gif here, in which, John and other students are sitting in classroom and are giving exam.
After sometime, the clock strikes 12 PM and teacher announces "Time Up"
This slide should be removed
Student Activity 1:
Students are required to code in the given template, about displaying the text "Game Over"
Template link: https://bit.ly/3dJrDtS
Hints:
- Define a variable "over" and initialize it's value to "False".
- When enemy collides with the player, assign "True" to "over".
- Replace the player image with the enemy image.
- Display the "GAME OVER" text using the render()
Solution link:
GREAT!
Solution
Student Additional Activity 1:
Resize the game window to 600x400
Template
Solution
Student Additional Activity 2:
Updating score by 10, everytime the bullet hits the enemy
Template:
C
Which of the following statements update score by 5 ?
Q.1
Which of the following is the correct sequence of commands, that are to be executed by Spyder Interpreter ?
C
Q.2
A
B
C
G12_C8 Anjali
By anjali_sharma
G12_C8 Anjali
- 132