uppygame.display.update ()#Refresh the screen .After you enter and run this code, you will get a picture like this:Clicking Close closes normally, and the title of the window becomes Hello, world!In this procedure, a lot of new concepts, such as events, are mentioned. I will continue to explain these concepts later.The code gives enough comments and believes that every friend who knows Python can read it.If you are not in touch with Python or have not learned to program, you can read my blog be
Pygame.ver1.9.1release123
>> Import Pygame>> Print Pygame.ver1.9.1release
Your version may be different from mine, it doesn't matter. The version of the book that I translated is still 1.7.1 ... So if there are outdated things out there, please don't hesitate to point them out!If you say why you want to introduce such an "outdated" thing, the real knowledge is not outdated, only the technology will. Here is mainly rely on
: direction = 'right' DISPLAYSURF.blit(catImg, (catx, caty)) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() pygame.display.update() fpsClock.tick(FPS)
In this example, the PDF of cat.png is provided. The downloaded file must be placed in a folder with the source file. The execution result is that a cat moves in a window. First right, then down, then left, then up, So loop.
Some new things appear in the above Co
Start making pygame games (1)
Start to enter the world of Python1. About this series
This will be a series of articles. It is my experience reading makeing games with Python pygame. Since the book is in English, I can organize it into an article in Chinese for your convenience. The author also wrote another book "inv
run to a maximum determined FPS value. The clock object will insert a small pause in the main game loop to ensure that our game program does not run too fast. If we don't have these pauses, our game will run as fast as the computer. It was really fast for the people who played the game. Calling the Tick () method of the clock object in the game loop will ensure that our game runs to a certain speed no matter how fast the computer runs. Create a Clock object with the following statement Fpsclock
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
bulletsbullet.append (Bullet ()) Interval_bullet= 25#number of frames fired bulletsIndex_bullet = 0#Initialize bullet coordinatesEnemy = [] forIinchRange (10):#total number of enemy aircraftEnemy.append (Enemy ()) Interval_enemy= 100#the interval at which the enemy aircraft appearedIndex_enemy = 0#Initialize the coordinates of the enemy aircraftClock =Pygame.time.Clock () whileTrue:#Game main Loop forEventinchpygame.event.get ():ifEvent.type = =Pygame
the activated bullet collided with the plane. theScore + = 10113 forEinchEnemies:#movement and description of enemy aircraft the ifCheckcrash (E, plane): theGameover =True the E.move ()117 Screen.blit (E.image, (e.x, e.y))118 Plane.move ()119Screen.blit (Plane.image, (PLANE.X,PLANE.Y))#Draw a plane -Text = Font.render ("score:%d"%score,1, (0,0,0))121Screen.blit (text, (0,0))#show fractions in the upper-left corner of the screen122 Else :123Text1 = Font.render ("score:%d
Similar to Python's built-in modules such as random, math, and time, the Pygame framework also has many modules to provide functions such as drawing, playing sound, and processing mouse input.
This chapter describes the basic modules and functions provided by Pygame, and assumes that the reader has basic python programming knowledge, read "Ivent Your Own Computer Games
Getting started with pygame for airplane vs. game with Python (4): getting the mouse position and motion, airplane vs. pygame
The target is a copy of the aircraft war, of course, after the copy, everyone will have the ability to add different content on their own.
First, you need to get some image materials. People who are familiar with image processing software and painting can make the materials by themse
This article mainly introduces how to use Python to get started with pygame for aircraft war games (4): Get the mouse position and movement. If you need a friend, refer to the next target for copying the airplane war, of course, after the copy, you will be able to add different content on your own.
First, you need to get some image materials. People who are familiar with image processing software and paint
2015/11/1 use Python to write a game. Getting started with pygame (1): installation of pygame and pythonpygame
Learning data structures and algorithms over the past two days is sometimes not as interesting as directly working on projects. I just learned how to use python. Now I am just making a small project.
Since I have always wanted to create a game, I want to use Python to create a basic game. I searche
, pygame cannot be installed.Sudo apt-Get install python2.6-DevInstall the corresponding development library based on the Python version of the machine. My Python version is 2.6.4, So I installed the 2.6 development library.You also need to install the python numeric library for processing vector and numerical computation, which is required by some games.Sudo apt-Get install Python-numeric Python-numpy Python-scipy
5. Install
Reprint Please note: @ small Wuyi http://www.cnblogs.com/xiaowuyi
Pygame. mixer is a module used to process sound and its meaning is "mixer ". In the game, the processing of sound generally includes two parts: making sound and playing sound. Here, only the playing sound is learned.1. Start and initialize pygame. MixerPygame. mixer. INIT (): Initialize mixer.Program, Usually put in the first fewCodeMedium:
Pygame is a python module designed to develop games. In fact, pygame is the same as time, OS, and SYS. Today, I officially started learning pygame: www.pygame.org. After the download, the installation is complete. In pygame's learning, I used the SPE editor, and it feels good.
1.
Pygame event-control object (airplane) movement and pygame event
Recently, I want to use pygame as a game. I learned this thing from xishui's eye-catching blog. I just wrote my own code for the plane war, it mainly optimizes the keyboard control plane movement.
#-*-Coding: UTF-8-*-import pygamefrom pygame. locals impor
Python Pygame and pythonpygame
1. Experiment Introduction
1.1 experiment content
In this lesson, we will explain the common objects and operations of Pygame, including graphics, animations, text, and audio, to ensure that you have a basic understanding of Pygame, at the same time, make preparations for subsequent courses.
1.2 experiment knowledge points
Pygame method of playing music, pygame playing music
This article describes how to play music in pygame. Share it with you for your reference. The details are as follows:
Method 1:
Import pygamefilename = '/home/A.mp3' pygame. mixer. music. load (filename) pygame. mixer.
This article mainly describes the detailed Python pygame installation process notes. 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.
See a tutorial today about Python Installing the Pygame module. Feel good, share it.
Install Python
Well, this little problem seems to be superfluous here. But in order to take care of
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.