Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- class Sprite:
- def __init__(self,x,y,filename):
- self.x=x
- self.y=y
- self.bitmap=pygame.image.load(filename)
- self.bitmap.set_colorkey((0,0,0))
- def picture(self,screen):
- screen.blit(self.bitmap,(self.x,self.y))
- def move_zet(zet):
- if zet.right==True:
- zet.x+=zet.step
- if zet.x>460:
- zet.right=False
- else:
- zet.x-=zet.step
- if zet.x<0:
- zet.right=True
- def move_gun_arrow(gun,arrow,event):
- if event.type==pygame.KEYDOWN:
- if event.key==pygame.K_LEFT:
- if gun.x>0:
- gun.x-=1
- if event.key==pygame.K_RIGHT:
- if gun.x<460:
- gun.x+=1
- if event.key==pygame.K_DOWN:
- if gun.y<410:
- gun.y+=1
- if event.key==pygame.K_UP:
- if gun.y>70:
- gun.y-=1
- if event.key==pygame.K_SPACE:
- if arrow.push == False:
- arrow.x=gun.x + 10
- arrow.y=gun.y - 5
- arrow.push = True
- if event.type==pygame.MOUSEMOTION:
- m=pygame.mouse.get_pos()
- pygame.mouse.set_visible(False)
- if 0<m[0]<460:
- gun.x=m[0]
- if 70<m[1]<400:
- gun.y=m[1]
- if event.type==pygame.MOUSEBUTTONDOWN:
- if event.button == 1:
- if arrow.push == False:
- arrow.x=gun.x + 10
- arrow.y=gun.y - 5
- arrow.push = True
- def fly(arrow):
- if arrow.y < 0:
- arrow.push = False
- arrow.x = -40
- arrow.y = 350
- elif arrow.push == False:
- arrow.x= -40
- arrow.y= 350
- else:
- arrow.y -= 3
- def log(arrow, zet):
- if abs(arrow.x - zet.x) <= 20 and abs(arrow.y - zet.y )<= 20:
- print(zet.po)
- arrow.push = False
- zet.po += 10
- zet.step *= 1.05
- elif arrow.y < 0:
- zet.po -= 1
- def main():
- pygame.init()
- window=pygame.display.set_mode(( 500, 500)) # окно
- pygame.display.set_caption('Пушка')
- screen=pygame.Surface((500,450))# игровой экран
- status_bar=pygame.Surface((500,50))
- #==== создание шрифтов
- pygame.font.init()
- bar_font=pygame.font.SysFont('Arial',24,True,False)
- zet=Sprite(250,20,'hero_2.png')
- zet.right=True
- zet.po = 0
- zet.step = 1
- gun=Sprite(250,190,'hero.png')
- arrow=Sprite(-40,350,'hero_3.png')
- arrow.push = False
- pygame.key.set_repeat(1,1)
- done=True
- while done:
- for event in pygame.event.get():
- if (event.type==pygame.QUIT):
- done = False
- move_gun_arrow(gun,arrow,event)
- screen.fill((73,101,78))
- status_bar.fill((192,207,178))
- fly(arrow)
- move_zet(zet)
- zet.picture(screen)
- arrow.picture(screen)
- gun.picture(screen)
- log(arrow,zet)
- status_bar.blit(bar_font.render('СЧЕТ: '+str(zet.po),1,(37,53,40)),(20,10))
- status_bar.blit(bar_font.render('СКОРОСТЬ: '+str(zet.step),1,(37,53,40)),(320,10))
- window.blit(screen,(0,50))
- window.blit(status_bar,(0,0))
- pygame.display.flip()
- pygame.time.delay(5)
- if __name__=='__main__':
- main()
- pygame.font.quit()
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement