2014-05-19 5 views
0

이 내가 화가 조류에 파이프를 그려 만든 함수가 내가 만든 가짜입니다 :파이 게임 튜플 표면 오류

def drawPipes(): 
#Pipes 1 
    if pipes1 == 1: 
     topPipe1Y =300 
     botPipe1Y =400 
     screen.blit(topL, (col1X, 0)) 
     screen.blit(botS, (col1X, 400)) <-----This part keeps getting the error. 

    elif pipes1 == 2: 
     topPipe1Y = 200 
     botPipe1Y = 300 
     screen.blit(topM, (col1X, 0)) 
     screen.blit(botM, (col1X, 300)) <-----This part keeps getting the error. 

    elif pipes1 == 3: 
     topPipe1Y = 100 
     botPipe1Y = 200 
     screen.blit(topS, (col1X, 0)) 
     screen.blit(botL, (col1X, 200)) <-----This part keeps getting the error. 

#Pipes 2 
    if pipes2 == 1: 
     topPipe2Y =300 
     botPipe2Y =400 
     screen.blit(topL, (col2X, 0)) 
     screen.blit(botS, (col2X, 400)) <-----This part keeps getting the error. 

    elif pipes2 == 2: 
     topPipe2Y =200 
     botPipe2Y =300 
     screen.blit(topM, (col2X, 0)) 
     screen.blit(botM, (col2X, 300)) <-----This part keeps getting the error. 

    elif pipes2 == 3: 
     topPipe2Y =100 
     botPipe2Y =200 
     screen.blit(topS, (col2X, 0)) 
     screen.blit(botL, (col2X, 200)) <-----This part keeps getting the error. 

#Pipes 3 
    if pipes3 == 1: 
     topPipe2Y =300 
     botPipe2Y =400 
     screen.blit(topL, (col3X, 0)) 
     screen.blit(botS, (col3X, 400)) <-----This part keeps getting the error. 

    elif pipes3 == 2: 
     topPipe2Y =200 
     botPipe2Y =300 
     screen.blit(topM, (col3X, 0)) 
     screen.blit(botM, (col3X, 300)) <-----This part keeps getting the error. 

    elif pipes3 == 3: 
     topPipe2Y =100 
     botPipe2Y =200 
     screen.blit(topS, (col3X, 0)) 
     screen.blit(botL, (col3X, 200)) <-----This part keeps getting the error. 

내 문제는 내가 내 프로그램을 실행하려고하면 내가

말하는 오류가 있다는 것입니다

TypeError: argument 1 must be pygame.Surface, not tuple.

나는 무엇을해야할지 모른다. 때때로 나는 그것을 달릴 수 있고 때때로 그렇지 않다. 내 표면을 screen이라고 부르며 나는 파이 게임을 사용한 다른 여러 프로그램에서 같은 문법을 사용했지만이 문제는 본 적이 없다. 아무도 나를 도울 수 있다면 정말 감사하겠습니다. 당신이 내 전체 프로그램을 참조해야하는 경우가 여기에 있습니다 :

"""------------------------------------------------------------------------------- 
Name:  module1 
Purpose: 

Author:  Nano 
Created:  18/05/2014 
Copyright: (c) Nano 2014 
Licence:  Open Source 
---------------------------------------------------------------------------------- 
Notes/ Checklist: 
    Turn off option to turn on and off printing. 
----------------------------------------------------------------------------------""" 
import pygame, sys, math, random, time, datetime 
from pygame.locals import * 
from datetime import timedelta 

pygame.init() 
fpsClock = pygame.time.Clock() 
fps = 60 
screenWid = 750 
screenLen = 500 
resolution = (screenWid, screenLen) 
pygame.display.set_caption('Flappy Bird') 
pygame.display.init() 
screen = pygame.display.set_mode((resolution)) 

printing = True 

black = (0,0,0) 
white = (255,255,255) 
red = (255,0,0) 
green = (0,255,0) 
blue = (0,0,255) 
yellow = (255,255,0) 
cyan = (0,255,255) 
purple = (255,0,255) 
lightTurquoise = (153,217,234) 
bgColor = (lightTurquoise) 

#--------------------------------------Pipes-------------------------------------- 
topL = pygame.image.load('TopPipe2.png') 
topM = pygame.image.load('TopPipe1.png') 
topS = pygame.image.load('TopPipe3.png') 
botL = pygame.image.load('BottomPipe2.png') 
botM = pygame.image.load('BottomPipe1.png') 
botS = pygame.image.load('BottomPipe3.png') 

sTopX = 100 
mTopX = 200 
lTopX = 300 

sBotX = screenLen-100 
mBotX = screenLen-200 
lBotX = screenLen-300 

col1Start = screenWid 
col2Start = col1Start+277 
col3Start = col2Start + 277 

col1X = col1Start 
col2X = col2Start 
col3X = col3Start 

pipes1=0 
pipes2=0 
pipes3=0 


pipes1 = random.randint(1,3) 
pipes2 = random.randint(1,3) 
pipes3 = random.randint(1,3) 

topPipe1Y = 0 
botPipe1Y = 0 

topPipe2Y = 0 
botPipe2Y = 0 

topPipe3Y = 0 
botPipe3Y = 0 


"""def drawPipes(): 
#Pipes 1 
    if pipes1 == 1: 
     topPipe1Y =300 
     botPipe1Y =400 
     screen.blit(topL, (col1X, 0)) 
     screen.blit(botS, (col1X, 400)) 

    elif pipes1 == 2: 
     topPipe1Y = 200 
     botPipe1Y = 300 
     screen.blit(topM, (col1X, 0)) 
     screen.blit(botM, (col1X, 300)) 

    elif pipes1 == 3: 
     topPipe1Y = 100 
     botPipe1Y = 200 
     screen.blit(topS, (col1X, 0)) 
     screen.blit(botL, (col1X, 200)) 

#Pipes 2 
    if pipes2 == 1: 
     topPipe2Y =300 
     botPipe2Y =400 
     screen.blit(topL, (col2X, 0)) 
     screen.blit(botS, (col2X, 400)) 

    elif pipes2 == 2: 
     topPipe2Y =200 
     botPipe2Y =300 
     screen.blit(topM, (col2X, 0)) 
     screen.blit(botM, (col2X, 300)) 

    elif pipes2 == 3: 
     topPipe2Y =100 
     botPipe2Y =200 
     screen.blit(topS, (col2X, 0)) 
     screen.blit(botL, (col2X, 200)) 

#Pipes 3 
    if pipes3 == 1: 
     topPipe2Y =300 
     botPipe2Y =400 
     screen.blit(topL, (col3X, 0)) 
     screen.blit(botS, (col3X, 400)) 

    elif pipes3 == 2: 
     topPipe2Y =200 
     botPipe2Y =300 
     screen.blit(topM, (col3X, 0)) 
     screen.blit(botM, (col3X, 300)) 

    elif pipes3 == 3: 
     topPipe2Y =100 
     botPipe2Y =200 
     screen.blit(topS, (col3X, 0)) 
     screen.blit(botL, (col3X, 200))""" 

def colisions(x,y,columnx,topPipeY,botPipeY): 
    if x>=columnx and x + 51 <= columnx: 
     if y >=topPipeY or y<= botPipeY: 
      print("top pipe 1") 
      movement = 'none' 
      birdy = int(screenLen/2) 
      if score > highScore: 
       highScore = score 
      score = 0 
      speed = 0 
      col1X = col1Start 
      col2X = col2Start 
      col3X = col3Start 
      print("Oops") 

score = 0 
bird = pygame.image.load('FlappyBird.png') 
bgImage = pygame.image.load('BackDrop.png') 
birdx = 250 
birdy = screenLen/2 
birdWid = 51 
birdLen = 36 
font = pygame.font.SysFont("Times New Roman, Arial", 20) 
scoreBoard = font.render("Score:", True, black) 
scoreBoardPos = (5,5) 
highScoreText = font.render("High Score:", True, black) 
scorePos = (65,5) 
movement = 'none' 
goingUp = 0 
highScore = 0 
orgSpeed = 2 
speed = 0 
two = 200 
three = 300 
four = 400 


"""================================Main Game Loop=================================""" 
while True: 
    topR = birdx+birdWid,birdy 
    botL = birdx, birdy+birdLen 
    botR = birdx+birdWid ,birdy+birdLen 
    if col1X <= -82: 
     col1X = screenWid 
     pipes1 = random.randint(1,3) 
    if col2X <= -82: 
     col2X = screenWid 
     pipes2 = random.randint(1,3) 
    if col3X <= -82: 
     col3X = screenWid 
     pipes3 = random.randint(1,3) 
    col1X-=speed 
    col2X-=speed 
    col3X-=speed 
    scoreAmount = font.render(str(score),True, black) 
    highScoreNum = font.render(str(highScore),True, black) 
    screen.fill(bgColor) 
    screen.blit(bgImage,(0,0)) 
#-----------------------------------Draws Pipes------------------------------------ 
##Pipes 1 
    if pipes1 == 1: 
     topPipe1Y =300 
     botPipe1Y =400 
     screen.blit(topL, (col1X, 0)) 
     screen.blit(botS, (col1X, four)) 

    elif pipes1 == 2: 
     topPipe1Y = 200 
     botPipe1Y = 300 
     screen.blit(topM, (col1X, 0)) 
     screen.blit(botM, (col1X, three)) 

    elif pipes1 == 3: 
     topPipe1Y = 100 
     botPipe1Y = 200 
     screen.blit(topS, (col1X, 0)) 
     screen.blit(botL, (col1X, two)) 

##Pipes 2 
    if pipes2 == 1: 
     topPipe2Y =300 
     botPipe2Y =400 
     screen.blit(topL, (col2X, 0)) 
     screen.blit(botS, (col2X, four)) 

    elif pipes2 == 2: 
     topPipe2Y =200 
     botPipe2Y =300 
     screen.blit(topM, (col2X, 0)) 
     screen.blit(botM, (col2X, three)) 

    elif pipes2 == 3: 
     topPipe2Y =100 
     botPipe2Y =200 
     screen.blit(topS, (col2X, 0)) 
     screen.blit(botL, (col2X, three)) 

##Pipes 3 
    if pipes3 == 1: 
     topPipe2Y =300 
     botPipe2Y =400 
     screen.blit(topL, (col3X, 0)) 
     screen.blit(botS, (col3X, four)) 

    elif pipes3 == 2: 
     topPipe2Y =200 
     botPipe2Y =300 
     screen.blit(topM, (col3X, 0)) 
     screen.blit(botM, (col3X, three)) 

    elif pipes3 == 3: 
     topPipe2Y =100 
     botPipe2Y =200 
     screen.blit(topS, (col3X, 0)) 
     screen.blit(botL, (col3X, two)) 

    screen.blit(bird, (birdx,birdy)) 
    screen.blit(scoreBoard, scoreBoardPos) 
    screen.blit(scoreAmount, scorePos) 
    screen.blit(highScoreText,(5,45)) 
    screen.blit(highScoreNum, (105,45)) 
    if birdx == col1X: 
     score +=1 
    if birdx == col2X: 
     score +=1 
    if birdx == col3X: 
     score +=1 
    for event in pygame.event.get(): 

     if event.type == MOUSEBUTTONDOWN: 
      speed = orgSpeed 
      goingUp+=10 
      if goingUp > 30: 
       goingUp = 30 
      movement = 'up' 

##Required for closing game 
     if event.type == QUIT: 
      pygame.quit() 
      sys.exit() 

    if movement == 'up': 
     if birdy <= 0: 
      birdy = 2 
      goingUp = 0 
      movement = 'down' 
     birdy-=4 
     goingUp-=1 
     if goingUp == 0: 
      movement = 'down' 
      goingUp = 0 
    if movement == 'down': 
     birdy+=4 
     if birdy >= screenLen or birdy+36 >= screenLen: 
      movement = 'none' 
      birdy = int(screenLen/2) 
      if score > highScore: 
       highScore = score 
      score = 0 
      speed = 0 
      col1X = col1Start 
      col2X = col2Start 
      col3X = col3Start 

#------------------------------Colission Conditions------------------------------- 
    colisions(birdx,birdy,col1X,topPipe1Y,botPipe1Y) 
    colisions(birdx,birdy,col2X,topPipe2Y,botPipe2Y) 
    colisions(birdx,birdy,col3X,topPipe3Y,botPipe3Y) 

    if birdx>=col1X and birdx + 51 <= col1X: 
     if birdy >=topPipe1Y or birdy<= botPipe1Y: 
      print("top pipe 1") 
      movement = 'none' 
      birdy = int(screenLen/2) 
      if score > highScore: 
       highScore = score 
      score = 0 
      speed = 0 
      col1X = col1Start 
      col2X = col2Start 
      col3X = col3Start 
      print("Oops") 

    pygame.display.update() 
    fpsClock.tick(fps) 

답변

0

나는 많은 코드에서이 라인 (여전히 botM에 정확히 무엇이 잘못 알고 있지만 당신이 어디에 있는지에 대해 생각하지 않는다 함께 할 수있다 생각)를 재 할당 : 당신은 튜플로 변화 but some global variables can be written without the global keyword.

topR = birdx+birdWid,birdy # note these now become tuples with two integers 
botL = birdx, birdy+birdLen 
botR = birdx+birdWid ,birdy+birdLen 

내가 파이 게임 객체가 얼마나 가변 모른다.

+0

나는 바보처럼 느껴진다. 튜플이 아닌 변수를 변경하는 것을 완전히 잊었다. 감사. – Nano