G12_C1_For TeacherReference

Introduction to Programming with Python

Activity Flow Slide no Topic Time
TA 4 Ice-breaker 3 min
5-12 Programming Intro 2 mins
10-13 Object Oriented Programming 3 mins
14-20 Introduction to Python + Spyder + Pygame 3 mins
21-31 TA - Coding 15 mins
SA 32-36 SA 5 mins
Wrap-Up 37-40 Quiz 1mins
SAA 41 Additional Activity 5 mins

CLASS STRUCTURE

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

Slide no Topic
22-30 Basic pygame code
34-35 SA Code - Creating enemy rect.
41 Additional Activity - Code

FOR PREPERATION & REFERENCE

Prerequisites

FOR STUDENTS

  1.  Computer with Internet connection.

  2. Latest browser installed.

FOR TEACHER

  1. Computer with Internet connection.

  2. Latest browser installed.

  3. Spyder IDE

  4. Projector to present screen.

M.S. Dhoni

Cristiano Ronaldo

Maria Sharapova

Tiger Woods

Roger Federer

Serena Williams

Lionel Messi

Identify the Personalities

Human vs Computer

B

As we know computer understands 0 and 1

then how do we communicate with the computer?

Programming Languages

B

Why should we learn Python?

Object-Oriented Programming

B

Guess the object in this game!

B

Smiley

Four Enemies

Food

B

Can you guess the Properties and Functions of a car?

Properties

Functions

Color

Name

Tyres

Drive()

Break()

Horn()

GREAT!

B

We will be creating some exciting games in the coming classes!

Let's understand about programming?

Where and how to write the program?

B

Spyder

Spyder IDE Download Instructions: Link

Spyder IDE Download: Link

1. Editor

4. Tabs

5. Run

3. Console

2. Main Menu

Spyder

B

Pygame Library

B

import pygame

Step 1: Download and install the "pygame" library

Step 2: Create a new file in Spyder and save it as "trex.py"

Step 3: Import the "pygame" library to your code

B

Step 4: Initialize the "pygame"

Step 5: Use "pygame" to create a window

Output:

import pygame

pygame.init()
import pygame

#initialising pygame and its functions 
pygame.init()

# creating game window and title
screen = pygame.display.set_mode((400,600))
    

B

Step 7: Use "pygame.display.set_caption()" to set title of game.

import pygame
#initialising pygame and its functions 
pygame.init()
# creating game window and title
screen = pygame.display.set_mode((400,600))
pygame.display.set_caption("Asteroid")

B

Output :

B

Step 8: Use "pygame.image.load" to change the background image.

import pygame

#initialising pygame and its functions 
pygame.init()

# creating game window and title
screen = pygame.display.set_mode((400,600))
pygame.display.set_caption("Draw Rectangle")

# Display game window 
background_image = pygame.image.load("bg2.jpg").convert()
##.blit() is how you copy the contents of one screen to another.
screen.blit(background_image,[0,0])

B

Output :

B

Coordinate system in pygame

y

x

0,0

width

height

pygame.Rect(50,70,40,40)

x

y

width

height

B

What is RGB (Red, Green, Blue) Combination in Programming?

B

Step 9: Use "pygame.draw.rect()" to draw a rectangle on screen.

Set Blue Color Through RGB combination

BLUE=(0,0,255)

pygame.draw.rect(screen,BLUE,player)

Draw Rectangle on screen

pygame.display.update()

Update Screen

player=pygame.Rect(200,200,30,30)

Create Rectangle

B

Output :

B

Student Activity 1 : Draw a white Rectangle on (100,100) coordinate with size 30,30. Name white Rectangle as 'enemy'.

 

 

Earlier we created Recttangle of Blue color.First We set Color of Rectangle then we create rectangle and after that we have to update the screen.

 

Hint : Earlier we created blue Rectangle , Now we need to create white Rectangle as shown in output. Take help of following code.

import pygame
#initialising pygame and its functions 
pygame.init()
# creating game window and title
screen = pygame.display.set_mode((400,600))
pygame.display.set_caption("Draw Rectangle")
# Display game window 
background_image = pygame.image.load("bg2.jpg").convert()
#.blit() is how you copy the contents of one screen to another.
screen.blit(background_image,[0,0])
#Color or rectangle
BLUE=(0,0,255)
#Draw Rectangle of blue color [left, top, width, height]
pygame.draw.rect(screen,BLUE,(200,200,100,50))
#Update the screen after pasting rectangle on it
pygame.display.update()

#Draw WHITE Rectangle on given coordinates
#Draw WHITE Rectangle on given coordinates
WHITE=(255,255,255)
enemy=pygame.Rect(100,100,30,30)
pygame.draw.rect(screen,WHITE,enemy)
pygame.display.update()

Student Activity 1: Solution

What is the correct statement to use pygame library?

A

C

B

Import pygame

IMPORT pygame

import pygame

Q.1

D

export pygame

import pygame as written here is the correct option.

All the letters in the "import" keyword must to be in lowercase.

C

import pygame

WHITE=(255,255,255)

White_rect=pygame.Rect(100,100,30,30)

--------------------- -------

pygame.display.update()                                              

Fill in the missing line if we want to display the rectangle?

A

C

B

pygame.init()

screen.blit(background_image,[0,0])

pygame.draw.rect(screen,WHITE,White_rect)

Q.2

D

import pygame

In this given question, a rectangle is created using rect().

pygame.draw.rect() function helps to draw the rectangle on the screen.

C

pygame.draw.rect(screen,WHITE,White_rect)

B

Link:     https://bit.ly/3gTdwnO

Student Additional Activity 2:

Creating multiple rectangles on ​same y-axis

Hint: 

 

WHITE=(255,255,255)
enemy=pygame.Rect(100,100,30,30)
pygame.draw.rect(screen,WHITE,enemy)
pygame.display.update()

Links Table

ACTIVITY NUMBER ACTIVITY NAME LINKS
Teacher Activity 1 Spyder information
Teacher Activity 2 Spyder install instructions
Teacher Activity 3 Adding White Rectangle(Student Activity Solution-1)
Teacher Activity 4 multiple rectangles on ​same y-axis(Additional Activity-1)
Student  Activity 1 Blue Recrangle
Aditional Activity 1 Adding Rectangle on Y-axis

Copy of G12_C01_For_Teacher

By anjali_sharma

Copy of G12_C01_For_Teacher

  • 90