设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
楼主: crossin先生
打印 上一主题 下一主题

【Pygame 第3课】 游戏中的事件

[复制链接]

2

主题

0

好友

50

积分

注册会员

Rank: 2

楼主
发表于 2013-11-21 20:18:02 |显示全部楼层
  1. import pygame

  2. from sys import exit

  3. pygame.init()

  4. screen = pygame.display.set_mode((700, 170), 0, 32)

  5. pygame.display.set_caption("Hello, World!")

  6. bg1 = pygame.image.load('bg.jpg').convert()
  7. bg2 = pygame.image.load('bg2.jpg').convert()
  8. bg3 = pygame.image.load('bg3.jpg').convert()
  9. i=1
  10. bglist=[bg1,bg2,bg3]
  11. num=len(bglist)
  12. background=bglist[0]


  13. while True:

  14.     for event in pygame.event.get():
  15.         if event.type == pygame.QUIT:
  16.             pygame.quit()
  17.             exit()
  18.         if event.type == pygame.MOUSEBUTTONDOWN:
  19.             background=bglist[i]
  20.             i=i+1
  21.             if i>num-1 :
  22.                 i=0
  23.         screen.blit(background,(0,0))
  24.         pygame.display.update()
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-5-7 00:19 , Processed in 0.018673 second(s), 22 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部