pygame的学习日记

下载好pygame

 1 sudo apt install python-pygame 

 

spyder ubuntu软件程序里找到它,下载下来

 

run-configue 设置代码运行时候,

console选项

第一个 使用ipython 这个就是他自己的里面运行

第二个是另开一个窗口 一般选择这个   如果觉得不习惯可以换,还在这里

 

'import sitecustomize' failed; use -v for traceback 出现这个是因为端口冲突,不用管了

打不开img.png 因为你的图片和代码小程序没有放在一起

convert_alpha() makes your program run a lot faster

作者用的时sublime2 text编辑器

 

 

 

1  def __init__(self,x,y, width, height, image_string):   #方法
2         
3         BaseClass(self,x,y, width, height, image_string)                          发现错误出现在这一行,baseclass后面没跟init 解决了也不行
4         Bug.list.add(self)
5         self.velx = 3
6     
7     def motion(self):             #另一个方法
8                     
9         self.rect.x += self.velx

 

 

1 'import sitecustomize' failed; use -v for traceback
2   File "/media/gkgy/新加卷/python Mes/pythonsoft/untitled4.py", line 10
3     class BaseClass(pygame.sprite.Sprite):     #精灵
4                    ^
5 SyntaxError: invalid syntax

 


or

1 Traceback (most recent call last):
2   File "/media/gkgy/新加卷/python Mes/pythonsoft/untitled5.py", line 10, in <module>
3     from untitled4 import *
4   File "/media/gkgy/新加卷/python Mes/pythonsoft/untitled4.py", line 10
5     class BaseClass(pygame.sprite.Sprite):     #精灵
6                    ^
7 SyntaxError: invalid syntax

 

 

 

什么嘛 视频跟不上了,有问题,没人叫

 

换一个

learn how to program  好像没意思https://www.reddit.com/r/inventwithpython 这个有讨论贴,每一章节的讨论贴

inventwithpython_3rd 这个

MakingGames 这个比较相对难一点

 

动画

 1 import pygame, sys
 2 from pygame.locals import *
 3 
 4 pygame.init()
 5 
 6 FPS = 30 # frames per second setting                             越大图像越快
 7 fpsClock = pygame.time.Clock()
 8 
 9 # set up the window
10 DISPLAYSURF = pygame.display.set_mode((400, 300), 0, 32)       #网址 ctrl+f 搜索set mode 就可以找到说明 宽和高 flags(屏幕的类型)
11 pygame.display.set_caption('Animation')                         #标题
12 
13 WHITE = (255, 255, 255)
14 catImg = pygame.image.load('cat.png')
15 catx = 10
16 caty = 10
17 direction = 'right'                                 #向右
18 
19 while True: # the main game loop
20     DISPLAYSURF.fill(WHITE)
21 
22     if direction == 'right':
23         catx += 5
24         if catx == 280:
25             direction = 'down'
26     elif direction == 'down':
27         caty += 5
28         if caty == 220:
29             direction = 'left'
30     elif direction == 'left':
31         catx -= 5
32         if catx == 10:
33             direction = 'up'
34     elif direction == 'up':
35         caty -= 5
36         if caty == 10:
37             direction = 'right'
38 
39     DISPLAYSURF.blit(catImg, (catx, caty))             #应该是把load的图像复制到面板上,否则显示不出来  后面是变量,是不是因为要随时把图像复制
40 
41     for event in pygame.event.get():
42         if event.type == QUIT:
43             pygame.quit()
44             sys.exit()
45 
46     pygame.display.update()
47     fpsClock.tick(FPS)

 

posted @ 2016-09-18 09:44  gkgy  阅读(147)  评论(0)    收藏  举报