Python and Pygame game developmentDirectory1th. Installing Python and Pygame 11. 1 Preliminary Knowledge 11. 2 Downloading and installing Python 11. 3 Installation instructions under Windows 11. 4 Installation Instructions on MAC OS x 21. 5 installation on Ubuntu and LinuxDescription 21. 6 Starting Python 21. 7 Installing Pygame 31. 8 How to read this book 41. 9
didn't really know how to use that skill to make something cool."
Recently, pygame has been found to be a treasure. We also found the tutorial. So I started my research immediately. I hope you will feel the same after watching pygame.4. About Python
Python is an object-oriented scripting language. The syntax is concise and clear. I have read and recommended "Python basics tutorial (version 2nd)" And later
This article mainly introduces Python's function of converting the mouse arrow into a graph by using pygame to replace the mouse movement effect. It involves pygame's graphic operations and has some reference value, for more information, see the example in this article. We will share this with you for your reference. The details are as follows:
Think about the school pygame now has a few minutes, and I wro
Here is a small series to bring you a installation of Python and Pygame and the corresponding environment variable configuration (graphics tutorial). Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.
hello,everyone!
Python is a good thing! Well, to Li someone this shabby praise, really can't on the table, hope forgive me. Then let's go straight to the dry.
First
According to the plan of last week, start learning pygame today.
1. hello world Program of pygame version.
Code:
[Python]#! /Usr/bin/python#-*-Coding: UTF-8 -*-Import sys# Import the pygame module. Line 4 is used to simplify your input. For example, you do not need to add the pygam
, then delete my source code and repeat it again, which makes it easier to master the use of pygame. Of course, this simple thing does not require so detailed learning for most skilled programmers. You can simply look at it.
Python error handling
The program will always go wrong, and pygame often runs like this. At that time, there was no way to force the progra
1, single pixel (draw point)
There are three main ways to draw points using Pygame:Method One: Draw a square with a length of 1 pixels
Copy Code code as follows:
Import Pygame,sys
Pygame.init ()
Screen=pygame.display.set_caption (' Hello world! ')
Screen=pygame.display.set_mode ([640,480])
Screen.fill ([255,255,255])
Pygame.draw.rect (sc
1, single pixel (draw point)
There are three main ways to draw points using Pygame:Method One: Draw a square with a length of 1 pixels wide
The code is as follows:
Import Pygame,sysPygame.init ()Screen=pygame.display.set_caption (' Hello world! ')Screen=pygame.display.set_mode ([640,480])Screen.fill ([255,255,255])Pygame.draw.rect (screen,[0,0,0],[150,50,1,1],1) #画1 a rectangle with a line width of 1, whic
This article mainly explains how to solve the error when pygame loads mp3 files of Chinese names. it has some reference value. if you are interested, refer to # pygame to play mp3 files:
Here I will only introduce a good understanding method.
Open the official document and I found that, like discovering the new world, this guy is so powerful, but now I can only use it to play my mp3. well, let's explore i
Installation
Start by installing all necessary dependencies, and mercurial and checkinstall for the installation:
1
sudo apt-get install python3-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python-numpy libportmidi-dev ffmpeg libswscale-dev libavformat-dev libavcodec-dev checkinstall mercurial
Then download the latest version ofPygame source code with the following command (this uses mercur
library is a very important part of Python, and we can use these libraries to implement a number of functions. Our goal is to achieve a small game through Pygame! What exactly does it do? I've got the direction! is to do a PC-side aircraft war ~ because this game mode is simple, functional clear, simple interface, very well in line with our expected goals. But I'd like to reiterate here that this idea is not what I came up with, but I found it on Git
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
Yesterday, there is in the Raspberry Pi operation Pygame, but the Raspberry Pi again on the net, very strange, my 306wifi display is the Raspberry Pi connection success, but is unable to use the network, so you can not download pictures, wait for the HDMI line bar.Now, look at the Little turtle's video has been half a year, thanks to his fun and no moral integrity language led me into the vast world of programming, I know the next road can only go on
must "blit" them (copying their meaning) onto the display object via the Blit () method. Animation It's really simple to move an image from one place to another, to erase the image from where it was originally, and then load the image in another place so that it looks like it's moving. In the computer's view, it is actually a group of pixels moving. is an example Here is a sample code Import Pygame, Sysf
Bought a book, but the book is too pit not the correct method of installation, so I can only my own officer net dead Chew English. The software was downloaded and suddenly realized why I didn't search videos and blogs. Here are some ways to explore yourself.Official portal
Python official website: https://www.python.org/
Pygame Official website: http://pygame.org/news (I do not know why this website always bring a news, I think this is a
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, vertica
Pygame.mixer is a module for handling sounds, meaning "mixer". In the game, the sound processing generally includes making the sound and playing the sound two parts, here only learns to play the sound part.
1, Pygame.mixer Startup and initialization
Pygame.mixer.init (): Initialization of the mixer. In a program, when used, it is generally placed in the first few lines of code:
Copy Code
.
The key to object-oriented is encapsulation. Let's take a look at how to encapsulate a bullet.
The most important thing to describe a bullet is its image and coordinate position. It requires so much, there is also a piece of code for handling the bullet display.
# Define a Bullet class that encapsulates the data and methods of bullets. class Bullet (object): def _ init _ (self): self. x = 0 self. y =-100 self. speed= 600 self. image =
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.