最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
python如何方向键控制上下左右
时间:2018-01-22 编辑:猪哥 来源:一聚教程网
本文所示代码实现python编程方向键控制图片上下左右,我们首先看下演示结果。
演示:
实例代码:
bif="1.jpg" mif="2.jpg" import pygame,sys from pygame.locals import * pygame.init() screen=pygame.display.set_mode((640,360),0,32) background=pygame.image.load(bif).convert() mouse_c=pygame.image.load(mif).convert_alpha() x,y=0,0 movex,movey=0,0 while True: for event in pygame.event.get(): if event.type ==QUIT: pygame.quit() sys.exit() if event.type==KEYDOWN: if event.key==K_LEFT: movex=-1 if event.key==K_RIGHT: movex=+1 elif event.key==K_UP: movey=-1 elif event.key==K_DOWN: movey=+1 if event.type==KEYUP: if event.key==K_LEFT: movex=0 if event.key==K_RIGHT: movex=0 elif event.key==K_UP: movey=0 elif event.key==K_DOWN: movey=0 x+=movex y+=movey screen.blit(background,(0,0)) screen.blit(mouse_c,(x,y)) pygame.display.update()
相关文章
- Golang ProtoBuf的基本语法详解 10-20
- Python识别MySQL中的冗余索引解析 10-20
- Python+Pygame绘制小球代码展示 10-18
- Python中的数据精度问题介绍 10-18
- Python随机值生成的常用方法介绍 10-18
- python3解压缩.gz文件分析 09-27