Moving Pipes

G9_C13_ForTeacher(ANJALI)

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

Activity Flow Slide No. Topic Time
3-7 Revision + Quiz 2 mins
8-18 Introduction to
Lists
12 mins
TA 19-23 TA-Coding 10 mins
SA 24-29 Student Activity 10 mins
Wrap-Up 30-32 Wrap-Up Quiz 2 mins
SAA 33-34 Additional Activities 10 mins

Class Structure

Slide No. Topic
13 Lists in python
20-23 TA Coding Steps
36 Activity Links Table

Preparation and Reference

TA: Teacher Activity        SA: Student Activity        SAA: Student Additional Activity

What we did in the last class?

(WARM-UP QUIZ)

In python constructor function is named as __init__

Q.1

Which one of these is a constructor function?

def __init__():

3

2

1

4

def constructor():

init():

def construct():

1

def __init__():

randInt() function generate only integer between the given range.

Q.2

What will be the random number generate by this line?

Integer between 5 and 10

3

2

1

4

Either of 5 or 10

All numbers between 5 and 10

15

1

Integer between 5 and 10

random.randInt(5,10)

You can go ahead

Magic?

Annie: Delhi

Sam : Noida

Jack : Gurgram

John : Gurgram

Math's Maic

Annie: Delhi

Sam : Noida

Jack : Gurgram

John : Gurgram

Step 1: Think of a two digit number.

Step 2: Multiply it with three. (16 x 3 = 48)

Step 3: Add 6 to this number. (48 + 6 = 54)

Step 4: Divide it with three. (54 / 3 = 18)

Step 5: Subtract the number chosen in step 1 with step 4 (18–16= 2)

Guess the Trick

Annie: Delhi

Sam : Noida

Jack : Gurgram

John : Gurgram

Factory

Zoetrope

Change with earlier class image

Movement of pipes.

Annie: Delhi

Sam : Noida

Jack : Gurgram

John : Gurgram

Step 1:  Create the move() function that will move the pipes

Steps to complete the activity

Step 2: Call the move function inside the game loop to move each created pipe.

 

Steps to complete the activity:

Oputput:

 

Student Activity- Add a Bottom pipe and another pipe object

Make Infinite Pipes

Task: Reset the pipe to original position when it get's out from left edge.

Hint:

1. Check inside the move() function if the pipe moved out from left edge.

 

 

2. Move both top and bottom pipe to right edge of the screen

 

Output:

Change positioning of top and bottom pipe

Task: Change the positioning of top and bottom pipe when reset.

Hint:

1. Update value of gap randomly after restting the pipe

 

 

2. Set top and bottom pipe according to the gap.

 

Steps to complete the activity:

Q.1

Which if these is correct way to define a method in a class?

name():

1

def name():

2

def name(self):

3

3

def name(self)

While defining a method in a class we need to give at least one argument that will poitn to current object.

function name(self):

4

Class name must be in same case as it is defined

How to create an object of following class?

book1 = Book()

3

2

1

book1 = Book()

book=book()

1

class Book:
    price=10
    author="xyz"
    
    def showPrice(self):
      print(self.price);


Book= book(self)

Q.2

ADDITIONAL ACTIVITY - 1

Task: Make bird go on top if it goes out from bottom.

Hint:

1. Check if bird is moved out from bottom. (In gravity function)

 

 

2. Set bird.y to 0 to move it to the top.

 

ADDITIONAL ACTIVITY - 1

Solution:

Hint: 1. Load the cloud image in the images dictionary

2. Place the cloud image on the screen

 

ADDITIONAL ACTIVITY - 1

Solution:

Hint: 1. Load the cloud image in the images dictionary

2. Place the cloud image on the screen

 

ADDITIONAL ACTIVITY - 2

Task: Make the bird Move to bottom if it goes out from top.

Hint:

1. Check if bird is moved out from top. (In gravity function)

 

 

2. Set bird.y to 600 to move it to the bottom.

 

ADDITIONAL ACTIVITY - 2

Solution:

Hint: 1. Load the cloud image in the images dictionary

2. Place the cloud image on the screen

 

Links Table

Activity  No. Activity Name Links
Teacher Activity 1 Bee 3
 
Teacher Activity 2 Bee 4 -SA solution
Teacher Activity3 AA1- Solution
Teacher Activity4 AA2 Solution
Student Activity 1 Bee 3.5
Additional Activity 1 Bee 3.5
Additional Activity 2 Bee 3.5

AND OR Debugging

G9_C14_ForTeacher

Activity Flow Slide No. Topic Time
3-7 Revision + Quiz 2 mins
8-18 Introduction to
Lists
12 mins
TA 19-23 TA-Coding 10 mins
SA 24-29 Student Activity 10 mins
Wrap-Up 30-32 Wrap-Up Quiz 2 mins
SAA 33-34 Additional Activities 10 mins

Class Structure

Slide No. Topic
13 Lists in python
20-23 TA Coding Steps
36 Activity Links Table

Preparation and Reference

TA: Teacher Activity        SA: Student Activity        SAA: Student Additional Activity

What we did in the last class?

(WARM-UP QUIZ)

In python constructor function is named as __init__

Q.1

Which one of these is a constructor function?

def __init__():

3

2

1

4

def constructor():

init():

def construct():

1

def __init__():

randInt() function generate only integer between the given range.

Q.2

What will be the random number generate by this line?

Integer between 5 and 10

3

2

1

4

Either of 5 or 10

All numbers between 5 and 10

15

1

Integer between 5 and 10

random.randInt(5,10)

You can go ahead

There is a party!

Boy: White shirt and blue pent.

Girls: White dress or blue dress

Choose according to dress code

Boy: White shirt and blue pent.

White shirt and blue pent

White shirt and blue pent

White shirt and blue pent

Choose according to dress code

Girls: White dress or blue dress

White dress or blue dress

White dress or blue dress

White dress or blue dress

and / or in programming

Condition1

Condition2

and

True

False

True

True

False

True

False

False

True

and / or in programming

Condition1

Condition2

or

True

False

True

True

False

True

False

False

True

True

Game ends when the Bee hits Pipe

Annie: Delhi

Sam : Noida

Jack : Gurgram

John : Gurgram

pipe1.topPipe

pipe1.bottomPipe

pipe2.topPipe

Pipe2.bottomPipe

or

Behavior in various states

Annie: Delhi

Sam : Noida

Jack : Gurgram

John : Gurgram

Play

Over

1. Bird is visible

2. Pipes are visible

3. Ground is moving

1. Game Over is visible

 

Step 1:  Create a variable state="play"

Steps to complete the activity

Step 2: Check if pipe1 collided with bee and make the state="over"

 

Step 3:  Create If condition for "over" state.

Steps to complete the activity

Step 4: Display "gameover" image inside "over" state if-block

 

Steps to complete the activity:

Output:

 

Good Going Team! Keep up the spirit!

Student Activity- Add a Bottom pipe and another pipe object

Show pipes and bird only in play state

Task: Stop Everything once bee hits the pipes

Hint:

1. Create a play state if block.

 

 

2. We only need to show pipes and bird in the play state, so move the display function inside the play state if block

 

Code:

Make the game end when any pipe is touched by the bee

Task: Make the bee collide with pipe2 also

Hint:

1. Add the condition to check collision between pipe2 and bird using OR key word.

 

 

 

 

bee.bee.colliderect(pipe2.topPipe) or bee.bee.colliderect(pipe2.bottomPipe)

Code:

bee.gravity() 
    
    if groundx< -330:
        groundx=0
        
    if bee.bee.colliderect(pipe1.topPipe) or bee.bee.colliderect(pipe1.bottomPipe) or bee.bee.colliderect(pipe2.topPipe) or bee.bee.colliderect(pipe2.bottomPipe) :
        state="over"
     
    pipe1.move()
    pipe2.move()
    
    if state=="play":
        bee.display()  
        pipe1.display() 
        pipe2.display() 
        groundx =groundx-5

Q.1

Which of these is used when we need to check if all condition are true before doing a task?

or

1

not

2

and

3

3

and

The "and" keyword makes sure all conditions are true before doing a task.

Two

4

"or" will return true when either of two condition is satisfied. i.e. or makes sure if block runs even if a single condition is true.

What will come in place of "?" if we want to repeated the course when one either of two condition is true. i.e marks<35 , attendance<35 

or

3

2

1

and

not

2

if marks<35  ?  attendance<35:
	#repeate the course

or

Q.2

ADDITIONAL ACTIVITY - 1

Task: Print the state of the game to console and see how it changes.

Hint:

1. Use print() to print the state of the game to console. 

 

 

 

ADDITIONAL ACTIVITY - 1

Solution:

Hint: 1. Load the cloud image in the images dictionary

2. Place the cloud image on the screen

 

ADDITIONAL ACTIVITY - 2

Task: Add comments in the code for each code block.

Hint:

1. Use # symbol to add Comments in the code.

 

Links Table

Activity  No. Activity Name Links
Teacher Activity 1 Bee 3
 
Teacher Activity 2 Bee 4 -SA solution
Teacher Activity3 AA1- Solution
Teacher Activity4 AA2 Solution
Student Activity 1 Bee 3.5
Additional Activity 1 Bee 3.5
Additional Activity 2 Bee 3.5

deck

By anjali_sharma