G12_C1_For TeacherReference
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 |
Slide no | Topic |
---|---|
22-30 | Basic pygame code |
34-35 | SA Code - Creating enemy rect. |
41 | Additional Activity - Code |
M.S. Dhoni
Cristiano Ronaldo
Maria Sharapova
Tiger Woods
Roger Federer
Serena Williams
Lionel Messi
B
As we know computer understands 0 and 1
then how do we communicate with the computer?
B
B
B
Smiley
Four Enemies
Food
B
Properties
Functions
Color
Name
Tyres
Drive()
Break()
Horn()
B
B
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
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
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
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
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.
Link : https://bit.ly/3vUsTkd
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()
What is the correct statement to use pygame library?
import pygame as written here is the correct option.
All the letters in the "import" keyword must to be in lowercase.
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?
In this given question, a rectangle is created using rect().
pygame.draw.rect() function helps to draw the rectangle on the screen.
B
Link: https://bit.ly/3gTdwnO
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()
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 |