设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
查看: 57853|回复: 0
打印 上一主题 下一主题

【Pygame 第5课】 游戏中的运动

[复制链接]

0

主题

0

好友

84

积分

注册会员

Rank: 2

楼主
发表于 2013-8-27 22:34:20 |显示全部楼层
在今天内容的基础上增加一行子弹。ps:两行子弹真霸气
  1. # !/usr/bin/python

  2. import pygame
  3. from sys import exit

  4. pygame.init()
  5. screen = pygame.display.set_mode((450, 800), 0, 32)
  6. pygame.display.set_caption("Hello, World!")

  7. bullet = pygame.image.load('bullet.png').convert_alpha() #load bullet image
  8. bullet1 = bullet
  9. backgroud = pygame.image.load('back.jpg').convert()
  10. plane = pygame.image.load('plane.png') #load plane image

  11. bullet_x = 0
  12. bullet_y = -1
  13. bullet1_x = 0
  14. bullet1_y = -1
  15. running = True

  16. while running:
  17.    for event in pygame.event.get():
  18.         if event.type == pygame.QUIT:
  19.            pygame.quit()
  20.            exit()
  21.   screen.blit(backgroud, (0, 0))
  22.   x, y = pygame.mouse.get_pos() # get the position of mouse
  23.    if bullet_y < 0:
  24.         bullet_x = x - bullet.get_width() / 2 - 23
  25.       bullet_y = y - bullet.get_height() / 2
  26.       bullet1_x = x - bullet.get_width() / 2 + 25
  27.      bullet1_y = y - bullet.get_height() / 2
  28. else:
  29.        bullet_y -= 3
  30.        bullet1_y -= 3
  31.   plane_x = x - plane.get_width() / 2
  32. plane_y = y - plane.get_height() / 2
  33.     screen.blit(bullet, (bullet_x, bullet_y))
  34.    screen.blit(bullet1, (bullet1_x, bullet1_y))
  35.     screen.blit(plane, (plane_x, plane_y))
  36.   pygame.display.update()
复制代码

2013-08-27 22:30:56的屏幕截图.png (90.64 KB, 下载次数: 532)

2013-08-27 22:30:56的屏幕截图.png

回复

使用道具 举报

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

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

GMT+8, 2024-5-3 00:25 , Processed in 0.019525 second(s), 24 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部