设为首页收藏本站

Crossin的编程教室

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

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

[复制链接]

0

主题

1

好友

78

积分

注册会员

Rank: 2

13#
发表于 2014-1-7 18:26:53 |只看该作者
浮生湮灭了美好 发表于 2013-10-19 19:01
先生我想问下 那个坐标为什么是还有子弹上移是我觉得本来应该是+的在第四象限。 ...

我感觉pygame里的坐标是反着的。-是朝上和朝右,+是朝下和朝左。
回复

使用道具 举报

0

主题

0

好友

101

积分

注册会员

Rank: 2

12#
发表于 2013-10-19 23:57:34 |只看该作者
虚心求教
回复

使用道具 举报

0

主题

1

好友

80

积分

注册会员

Rank: 2

11#
发表于 2013-10-19 19:01:00 |只看该作者
先生我想问下 那个坐标为什么是
  1. bullet_x = x - bullet.get_width() / 2
  2.         bullet_y = y - bullet.get_height() / 2
复制代码
还有子弹上移是
  1. bullet_y -= 5
复制代码
我觉得本来应该是+的在第四象限。
回复

使用道具 举报

174

主题

45

好友

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

10#
发表于 2013-8-28 20:24:16 |只看该作者
OrangeScript 发表于 2013-8-28 14:53
这样写可以吗?

不太对哦
你运行试试

这样每次都会把子弹坐标设在鼠标位置上,然后。。。后面逻辑有点乱
#==== Crossin的编程教室 ====#
微信ID:crossincode
网站:http://crossincode.com
回复

使用道具 举报

1

主题

0

好友

15

积分

新手上路

Rank: 1

9#
发表于 2013-8-28 14:53:51 |只看该作者
本帖最后由 OrangeScript 于 2013-8-28 14:57 编辑
  1. # -*- coding: utf-8 -*-
  2. import pygame
  3. from sys import exit
  4. pygame.init()
  5. SCREEN_SIZE=(450,800)
  6. screen = pygame.display.set_mode(SCREEN_SIZE,0,32)
  7. pygame.display.set_caption("plane")
  8. background=pygame.image.load('back.jpg').convert()
  9. plane=pygame.image.load('plane.png').convert_alpha()
  10. bullet=pygame.image.load('bullet.png').convert_alpha()
  11. x=0
  12. y=0
  13. while True:
  14.     for event in pygame.event.get():
  15.         if event.type == pygame.QUIT:
  16.             pygame.quit()
  17.             exit()
  18.     x,y=pygame.mouse.get_pos()
  19.     bullet_x,bullet_y=pygame.mouse.get_pos()
  20.     x-=plane.get_width()/2
  21.     y-=plane.get_height()/2
  22.     screen.blit(background,(0,0))
  23.     screen.blit(plane,(x,y))
  24.     bullet_x-=bullet.get_width()/2;
  25.     bullet_y-=bullet.get_height()/2;
  26.     while bullet_y>=0:
  27.         screen.blit(bullet,(bullet_x,bullet_y))
  28.         bullet_y=bullet_y-100;
  29.         pygame.display.update()
复制代码
这样写可以吗?
回复

使用道具 举报

0

主题

0

好友

56

积分

注册会员

Rank: 2

8#
发表于 2013-8-28 14:30:36 |只看该作者
支持
回复

使用道具 举报

0

主题

0

好友

26

积分

新手上路

Rank: 1

7#
发表于 2013-8-28 10:05:02 |只看该作者
不错,希望尽快把打飞机教程写完!
回复

使用道具 举报

0

主题

0

好友

16

积分

新手上路

Rank: 1

6#
发表于 2013-8-28 09:43:16 |只看该作者
赞一个
回复

使用道具 举报

174

主题

45

好友

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

5#
发表于 2013-8-27 23:47:44 |只看该作者
Myk_cc 发表于 2013-8-27 22:34
在今天内容的基础上增加一行子弹。ps:两行子弹真霸气

#==== Crossin的编程教室 ====#
微信ID:crossincode
网站:http://crossincode.com
回复

使用道具 举报

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, 下载次数: 561)

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

回复

使用道具 举报

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

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

GMT+8, 2024-5-18 11:59 , Processed in 0.027898 second(s), 23 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部