Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- pygame.init()
- screen = pygame.display.set_mode((1080,720))
- background = pygame.image.load('assets/bg.jpg').convert()
- class Player(pygame.sprite.Sprite):
- def __init__(self):
- super().__init__()
- self.health = 100
- self.maxhealt = 100
- self.attack = 8
- self.velocity = 5
- self.image = pygame.image.load('assets/player.png').convert_alpha()
- self.rect = self.image.get_rect()
- self.rect.x = 400
- self.rect.y = 500
- def move_right(self):
- self.rect.x += self.velocity
- def move_left(self):
- self.rect.x -= self.velocity
- def update(self):
- # for future use. Here you can add automatic movement / animation / collision detection......
- pass
- # ---- PLAYER CLASS DONE -------
- player = Player() #Creating a playerobject
- while running:
- screen.blit(background,(0,-200))
- player.update() #for future use, for instance animation
- player.draw()
- pressed = pygame.key.get_pressed()
- if pressed[pygame.K_LEFT]:
- game.player.move_left()
- if pressed[pygame.K_RIGHT]:
- game.player.move_right()
- pygame.display.flip()
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment