1

チェーンのパーツを回転させる小さなゲームを作っています。私はpygameが初めてですが、ここから始めます。

#!/usr/bin/python
import pygame
def draw(square):
    (x,y) = square
    pygame.draw.rect(screen, black, (100+x*20,100+y*20,20,20), 1) 

def rotate(chain, index, direction):
    (pivotx, pivoty) = chain[index]
    if (direction == 1):
        newchain = chain[:index]+[(y-pivoty+pivotx, (x-pivotx)+pivoty) for (x,y) in chain[index:]]
    else:
        newchain = chain[:index]+[(y-pivoty+pivotx, -(x-pivotx)+pivoty) for (x,y) in chain[index:]]

    if (set(chain) & set(newchain[index+1:]) == set()):
        return newchain
    else:
        print "Collision!"
        return chain

pygame.init()

size = [600, 600]
screen = pygame.display.set_mode(size)
white = (255,255,255)
black = (0,0,0)

n = 20
chain = [(i,0) for i in xrange(n)]

screen.fill(white)
for square in chain:
    draw(square)

pygame.display.flip()
raw_input("Press Enter to continue...")
newchain = rotate(chain, 5, 1)
print chain
print newchain
screen.fill(white)
for square in newchain:
    draw(square)

pygame.display.flip()
raw_input("Press Enter to continue...")

pygame で適切な場所にジャンプするだけでなく、回転をアニメーションとしてスムーズに表示することは可能ですか?

4

1 に答える 1

1

状態を最終状態に変更しない関数を作成する必要がありますが、動きの一部を実行し、アニメーションが完了していない場合はタイムアウトでそれ自体を呼び出します。

たとえば(これは疑似パイゲームです)

f(object):
     object.position.x = 10

オブジェクトをスムーズにアニメーション化するわけではありませんが、

f(object):
     if object.position.x >= 10:
         return
     object.position.x += 1
     setTimer(10, f(object))

します。

于 2013-10-16T09:53:05.330 に答える