2016-05-22 15 views
0

私はパイゲームでゲームを作ろうとしていますが、2つのバグがあります。パイゲームでスコアが急上昇するのはなぜですか?

バグ1つの

私のスコアは私の条件は、一度に1ポイントを増やすことであるゲームで急激に増加します。 スコアを高めるために私のコードは次のとおりです。ここで

if thing_starty >display_height: 
      thing_stary = 0-thing_height 
      thing_startx= random.randrange(0,display_width) 
      dodged += 1 
      thing_speed += 1 
      thing_width += (dodged * 1.2) 

は避け私のスコアで、それは1によってブロックが画面の外に行くたびに増やす必要があります。 、ブロックが画面の外に通過した後、それはback.Alsoを付属していませんが、ゲーム

バグ私のゲームでは2

がトップから、次の黒い四角形があり、それは、画面消灯後の事はあります衝突がなくても終了する。
ブロックである戻ってくるためのコード:

if thing_starty >display_height: #Check if block is there in the screen or not 
      thing_stary = 0 - thing_height 
      thing_startx= random.randrange(0,display_width) 
      dodged += 1 
      thing_speed += 1 
      thing_width += (dodged * 1.2) 

フルコード:

import pygame 
import time 
import random 

pygame.init() 

#Colours 
white = (255,255,255) 
black = (0,0,0) 
red = (255,0,0) 

#Game Display 
display_width = 1080 
display_height = 720 
gameDisplay = pygame.display.set_mode((display_width,display_height)) 
pygame.display.set_caption('Eat It! ~ Snapnel Productions') 

#Clock 
clock = pygame.time.Clock() 
FPS = 60 

#Font Size 
exsmallfont = pygame.font.SysFont("comicsansms", 17) 
smallfont = pygame.font.SysFont("comicsansms", 25) 
medfont = pygame.font.SysFont("comicsansms", 50) 
largefont = pygame.font.SysFont("comicsansms", 80) 

#Car 
def car(x,y): 
    gameDisplay.blit(carimg,(x,y)) 
global x, y, x_change 
carimg=pygame.image.load('food.png') 
#With of the car(i.e food image) 
car_width=10 

#Things 
def things(thingx,thingy,thingw,thingh,color): 
    pygame.draw.rect(gameDisplay,color,[thingx,thingy,thingw,thingh]) 

#Things doged 
def things_dodged(count): 
    font = pygame.font.SysFont(None, 25) 
    text = font.render("Dodged: "+str(count), True, red) 
    gameDisplay.blit(text,(0,0)) 
#Starting Of the game 
def game_intro(): 
    intro = True 
    while intro:  
     for event in pygame.event.get(): 

     if event.type == pygame.QUIT: 
      pygame.quit() 
      quit() 
     if event.type == pygame.KEYDOWN: 
      if event.key ==pygame.K_c: 
       intro = False 
      if event.key ==pygame.K_q: 
       pygame.quit() 
       quit() 
     gameDisplay.fill(black) 
     #Game Initial display message 
     message_to_screen("Dodge It!", 
          red, 
          -200, 
          size="large") 

     message_to_screen("Press 'C' to play the game or 'Q' to quit.", 
          white, 
          150, 
          size="small") 
     pygame.display.update() 
     clock.tick(15) 

#Text Size 
def text_objects(text,color, size): 
    if size=="small": 
     textSurface=smallfont.render(text, True ,color) 
    elif size=="medium": 
     textSurface=medfont.render(text, True ,color) 
    elif size=="large": 
     textSurface=largefont.render(text, True ,color) 


    return textSurface,textSurface.get_rect() 

#Message to screen 
def message_to_screen(msg,color,y_displace=0,size="small"): 
    textSurf,textRect=text_objects(msg,color,size) 
    textRect.center = (display_width/2),(display_height/2)+y_displace 
    gameDisplay.blit(textSurf,textRect) 

#The Game run up 
def runGame(): 
    #global x,y, x_change 
    gameExit = False 
    gameOver = False 

    x=(display_width*0.45)  
    y=(display_height*0.48) 
    x_change =0 

    #To count score 
    thingCount=1 
    dodged=0 

    #Block Initial Size 
    thing_startx = random.randrange(0,display_width) 
    thing_starty = -600 
    thing_speed = 7 
    thing_width = 100 
    thing_height = 100 
    while not gameExit: 

     while gameOver == True: 
      #Game Over message 

      gameDisplay.fill(white) 
      message_to_screen("Game over", 
           red, 
           y_displace=-50, 
           size="large") 
      message_to_screen("Press C to play again or Q to quit.", 
           red, 
           y_displace=50, 
           size="medium") 
      pygame.display.update() 

      for event in pygame.event.get(): 
       if event.type == pygame.KEYDOWN: 
        if event.key == pygame.K_q: 
         gameExit = True 
         gameOver = False 
        if event.key == pygame.K_c: 
         gameLoop() 

     #Game Controls 
     for event in pygame.event.get(): 
      if event.type == pygame.QUIT: 
       gameExit = True 
      if event.type == pygame.KEYDOWN: 
       if event.key == pygame.K_LEFT: 
        x_change = -5 
       elif event.key == pygame.K_RIGHT: 
        x_change = 5 

      if event.type == pygame.KEYUP: 
       if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: 
        x_change=0 

     x += x_change 
     gameDisplay.fill(white) 

     things(thing_startx,thing_starty,thing_width,thing_height,black) 
     thing_starty+=thing_speed 
     car(x,y) 
     things_dodged(dodged) 

     if x>display_width-car_width or x<0: 
      gameOver = True 

     #Check if block is in the screen 
     if thing_starty >display_height: 
      thing_stary = 0 - thing_height 
      thing_startx= random.randrange(0,display_width) 
      dodged += 1 
      thing_speed += 1 
      thing_width += (dodged * 1.2) 

     #Check Collision with block 
     if y < thing_starty+thing_height: 
      print('y crossover') 

      if x > thing_startx and x < thing_startx + thing_width or x+car_width > thing_startx and x + car_width < thing_startx+thing_width: 
       print('x crossover') 
       gameOver = True 

     pygame.display.update() 

#The game run up 
def gameLoop(): 
    clock.tick(FPS) 
    runGame() 
    pygame.quit() 
    quit() 

game_intro() 
gameLoop() 

Here食品画像です。
あらかじめ仲間たちに感謝します。本当にこのバグに注意してください。

答えて

1

あなたの変数名のタイプミスを持って、それはおそらく次のようになります。

thing_starty 

の代わり:

thing_stary 
+0

あなたがイメージをダウン得るために、私の方法を教えてください。それは私の画面の一番下にあります。 –

+0

あなたのバグ2のコードはバグ1と同じですが、それが間違っている部分を表すようにアップデートできますか? –

+0

私の両方のバグはうまく解決されましたが、今はその食べ物のイメージが画面の下にあることが必要です。それは底にあります。どうすればいいですか? –

関連する問題