0

我正在尝试在 pygame 中制作射击游戏。我可以让玩家四处移动,当按下空间时,子弹会回到它的位置。我想知道如何让它远离玩家,直到它碰到屏幕边缘。这是我到目前为止所拥有的:

if AMMO > 0:
    if event.type == pygame.KEYDOWN and Gun.image == NOGUN:
        if event.key == pygame.K_SPACE and Gun.image == NOGUN:
            Bullet.rect.center = Player.rect.center
            if Player.direction == 0:
                Bullet.direction = 0 #WHERE THE BULLET WILL MOVE

            shot.play()
            print "BANG"
            AMMO = AMMO - 1
            time.sleep(0.09)
4

3 回答 3

3

我们在这里需要更多代码。

在伪代码中:

def frameUpdate( timeBetweenFrame, bulletSpeed, playerDirectionVector ):
       bullet.position = bullet.position + playerDirectionVector.MultiplyByScalar(bulletSpeed * timeBetweenFrame);

其中 playerDirectionVector 是玩家面向的方向的归一化向量。

于 2013-06-24T19:48:02.533 回答
0

尝试这个

if AMMO > 0:
if event.type == pygame.KEYDOWN and Gun.image == NOGUN:
    if event.key == pygame.K_SPACE and Gun.image == NOGUN:
        #Initialize Bullet so it's not null and do the rest
        Bullet.rect.center = Player.rect.center
        if Player.direction == 0:
            Bullet.direction = 0

 if Bullet != null
    Bullet.X += 10 
    if Bullet.X > ScreenWidth()
        Bullet = null 
#These are all examples so you can understand the logic, I don't remember exactly how pygame works, but since you can move a character around you can find this :P

请记住,此代码只允许一个项目符号!

于 2013-11-29T08:03:55.060 回答
0

在 psudocode 中创建项目符号实例时使用的内容

#making your starting bullet cords
Bulletx = playerx
Bullety = playery
#this stores the angle the bullet was   shot from
Bulletangle = degreesplayerisrotated

这会将角度转换为弧度 Bulletangle = Bulletangle×pi/180

#this line updates the cords speed is a set value of how fast you want the bullet to move
Bulletx = bulletx-cos(bulletangle)×speed
Bullety = bullety-sin (bulletangle)×speed

Screen.blit (bullet, (bulletx, bullety))

或者用绳子画一个圆圈

如果你有问题一定要问希望这能解决问题

于 2014-11-20T19:51:47.060 回答