Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.09 KB | None | 0 0
  1. import pygame as pg
  2.  
  3.  
  4. pg.init()
  5.  
  6.  
  7. class Player:
  8.     def __init__(self, x, y, f_x, f_y, width, height, flor):
  9.         self.x = x
  10.         self.y = y
  11.         self.f_x = f_x
  12.         self.f_y = f_y
  13.         self.width = width
  14.         self.height = height
  15.         self.step = 5
  16.         self.jump = 5
  17.         self.flor = flor
  18.         self.jump_fact = False
  19.  
  20.     def moving(self):
  21.         keys = pg.key.get_pressed()
  22.         if keys[pg.K_a]:
  23.             if self.x == (1080 / 2) - self.width / 2:
  24.                 if self.f_x < -5:
  25.                     self.f_x += self.step
  26.                 else:
  27.                     self.x -= self.step
  28.             elif self.x > 40:
  29.                 self.x -= self.step
  30.  
  31.         if keys[pg.K_d]:
  32.             if self.x == (1080 / 2) - self.width / 2:
  33.                 if self.f_x > -1620:
  34.                     self.f_x -= self.step
  35.                 else:
  36.                     self.x += self.step
  37.             elif self.x < 1080 - self.width - 40:
  38.                 self.x += self.step
  39.  
  40.         if not self.jump_fact:
  41.             if keys[pg.K_SPACE]:
  42.                 self.jump_fact = True
  43.         else:
  44.             if self.jump >= -5:
  45.                 if self.jump < 0:
  46.                     self.y += self.jump ** 2
  47.                 else:
  48.                     self.y -= self.jump ** 2
  49.                     self.jump -= 1
  50.             else:
  51.                 self.jump_fact = False
  52.                 self.jump = 5
  53.  
  54.     def model(self):
  55.         return pg.draw.rect(screen, (255, 225, 0), (self.x, self.y, self.width, self.height))
  56.  
  57.     def flor(self):
  58.         return screen.blit(self.flor, (self.f_x, self.f_y))
  59.  
  60.  
  61. screen = pg.display.set_mode((1080, 590))
  62. bg = pg.image.load('img/bg2.jpg')
  63. img = pg.image.load('img/moving_bg.png')
  64. clock = pg.time.Clock()
  65. pl = Player(510, 425, -812, 300, 60, 85, img)
  66.  
  67.  
  68. def reset_window():
  69.     screen.blit(bg, (0, 0))
  70.     pl.flor()
  71.     pl.model()
  72.     pg.display.update()
  73.  
  74.  
  75. while True:
  76.     clock.tick(60)
  77.  
  78.     for event in pg.event.get():
  79.         if event.type == pg.QUIT:
  80.             exit()
  81.  
  82.     pl.moving()
  83.  
  84.     reset_window()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement