2017-05-10 5 views
1

最近私はパイガームを持っていて、特定の矩形をブリッティングすることに問題がある。 プログラムそのものは、(完了していない)不足分の戦いです。プログラムを実行してFIGHT(FIGHTモードに入る)を押すと、その上のattackLineRectを左に動かしてattackBarRectを取得する必要がありますが、表示されません。しかし、ある時間後にFIGHTモードが終了するので、rectはそこにありますが、表示されません。私は問題を整理しましたが、エラーメッセージが表示されていました(私には何もありません)と、バックラウンドが項目上でブリットされている(テストされたものは動作しませんでした)。私を助けてください。 全コード:パイガムの矩形はそこにあるがブリットしていないように見える

import sys, pygame, time, os 
pygame.init() 
size = width, height = 600,448 
menu1=[0,1,0,0] 
enemyHealth=3000 
attackNumber=0 
attackPowerSelf=0 
attackPower=1 
attackLineX=546 
attackLineY=246 
def pingdef(): 
    pass 
def menuSelect(): 
    was=1 
    rerun=False 
    pressed = pygame.key.get_pressed() 
    x=menu1.index(1) 
    if pressed[pygame.K_RIGHT]!=0: 
     time.sleep(0.2) 
     if x==3: 
      menu1[x]=0 
      menu1[0]=1 
     else: 
      menu1[x]=0 
      menu1[x+1]=1 
    elif pressed[pygame.K_LEFT]!=0: 
     time.sleep(0.2) 
     if x==0: 
      menu1[x]=0 
      menu1[3]=1 
     else: 
      menu1[x]=0 
      menu1[x-1]=1 
    elif pressed[pygame.K_z]!=0: 
     return x 
    else: 
     rerun=True 
    x=menu1.index(1) 
    if x==0: 
     screen.blit(backround, backroundRect) 
     if x!=was: 
      pingdef() 
     screen.blit(fight,fightRect) 
     was=x 
    if x==1: 
     screen.blit(backround, backroundRect) 
     if x!=was: 
      pingdef() 
     screen.blit(act,actRect) 
     was=x 
    if x==2: 
     screen.blit(backround, backroundRect) 
     if x!=was: 
      pingdef() 
     screen.blit(item,itemRect) 
     was=x 
    if x==3: 
     screen.blit(backround, backroundRect) 
     if x!=was: 
      pingdef() 
     screen.blit(mercy,mercyRect) 
     was=x 
    pygame.event.pump() 
    pygame.display.flip() 
    if rerun==True: 
     return None 
screen = pygame.display.set_mode(size) 

backround = pygame.image.load("images\\backround.png") 
backroundRect = backround.get_rect() 
fight=pygame.image.load("images\\fightSelected.png") 
fightRect = fight.get_rect() 
act=pygame.image.load("images\\act.png") 
actRect = act.get_rect() 
item=pygame.image.load("images\\item.png") 
itemRect = item.get_rect() 
mercy=pygame.image.load("images\\mercy.png") 
mercyRect = mercy.get_rect() 
attackBar=pygame.image.load("images\\attackBar.png") 
attackBarRect = attackBar.get_rect() 
attackLine=pygame.image.load("images\\attackLine.png") 
attackLineRect = attackLine.get_rect() 
pygame.mixer.music.load("sounds\\Megalovenia.ogg") 
pygame.mixer.music.play(loops=-1, start=0.0) 
screen.blit(fight,fightRect) 
screen.blit(backround, backroundRect) 
pygame.display.flip() 
fightRect=fightRect.move(42,403) 
actRect=actRect.move(179,403) 
itemRect=itemRect.move(324,403) 
mercyRect=mercyRect.move(463,403) 
attackBarRect=attackBarRect.move(47,246) 
attackLineRect=attackLineRect.move(attackLineX,attackLineY) 
while True: 
    for event in pygame.event.get(): 
     if event.type == pygame.QUIT: sys.exit() 
    screen.blit(backround, backroundRect) 
    while True: 
     selected=menuSelect() 
     if selected!=None: 
      break 
    time.sleep(0.2) 
    if selected==0: 
     screen.blit(backround, backroundRect) 
     screen.blit(attackBar,attackBarRect) 
     time.sleep(0.2) 
     while True: 
      pressed = pygame.key.get_pressed() 
      if pressed[pygame.K_RETURN]==1 or attackLineRect.left<47: 
       attackLineRect=attackLineRect.move(546,246) 
       break 
      if attackLineRect.right<304: 
       attackPowerSelf+=attackPower 
      else: 
       attackPowerSelf-=attackPower 
      attackLineX-=1 
      attackLineRect=attackLineRect.move(attackLineX,attackLineY) 
      screen.blit(attackBar,attackBarRect) 
      screen.blit(attackLine,attackLineRect) 
      pygame.event.pump() 
      pygame.display.flip() 
    if selected==1: 
     print("ACT") 
    if selected==2: 
     print("ITEM") 
    if selected==3: 
     print("MERCY") 
    pygame.display.flip() 


wait=input("") 

ない作業部:

if selected==0: 
     screen.blit(backround, backroundRect) 
     screen.blit(attackBar,attackBarRect) 
     time.sleep(0.2) 
     while True: 
      pressed = pygame.key.get_pressed() 
      if pressed[pygame.K_RETURN]==1 or attackLineRect.left<47: 
       attackLineRect=attackLineRect.move(546,246) 
       break 
      if attackLineRect.right<304: 
       attackPowerSelf+=attackPower 
      else: 
       attackPowerSelf-=attackPower 
      attackLineX-=1 
      attackLineRect=attackLineRect.move(attackLineX,attackLineY) 
      screen.blit(attackBar,attackBarRect) 
      screen.blit(attackLine,attackLineRect) 
      pygame.event.pump() 
      pygame.display.flip() 

答えて

0

あなたはattackLineRect下方に移動すると大きなステップで右にしています。

attackLineX = 546 
attackLineY = 246 

# This moves the rect to the right by 546 pixels and down by 246 px. 
attackLineRect = attackLineRect.move(attackLineX, attackLineY) 

attackLineRectを印刷してみると、画面がすぐに消えてしまいます。

たとえば、move(-1, 0)に変更してゆっくりと左に移動します。

attackLineRect = attackLineRect.move(-1, 0) 

また、あなたのプログラムは奇妙な方法で構成されており、私はいくつかのヒントを得るためにCode ReviewまたはRedditに投稿することをお勧めしたいです。しかし、コードは正しく動作するはずですから、問題を最初に修正し、画像と共に完全なコードを投稿してください。すでに使用すべき

ことの一つは、例えば、フレームレートを制限するpygame.time.Clockです:

clock = pygame.time.Clock() 

while True: 
    # In each while loop call `clock.tick(30)` to limit the frame rate to 30 fps. 
    clock.tick(30) 
+0

は答えてくれてありがとう!本当に助けになった。写真については、私がここに置くと著作権侵害の可能性があります(元のものとほぼ同じです)。ここに私の作業コードがあります: https://www.dropbox.com/s/ju9mwgz9t7wii5u/underthetale.py?dl=0 – Evgeny

+0

次に、画像を「pygame.Surface」で置き換えてカラー(コードレビューのためだけ)。代わりに、http://opengameart.org/から無料のオープンソースのグラフィックスを選ぶこともできます。 – skrx

+0

非常に素早く修正できるものがあります:イメージは通常、ロードされた後に変換されるべきです。例えば、 'act = pygame.image.load "images \\ act.png").convert_alpha() '.convert()'またはそれが透明である場合 'act = pygame.image.load("画像\\ act.png ")です。これはパフォーマンスを向上させるのに役立ちます。 – skrx

関連する問題