Speaking of drawing, pygame provides some useful methods.DrawDrawing.
‘‘‘pygame.draw.rect - draw a rectangle shape draw a rectangle shapepygame.draw.polygon - draw a shape with any number of sides draw a shape with any number of sidespygame.draw.circle - draw a circle around a point draw a circle around a pointpygame.draw.ellipse - draw a round shape inside a rectangle draw a round shape inside a rectanglepygame.draw.arc - draw a partial s
Python is very extensible because there are a lot of pants and bags that can be swapped, oh, it's the library and the package.Whatever, after Gobang, there are XJM and HH and other people's advice, I also think you can try to learn to use these libraries to write a better game program.Here's the question, how do I install these libraries?The question was undoubtedly answered with XJM and without mercy ...As if I had not searched and ran to ask him, fortunately, HH showed me the street lamp, with
In short, it is an animated image.
Two member variables
1) self. Image = the surface of the image to be displayed
2) self. rect = displays the area of the surface,
Common Methods for setting rect: Self. rect = self. image. get_rect ()
Then set self. rect. topleft = () to set the position in the upper left corner to set the display position of the genie on the screen.
Member Functions
The following are sprite member functions. Update is used to update sprite images and is generally overwritten.
S
This article gives an example of how Pygame plays music. Share to everyone for your reference. Specifically as follows:
Method One:
?
1 2 3 4
Import pygame filename= '/home/a.mp3 ' pygame.mixer.music.load (filename) pygame.mixer.music.play (loops=0, start=0.0)
Method Two:
?
1 2 3 4 5
Import pygame filename= '/home/pe
This article describes how Python uses Pygame to play MIDI and MP3 files. Share to everyone for your reference. The implementation method is as follows:
"' Pg_midi_sound101.py play MIDI Music files (also mp3 files) using Pygame tested with python273/331 and pygame192 by ve
Gaseat ' Import Pygame as pg Def play_music (music_file): ' Stream music with Mixe
This series of blogs introduces the development of mini-games in the Python+pygame library. There is the wrong point of writing and hope you haihan.Until now we have learned a lot of pygame basic knowledge, starting from this blog we will learn the Pygame in the advanced part, more and the wizard module, conflict detection related knowledge.One, Sprite module, Sp
How to play music in pygame
This article describes how to play music in pygame. Share it with you for your reference. The details are as follows:
Method 1:
?
1 2 3 4
Import pygame Filename = '/home/A.mp3' Pygame. mixer. music. load (filename) Pygame.
Keys=pygame.key.get_pressed (), accept all keystrokes currently pressed in the game, and save them as a list, placed in the keys variablePygame. K_w tells Pygame you are checking the W key, by modifying the last letter, you can change it to any button you want to check.Import Pygamepygame.init () size=[400,300]screen=pygame.display.set_mode (size) clock=pygame.time.clock () done= Falsewhile not done:keys=pygame.key.get_pressed () if Keys[
This section implements a small ball program that moves freely in the window. It provides detailed comments and does not need to be explained.
Code:
[Python]#-*-Coding: UTF-8 -*-Import sysImport pygameFrom pygame. locals import *Def play_ball ():Pygame. init ()# Window sizeWindows size = (width, height) = (700,500)# Offset of the ball running [horizontal, vertical]. The larger the value, the faster the move
Then the last time to continue. A simple drawing function Pygame provides us with a few simple drawing functions, such as drawing rectangles, circles, ellipses, lines, and independent pixel points. The following program implements some simple drawing operations. Import Pygame, Sysfrom pygame.locals import *pygame.init () Displaysurf = Pygame.display.set_mode ((500,400), 0,32) BLACK = (0, 0, 0) White = (25
Simple pie game, mastering the Pygame of lines and arcs, as well as the response to input.1 ImportMath2 Importpygame, sys3 fromPygame.localsImport*4 Pygame.init ()5Screen = Pygame.display.set_mode ((600, 500))6Pygame.display.set_caption ("The Pie Game--Press 1 2 3 4")7MyFont = Pygame.font.Font (None, 60)8 9color = 200, 80, 60Tenwidth = 5 Onex = 300 Ay = 250 -RADIUS = 200 -Position = X-radius, Y-radius, radius*2, radius*2 the -Piece1 =False -Piece2 =
Pygame in common Python modules (Manual: home page), pythonpygame
Pygame manual Official Website:Http://www.pygame.org/docs/
Pygame Homepage
Instructions:
Self-Report
The basic information about Pygame, what is it, who participates in it, and where to find it.
Install
The steps required to comp
I used Python to write games. Getting started with pygame (5): Object-oriented game design, pythonpygame
There was a Moving bullet in yesterday's content. Although we only added one bullet, you can see that we need to record the x and y coordinates of the bullet and update its coordinates each time. If we want to have multiple bullets, We need to store multiple coordinates. At that time, the processing was not so simple. Maybe we can use two lists, on
Automatic tracking algorithm, in our design of 2D shooting games often used, this sounds very tall things, in fact, is not a military science patent, in mathematics to solve the words need to resolve the differential equation,It's hard to work out a mathematical basis. But we have a computer is not the same, relying on the computer very fast computing speed, we use the idea of differentiation, coupled with a simple triangular knowledge, we can achieve it.Well, don't say much, let's look at its a
Python pygame module usage example, pythonpygame
The example in this article describes the usage of the pygame module in python and shares it with you for your reference. The specific method is as follows:
import pygame, sys from pygame.locals import * #set up pygame pygame.init() windowSurface = pygame.display.set_m
installedBayiA package to uninstall0Packages that have1packages have not been upgraded. Need to download24.9MB/27.4MB of software packages. will be consumed after decompression86.9MB of extra space. Do you want to continue? [Y/n]After installation in the virtual environment:(kivy) ~/pythonvenv echo hg+http://bitbucket.org/pygame/pygame >> requirements.txt Install -R requirements.txt (kivyinstall)~/python
Import of the warranty retrieval module will not produce errors
Some modules in pygame are tested, such as camera, and may disappear one day.
Before writingCodeFault tolerance is required.
Try: Import sysimport randomimport mathimport osimport getoptimport pygamefrom socket import * From pygame. locals import * doesn t importerror, err: Print "couldn't load module. % s "% (ERR) sys. exit (2)
Compi
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.