python 历遍子弹_Python游戏子弹移动

我看你船的旋转有问题。在

如果创建旋转的宇宙飞船display_s,那么得到的图像大小与space_ship大小不同,因此必须得到display_s矩形,并将宇宙飞船center指定给display_s中心。在display_s_rect = display_s.get_rect( center=spaceship_rect.center)

现在您必须使用display_s_rect来显示display_s

^{pr2}$

顺便说一句:

blit()期望在屏幕上放置blited图像左上角的位置。在

与screen.blit(display_s, (space_ship_rect.centerx, space_ship_rect.centery))

display_s的左上角将放在(space_ship_rect.centerx, space_ship_rect.centery)中,但我认为您应该将display_s放在(space_ship_rect.centerx, space_ship_rect.centery)的中间

将中心值(如前所述)分配给(space_ship_rect.centerx, space_ship_rect.centery),但在blit()中使用(space_ship_rect.x, space_ship_rect.y)。在

您可以使用space_ship_rect代替(space_ship_rect.x, space_ship_rect.y)中的blit(),得到相同的结果。在

我想你在blit()中的mousec位置也有同样的问题。在

获取mousec矩形,将鼠标位置指定给矩形中心,然后使用矩形x,y作为blit。在mousec_rect = mousec.get_rect( center = pygame.mouse.get_pos() )

screen.blit(mousec, mousec_rect)

编辑:

你的主循环后,我的修改-现在船是旋转,因为它应该display_s = space_ship # default value at start when ship wasn't rotate

while True:

clock.tick(60)

screen.blit(bk, (0, 0))

for event in pygame.event.get():

if event.type == QUIT:

pygame.quit()

sys.exit()

elif event.type == MOUSEBUTTONDOWN and event.button == 3:

pressed_down = 1

elif event.type == MOUSEBUTTONUP:

pressed_down = 0

if pressed_down == 1:

x, y = pygame.mouse.get_pos()

x1, y1 = x - space_ship_rect.x, y - space_ship_rect.y

angle = math.atan2(y1, x1)

dx = speed*math.cos(angle)

dy = speed*math.sin(angle)

movex = space_ship_rect.centerx = space_ship_rect.centerx + dx#ship x

movey = space_ship_rect.centery = space_ship_rect.centery + dy#ship y

if event.type == MOUSEMOTION:

x1, y1 = pygame.mouse.get_pos()

x2, y2 = space_ship_rect.centerx, space_ship_rect.centery

dx, dy = x2 - x1, y2 - y1

rads = math.atan2(dx, dy)

degs = math.degrees(rads)

display_s = pygame.transform.rotate(space_ship, (degs))#rotation of ship

display_s_rect = display_s.get_rect(center = space_ship_rect.center)

if event.type == MOUSEBUTTONDOWN and event.button == 1:

#Is it possible for me to get the degree rotation of the space_ship and apply it to here so the beam will travel in the direction it was shot in?

pass

screen.blit(display_s, display_s_rect)

#screen.blit(display_s, space_ship_rect)

pos = pygame.mouse.get_pos()

mousec_rect = mousec.get_rect(centerx=pos[0], centery=pos[1])

screen.blit(mousec, mousec_rect )

pygame.display.update()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值