Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame as pg
- pg.init()
- class Player:
- def __init__(self, x, y, f_x, f_y, width, height, flor):
- self.x = x
- self.y = y
- self.f_x = f_x
- self.f_y = f_y
- self.width = width
- self.height = height
- self.step = 5
- self.jump = 5
- self.flor = flor
- self.jump_fact = False
- def moving(self):
- keys = pg.key.get_pressed()
- if keys[pg.K_a]:
- if self.x == (1080 / 2) - self.width / 2:
- if self.f_x < -5:
- self.f_x += self.step
- else:
- self.x -= self.step
- elif self.x > 40:
- self.x -= self.step
- if keys[pg.K_d]:
- if self.x == (1080 / 2) - self.width / 2:
- if self.f_x > -1620:
- self.f_x -= self.step
- else:
- self.x += self.step
- elif self.x < 1080 - self.width - 40:
- self.x += self.step
- if not self.jump_fact:
- if keys[pg.K_SPACE]:
- self.jump_fact = True
- else:
- if self.jump >= -5:
- if self.jump < 0:
- self.y += self.jump ** 2
- else:
- self.y -= self.jump ** 2
- self.jump -= 1
- else:
- self.jump_fact = False
- self.jump = 5
- def model(self):
- return pg.draw.rect(screen, (255, 225, 0), (self.x, self.y, self.width, self.height))
- def flor(self):
- return screen.blit(self.flor, (self.f_x, self.f_y))
- screen = pg.display.set_mode((1080, 590))
- bg = pg.image.load('img/bg2.jpg')
- img = pg.image.load('img/moving_bg.png')
- clock = pg.time.Clock()
- pl = Player(510, 425, -812, 300, 60, 85, img)
- def reset_window():
- screen.blit(bg, (0, 0))
- pl.flor()
- pl.model()
- pg.display.update()
- while True:
- clock.tick(60)
- for event in pg.event.get():
- if event.type == pg.QUIT:
- exit()
- pl.moving()
- reset_window()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement