设为首页收藏本站

Crossin的编程教室

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

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

[复制链接]

0

主题

1

好友

114

积分

注册会员

Rank: 2

楼主
发表于 2016-9-10 00:59:44 |显示全部楼层
改了下子弹的X坐标,变成散弹了
  1. # -*- coding: utf-8 -*-
  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. background = pygame.image.load('back.jpg').convert()
  8. plane = pygame.image.load('plane.png').convert_alpha()
  9. bullet=pygame.image.load('bullet.png').convert_alpha()
  10. bullet1=bullet
  11. bullet2=bullet
  12. bullet_x=0
  13. bullet_y=-1
  14. bullet1_x=0
  15. bullet1_y=0
  16. bullet2_x=0
  17. bullet2_y=0
  18. while True:
  19.     for event in pygame.event.get():
  20.         if event.type == pygame.QUIT:
  21.             pygame.quit()
  22.             exit()
  23.     screen.blit(background, (0,0))
  24.     x, y = pygame.mouse.get_pos()
  25.     if bullet_y<0:
  26.         bullet_x=x-bullet.get_width()/2
  27.         bullet_y=y-bullet.get_height()/2
  28.         bullet1_x=x-bullet.get_width()/2-23
  29.         bullet1_y=y-bullet.get_height()/2
  30.         bullet2_x=x-bullet.get_width()/2+23
  31.         bullet2_y=y-bullet.get_height()/2
  32.     else:
  33.         bullet_y-=2
  34.         bullet1_y-=2
  35.         bullet1_x-=0.5
  36.         bullet2_y-=2
  37.         bullet2_x+=0.5
  38.     screen.blit(bullet,(bullet_x,bullet_y))
  39.     screen.blit(bullet1,(bullet1_x,bullet1_y))
  40.     screen.blit(bullet2,(bullet2_x,bullet2_y))
  41.     x-= plane.get_width() / 2
  42.     y-= plane.get_height() / 2
  43.     #print (x,y,bullet_x,bullet_y)
  44.     screen.blit(plane, (x,y))
  45.     pygame.display.update()
复制代码
回复

使用道具 举报

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

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

GMT+8, 2024-5-4 02:25 , Processed in 0.029233 second(s), 22 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部