파이썬 뉴비 입니다

파이썬 뉴비 입니다

QA

파이썬 뉴비 입니다

본문

 

code

import pygame

import random

 

WHITE=(225,225,225)

RED=(255,0,0)

pad_width=1024

pad_height=55

background_width=1024

dorn_width=90

dorn_hieght=55

trash_width=110

trash_height=67


 

def drawObject(obj,x,y):

global gamepad

gamepad.blit(obj(x,y))


 

def runGame():

global gamepad,dorn,clock,background1,background2

global trash,fires,bullet,boom


 

isShottrash=False

boom_count=0

bullet_xy=[]

x=pad_width*0.05

y=pad_height*0.8

y_change=0

background1_x=0

background2_x=background_width

trash_x=pad_width

trash_y=random.randarange(0,pad_height)

fire_x=pad_width

fire_y=random.randarange(0,pad_height)

random.shuffle(fires)

fire=fires[0]

crashed=False

while not crashed:

for event in pygame.event.get():

if event.type==pygame.QUIT:

crashed=True

if event.type==pygame.KEYDOWN:

if event.key==pygame.K_UP:

y_change=-5

elif event.key==pygame.K_DOWN:

y_change=5

elif event.key==pygame.K_LCTRL:

bullet_x=x+dorn_width

bullet_y=y+dorn_hieght/2

bullet_xy.append([bullet_x,bullet_y])

if event.type==pygame.KEYUP:

if event.key==pygame.K_UP or event.key==pygame.K_DOWN:

y_change=0

gamepad.fll(WHITE)

background1_x-=2

background2_x-=2

if background1_x==-background_width:

background1_x=background_width

if background2_x==-background_width:

background2_x=background_width

drawObject(background1,background1_x,0)

drawObject(background2,background2_x,0)

y+=y_change

if y<0:

y=0

elif y>pad_height-dorn_hieght:

y=pad_height-dorn_hieght

trash_x=7

if trash_x <=0:

trash_x=pad_width

trash_y=random.randarange(0,pad_height)

if leaves==None:

leaves_x-=30

else:

fire_x-=15

if leaves_x<=0:

leaves_x=pad_width

leaves_y=random.randarange(0,pad_width)

random.shuffle(leaves)

leaves=leaves[0]

if len(bullet_xy)!=0:

for i, bxy in enumerate(bullet_xy):

bxy[0]+=15

bullet_xy[i][0]=bxy[0]

if bxy[0]>trash_x:

if bxy[1]>trash_y and bxy[1]< trash_y+trash_height:

isShottrash=Ture

if bxy[0]>=pad_width:

try:

bullet_xy.remove(bxy)

except:

pass

drawObject(dron,x,y)

if len(bullet_xy)!=0:

for bullet_x,by in bullet_xy:

drawObject(bullet,x,y)

if not isShottrash:

drawObject(trash,trash_x,trash_y)

else:

drawObject(boom,trash_x,trash_y)

boom_count+=1

if boom_count>5:

boom_count=0

trash_x=pad_width

trash_y=random.randarange(0,pad_height-trash_height)

isShottrash=False

if leaves!=None:

drawObject(leaves,leaves_x,leaves_y)

pygame.display.update()

clock.tick(60)

pygame.quit()

quit()


 

def initGame():

global gamepad,dorn,clock,background1,background2

global trash,leaves,bullet,boom

 

fires=[]

 

pygame.init()

gamepad=pygame.display.set_mode((pad_width,pad_height))

pygame.display.set_caption('dron flying')

dorn=pygame.image.load('images/dron.png')

background1=pygame.image.load('images/background')

background2=background1.copy()

trash=pygame.image.load('images/leaves.png')

leaves.append(pygame.image.load('images/leaves.png'))

leaves.append(pygame.image.load('images/leaves2.png'))

 

boom=pygame.image.load('images/boom.png')

 

for i in range(3):

fires.append(None)

bullet=pygame.image.load('images/bullet.png')

clock=pygame.time.Clock()

runGame()

initGame()

/code

 

이런식으로 구성했는데 오류가 계속 발생합니다 뭐가 문제일까요 ㅠㅠ

 

이 질문에 댓글 쓰기 :

답변 1

답변을 작성하시기 전에 로그인 해주세요.
전체 123,531 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT