파이게임 충돌 후 없어지게 하는방법 아시는분 계실까요?
조회수 1225회
일단 혹시 몰라 코드는 전부 올려둘게요ㅎㅎ
만드는 것은 오락실게임 텐가이 비슷하게 만들려고 하는데 막혔어요.
bullet이 bossman과 충돌했을때 bossman이 사라지는(죽는?)것을 하고싶은데
무적이된것마냥 안죽네요ㅜㅜ 인터넷도 뒤져보고 똑같이 한건데도 방법을 모르겠네요
맞췄을때 에서 뭔가를 틀린거겠죠?
import pygame
from time import sleep
WHITE = (255,255,255) #색 비율
pad_width = 1024 #화면 폭
pad_height = 512 #화면 높이
background_width = 1024
aircraft_width = 90
aircraft_height = 55
boss_width = 200
boss_height = 200
def drawObject(obj,x,y): #객체
global gamepad
gamepad.blit(obj,(x,y))
def back(background,x,y): #배경
global gamepad
gamepad.blit(background,(x,y))
def airplane(x,y): #유저
global gamepad, aircraft
gamepad.blit(aircraft,(x,y))
def rungame():
global gamepad, clock, aircraft, bossman , background1, background2, bullet
global boom
#무기에 맞았을때
isShotBoss = False
boom_count = 0
bullet_xy = []
#유저 위치
aircraft_x = pad_width * 0.05
aircraft_y = pad_height * 0.8
aircraft_y_change = 0
aircraft_x_change = 0
#보스 위치
bossman_x = pad_width * 0.8
bossman_y = pad_height * 0.4
background1_x = 0
background2_x = background_width
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:
aircraft_y_change = -5
elif event.key == pygame.K_DOWN:
aircraft_y_change = 5
elif event.key == pygame.K_LEFT:
aircraft_x_change -= 5
elif event.key == pygame.K_RIGHT:
aircraft_x_change = 5
elif event.key == pygame.K_LCTRL:
bullet_x = aircraft_x + aircraft_width
bullet_y = aircraft_y + aircraft_height/2
bullet_xy.append([bullet_x,bullet_y])
elif event.key == pygame.K_SPACE:
sleep(5)
if event.type == pygame.KEYUP:
if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
aircraft_y_change = 0
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
aircraft_x_change = 0
gamepad.fill(WHITE)
#위치조정
aircraft_y += aircraft_y_change
if aircraft_y< 0:
aircraft_y = 0
elif aircraft_y > pad_height - aircraft_height:
aircraft_y = pad_height - aircraft_height
aircraft_x += aircraft_x_change
if aircraft_x < 0:
aircraft_x = 0
elif aircraft_x > pad_height - aircraft_height:
aircraft_x = pad_height - aircraft_height
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)
if len(bullet_xy) != 0: #총알
for i,bxy in enumerate(bullet_xy):
bxy[0] += 15
bullet_xy[i][1] = bxy[1]
if bxy[1] > bossman_x: #맞췄을떄
if bxy[0] > bossman_y and bxy[0] < bossman_y:
bullet_xy.remove(bxy)
isShotBoss = True
boom_count += 1
if bxy[1] <= 0:
try:
bullet_xy.remove(bxy)
except:
pass
if len(bullet_xy) != 0:
for bx,by in bullet_xy:
drawObject(bullet,bx,by)
drawObject(aircraft,aircraft_x,aircraft_y)
drawObject(bossman,bossman_x,bossman_y)
pygame.display.update()
clock.tick(60)
pygame.quit()
quit()
def initgame():
global gamepad, clock, aircraft, bossman, background1, background2, bullet
pygame.init()
gamepad = pygame.display.set_mode((pad_width, pad_height))
pygame.display.set_caption('PyFLYing')
aircraft = pygame.image.load('images/plane.png') #유저 이미지
background1 = pygame.image.load('images/background.png') #배경 이미지
background2 = background1.copy()
bossman = pygame.image.load('images/bat.png') #적 이미지
bullet = pygame.image.load('images/bullet.png') #총알 이미지
clock = pygame.time.Clock()
rungame()
initgame()
-
(•́ ✖ •̀)
알 수 없는 사용자 - 〉
댓글 입력