G12_C7_For_Teacher

Collosion

Activity Flow Slide No. Topic Time
TA Last class revision+quiz 1 min
Functions introduction 6 min
Calculation of new x,y 6 min
Teacher activity 8 min
SA Student activity 8 min
Wrap - Up Quiz 5 min
Additional activity

Class Structure

Slide No. Topic
23-25 Function intro code
31-32 TA- Code

Preparation and Reference

Prerequisites

FOR STUDENTS

  1. Computer with Internet connection.

  2. Spyder IDE installed. 

  3. "pygame" package installed.

FOR TEACHER

  1. Computer with Internet connection.

  2. Latest browser installed.

  3. "pygame" package installed.

  4. Spyder IDE installed.

What we did in the last class?

Same images

(WARM-UP QUIZ)

Same images

When an object change its behaviour, this is called?

A

State

Nature of object 

 

Q.1

A

Position 

 

B

C

When an object change its state, Its behaviour also change. So option A is correct.

D

Movement

 

Which of the following library helps us to randomize the items of a list?

B

seed

pygame

Q.2

A

random

B

C

random library is use to randomize the number or list. Right option is B

D

sys

Same images

Game Feature to be added

In previous class, we learned state of bullet like ready and fired state. In this classs we will learn if bullet hit the asteroid/enemy, enemy will loss from screen.

How to disapper asteroid/enemy when bullet hit the enemy

0,0

400

600

John is playing spinner game with his friends.There are many options written on spinner such as 'Dance','Story Telling','Singing','Mimicry' and so on. Each friend will spin the spinner and have to do activity as he found on spinner.

Teacher Activity-Select a random option from given choice

import random


Activities = ['Singing','Mimicry','Story Telling','Drama','Dance']


print(random.choice(Activities))

import random library

create list of activites

random.choice function return the random value from given list.

How collision can be detect in objects

x-axis

y-axis

1

2

3

4

When objects having same x or y-axis then collosion happen

Teacher Activity- Lets understand with example when two object get collosion

import pygame
a = pygame.Rect((1, 1), (2, 2))
b = pygame.Rect((0, 0), (2, 2))
c = pygame.Rect((0, 0), (1, 1))

print(a.colliderect(b))


print(a.colliderect(c))


print(b.colliderect(c))        

Output is 1 because y-axis of a and b is same

Output is 0 because both axis of and is different

Output is 1 because x-axis of b and c is same

GREAT!

Same images

Same images

Teacher Activity

Step 1 - Bullet hit enemy

 

Same images

Creating rectangle for bullet

if enemy.y < -250 or enemy.y > 850:  
      evly[i] = -1*evly[i]
      i+=1    
      
if bullet.colliderect(enemy):

      enemy.y=random.choice([random.randint(-250,0),random.randint(600,840)])
      
      enemy.x=random.choice([random.randint(-250,0),random.randint(400,600)])
      
 screen.blit(enemy_image,enemy)     
  
  if forward:     

Check if bullet collide the enemy

Find a random number of x and y-axis and set location of enemy.x and enemy.y on that location, which actually does not exist. So it will disappear the enemy

Same images

B

Task: Kill the enemy when a bullet hits the enemy, withouf using random.choice method.

Same images

Hint 1:  Set position of enemy at a location which does not exist on game window.

 

 

Same images

 i+=1    
    if bullet.colliderect(enemy):
        
        #enemy.x=1000
        #enemy.y=1000
        
      

10

Any number but not beteen 10,101

Q.1

Any number between 10 and 101

A

B

D

Either 10 or 101

C

random.choice( ) return a random number from a given list. So correct answer is D

 

1

Q

import random

num = random.choice(range(10, 101))
print(num)

What would be output of following code:-

Two rectangles are moving in a 2-D plane. A rectangle has (2,4,2,2) coordinates and B rectangle has (0,0,2,2) coordinate. If we use A.colliderect(B), What would be output?

 

A and B object will not collide.

A and B will Collide

Corner of Both objects will collide

Error in Syntax

A

B

C

D

Q 2

A and B are moving on different axis. A is on 2,4 coordinate and B is on 0,0 coordinate. So they will not collide. Correct answer is A

B

Hint:

1. create a list of 1 to 6 number.

2. Use random library

 

Additional Activity-1

Task: Create a dice game for your friends. When your friend run the game,each time they get a different number from 1 to 6.

Same images

Output :

 

B

Additional Activity-2

Task: Count that how many enemies are destroyed by spaceship.

Same images

Output :

 

Hint:

1.initialize a variable named score with 0.

2.Write your code in given line.

Same images

Activity Activity Name Link
Teacher Activity 1 Bullet Creation
Teacher Activity 2 Bullet hitting Enemy
Teacher Activity 3 Kill the enemy
Student Template Bullet hitting Enemy
AA1 dice game
AA2 print Score

Links Table

https://bit.ly/3jkiGe8

https://bit.ly/361Zqu7

https://bit.ly/361Zqu7

Copy of G12_C7_New_For_Teacher

By anjali_sharma

Copy of G12_C7_New_For_Teacher

  • 91