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

このコードでは、箇条書きが 1 つしか許可されないことに注意してください。

于 2013-11-29T08:03:55.060 に答える