[Python] Pygame module design game

Pygame is a cross platform Python module designed for video games, including images and sounds. Based on SDL, real-time video game development is allowed without being bound by low-level languages (such as machine language and assembly language).

The history of Pygame
Pygame is a written game library using SDL library. SDL, full name of Simple DirectMedia Layer, was written by Sam Lantinga, a big bull. It is said that he created this thing in order to make Loki (a good company dedicated to porting Windows games to Linux, but it has failed) work more effectively.
SDL is written in C, but it can also be developed in C + +. Of course, there are many other languages. Pygame is a library used in Python. Pygame has existed for a long time, and many excellent programmers have joined in it to make Pygame better and better.

This article is just a brief introduction to Pygame getting started

1. Install Pygame module pip install Pygame

2. Specific code information:

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#By cacho_
#Blog: https://blog.csdn.net/sinat_37967865
#File: pygameModel.py
#Date: September 23, 2018
#Note: pip install pygame cross platform Python module is specially designed for video games, including images and sounds.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

import pygame                   # Import pygame Library
import sys



size = width, height = 650, 487          # Set the game window size, from right to left are sequence assignment and tuple assignment

pygame.init()                            # Initialize pygame
screen = pygame.display.set_mode(size)   # Initialize game window
pygame.display.set_caption("my first pygame program")      # Set game window title
background = pygame.image.load('./images/background.jpg')  # Set game window background picture
target = pygame.image.load('./images/PYG02-ball.gif')      # Load target image
# BLACK = 0, 0, 0                                            # Set background color


'''''''''
//Process game exit, loop from message queue
'''''''''
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

#Message queuing, some actions
    # screen.fill(BLACK)                   # Background fill (the background color has been set during initialization and needs to be filled)
    screen.blit(background, (0, 0))        # Draw background picture
    pygame.display.update()                # Update screen (last step to update screen)

 

Keywords: Python pip Assembly Language Windows

Added by cetaces on Fri, 27 Dec 2019 17:12:14 +0200