파이게임 깔고 붙여넣어서 실행하셈
같은폴더에 newhit란 이름의 wav 파일 하나 너노셈 타격음임
꿀잼임 내가만들고 내가 존나함
import pygame, random, time
pygame.mixer.init()
pygame.init()
pygame.mixer.music.load('newhit.wav')
screenx = 1000
screeny = 800
screen = pygame.display.set_mode((screenx,screeny))
px = 20
py = 20
k = 0
fpsClock = pygame.time.Clock()
count =0
pBullets = []
shoot_count = 1
hit_count = 0
font = pygame.font.SysFont("Comic Sans MS", 30)
class state:
def __init__(self):
self.x = 0
self.y = 0
self.right = 0
self.left = 0
self.up = 0
self.down = 0
self.shoot = 0
self.hp = 500
def cheat():
global shoot_count
r = abs(eState.y-pState.y)
l = eState.x-pState.x
if l>r*5:
pBullets.append([pState.x+25,pState.y])
shoot_count+=1
def do(player):
speed = 5
if player.right == 1:
player.x += speed
elif player.left == 1:
player.x -= speed
elif player.up == 1:
player.y -= speed
elif player.down == 1:
player.y += speed
if player.x > (screenx/3)-20:
player.x = (screenx/3)-20
if player.y<0:
player.y = 0
if player.y>screeny-50:
player.y = screeny-50
if player.x <0:
player.x = 0
def enemy_do(enemy):
speed = 5
if enemy.right == 1:
enemy.x += speed
elif enemy.left == 1:
enemy.x -= speed
elif enemy.up == 1:
enemy.y -= speed
elif enemy.down == 1:
enemy.y += speed
if enemy.x > screenx-20:
enemy.x = screenx-20
if enemy.y<0:
enemy.y = 0
if enemy.y>screeny-50:
enemy.y = screeny-50
if enemy.x <0:
enemy.x = 0
def distance(ax,ay,bx,by):
return ((bx-ax)**2+(by-ay)**2)**0.5
pState = state()
eState = state()
eState.x = screenx*2/3
eState.y = 300
while 1:
for i in pygame.event.get():
if i.type == pygame.QUIT:
pygame.quit()
exit
if i.type == pygame.KEYDOWN:
if i.key == pygame.K_UP:
pState.up = 1
if i.key == pygame.K_DOWN:
pState.down = 1
if i.key == pygame.K_LEFT:
pState.left = 1
if i.key == pygame.K_RIGHT:
pState.right = 1
if i.key == pygame.K_c:
pBullets.append([pState.x+25,pState.y])
shoot_count+=1
if i.type == pygame.KEYUP:
if i.key == pygame.K_UP:
pState.up = 0
if i.key == pygame.K_DOWN:
pState.down = 0
if i.key == pygame.K_LEFT:
pState.left = 0
if i.key == pygame.K_RIGHT:
pState.right = 0
if random.randrange(2)==0:#Enemy moving
if count==0:
eState.up = 1
eState.down = 0
else:
if count ==0:
eState.up = 0
eState.down = 1
do(pState)
enemy_do(eState)
screen.fill([255,255,255])
pygame.draw.circle(screen,[0,0,0],[pState.x,pState.y],25,0)
pygame.draw.circle(screen,[250,0,0],[eState.x,eState.y],25,0)
pygame.draw.rect(screen,[0,0,0],[0,0,screenx/3,screeny],1)
k = 0
if i!=[]:
for i in pBullets:
if distance(i[0],i[1],eState.x,eState.y)<=28:
eState.hp -= 1
pygame.mixer.music.play()
del pBullets[k]
hit_count+=1
pygame.draw.circle(screen,[0,0,0],[i[0],i[1]],3,0)
i[0]+=25
if i[0]>screenx:
del pBullets[k]
k+=1
eHP = font.render("%d"%eState.hp,1,[0,0,0])
screen.blit(eHP,[eState.x,eState.y])
accurate = font.render(str(100*hit_count/float(shoot_count))+'%',1,[0,0,0])
screen.blit(accurate,[screenx-100,300])
pygame.display.update()
count +=1
if count>10:
count = 0
fpsClock.tick(60)
응 안해