- 帖子
- 85
- 精华
- 0
- 积分
- 273
- 阅读权限
- 30
- 注册时间
- 2015-12-17
- 最后登录
- 2016-5-3
|
加了一些限制让飞机保持在窗口内- import pygame
- from sys import exit
- pygame.init()
- screen=pygame.display.set_mode((960,640))
- pygame.display.set_caption('Hello, World!')
- background=pygame.image.load('.\data file\pypic2.jpg').convert()
- plane=pygame.image.load('.\data file\plane.gif').convert()
- width=plane.get_width()/2
- height=plane.get_height()/2
- while True:
- for event in pygame.event.get():
- if event.type==pygame.QUIT:
- pygame.quit()
- exit()
- screen.blit(background,(0,0))
- x,y=pygame.mouse.get_pos()
- if y>=640-height:
- if x<width:
- screen.blit(plane,(0,640-2*height))
- elif x>960-width:
- screen.blit(plane,(960-2*width,640-2*height))
- else:
- screen.blit(plane,(x-width,640-2*height))
- elif y<height:
- if x<width:
- screen.blit(plane,(0,0))
- elif x>960-width:
- screen.blit(plane,(960-2*width,0))
- else:
- screen.blit(plane,(x-width,0))
- else:
- if x<width:
- screen.blit(plane,(0,y-height))
- elif x>960-width:
- screen.blit(plane,(960-2*width,y-height))
- else:
- screen.blit(plane,(x-width,y-height))
- pygame.display.update()
复制代码 |
|