This is a function I made to draw pipes in an angry birds knockoff I made:
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.
My issue is that when I try to run my program I get an error saying
TypeError: argument 1 must be pygame.Surface, not tuple.
I have no idea what to do, sometimes I am able to run it and sometimes I am not. My surface is called screen and I have used the same syntax in multiple other programs where I have used pygame but I have never had this issue. If anybody can help me I would really appreciate it. If you need to see my entire program it is here:
"""-------------------------------------------------------------------------------
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)