0
0 Комментариев
import pygame
 pygame.init()
 win=pygame.display.set_mode((1500,900))
 pygame.display.set_caption("trapp")
 walkRight=[pygame.image.load('ftr1_rt1.gif'),
pygame.image.load('ftr1_rt2.gif')]
 walkLeft=[pygame.image.load('ftr1_lf1.gif'),
pygame.image.load('ftr1_lf2.gif')]
 bg=pygame.image.load('60_1275.jpg')
playerStand=pygame.image.load('ftr1_fr1.gif')
 clock=pygame.time.Clock()
x=50
y=867
widht=16
height=16
speed=7
isJump= False
jumpCount= 10
 left=False
right=False
animCount=0
 lastMove="right"
 class snaryad():
 def __init__(self,x,y,radius,color,facing):
  self.x=x
  self.y=y
  self.radius=radius
  self.color=color
  self.facing=facing
  self.vel=8*facing
  def draw(self,win):
  pygame.draw.circle(win,self.color,(self.x,self.y),self.radius)
 pl = pygame.Surface((40,40))
pl.fill((210,120,60))
 def make_level(level,pl):
 xi=0
 yi=0
 for row in level:
  for col in row:
   if col=='-':
    win.blit(pl ,(xi,yi))
   xi= 40
  yi += 40
  xi=0
 level= [
 '--------------------------------------------',
 '-                                          -',
 '-                                          -',
 '-                                          -',
 '-                                          -',
 '-                                          -',
 '                                           -',
 '-                                          -',
 '-                                          -',
 '-                                          -',
 '-                                          -',
 '-                                          -',
 '-                                          -',
    '-                                          -',
 '--------------------------------------------',]
pl = pygame.Surface((40,40))
pl.fill((210,120,60))
   def drawWindow():
 global animCount
 win.blit(bg,(0,0))
  if animCount + 1 >=10:
  animCount=0
 if left:
  win.blit(walkLeft[animCount//5],(x,y))
  animCount += 1
 elif right:
  win.blit(walkRight[animCount//5],(x,y))
  animCount += 1
 else:
  win.blit(playerStand,(x,y))
 for bullet in bullets:
  bullet.draw(win)
  pygame.display.update()
run=True
bullets=[]
while run:
 clock.tick(30)
 for event in pygame.event.get():
  if event.type==pygame.QUIT:
   run=False
  for bullet in bullets:
  if bullet.x < 1500 and bullet.x > 0:
   bullet.x += bullet.vel
  else:
   bullets.pop(bullets.index(bullet))
  keys=pygame.key.get_pressed()
 make_level(level,pl)
  if keys[pygame.K_f]:
  if lastMove == "right":
   facing = 1
  else:
   facing = -1
  if len(bullets) < 11:
   bullets.append(snaryad(round(x + widht//2),round(y + height),5,(60,0,80), facing))
   if keys[pygame.K_LEFT] and x>3:
  x -= speed
  left=True
  right=False
  lastMove="left"
 elif keys[pygame.K_RIGHT] and x<1500 - widht -19:
  x += speed
  left=False
  right=True
  lastMove="right"
 else:
  left=False
  right=False
  animCount=0
 if not(isJump):
  if keys[pygame.K_SPACE]:
   isJump=True
 else:
  if jumpCount >= -10:
   if jumpCount < 0:
    y += (jumpCount ** 2) / 2
   else:
    y -= (jumpCount ** 2) / 2
   jumpCount -= 1
  else:
   isJump=False
   jumpCount=10
 drawWindow()
pygame.quit()


Добавить комментарий