Informatics 9. Билингвальный учебник | страница 34



screen.fill(WHITE)


Keep in mind

To find RGB code of color you need you can use online color picker at

www.colorpicker.com


Flipping the Screen

Very important!

You must flip the display after you draw. The computer will not display the graphics as you draw them because it would cause the screen to flicker. This waits to display the screen until the program has finished drawing. The command below “flips” the graphics to the screen.


# Go ahead and update the screen with what we’ve drawn

pygame.display.flip()


Practice 1

1. Create a window (500 x 600 pixels);

2. Set background color to green;

Hint: use .fill() and .flip() methods.


Setting a background image

Any bitmap images used in a game should already be sized for how it should appear on the screen.

Don’t take a 5000 x 5000 pixel image from a high-resolution camera and then try to load it into a window only 800 x 600.

Loading an image is a simple process and involves only one line of code.


bkground_image = pygame.image.load(“image.jpg”)

“pygame.image.load” method is used to load an image.

The image needs to be converted to a format Pygame can more easily work with. To do that, we append .convert() to the command to call the convert function.


bkground_image=pygame.image.load(“image.jpg”).convert()

Call blit method to draw image on screen. This command should be done inside the loop so the image gets drawn each frame.

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

This code blit’s the image held in bkground_image to the screen starting at (0, 0).


Practice 2

1. Create a window (800 x 600 pixels);

2. Set title “Space Invaders“;

3. Find a space image and set to background.


Keep in mind

This file must be located in the same directory that the python program is in, or the computer will not find it.


Keep in mind

Loading the image should be done before the main program loop.


Literacy

1. Explain the steps of setting background image.

2. What is the difference between setting background color and background image?


Terminology

background - фон - фон

fill - толтыру - заполнить

flip - айналдыру - перевернуть

load - жүктеу - загрузить

append - қосу - присоединять

appear - пайда болу - появляться


4.3 DRAWING SHAPES. PYGAME ANIMATION.

You will:

Draw different shapes;

Program character movement.


What is the most important element in video games?

Drawing shapes

A program can draw things like rectangles, polygons, circles, ellipses, arcs, and lines.

pygame.draw.rect(Surface, color, (x, y, width, height), thickness)