Advertisement
Guest User

Player help

a guest
Mar 18th, 2018
119
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. from settings import Music_Mixer, loadCustomFont, States, screen
  3. from time import sleep
  4.  
  5. """This section contains entity states which are separate from game and menu states."""
  6. class Player():
  7.     def __init__(self, x, y):
  8.         self.health = 100
  9.         self.speed = 1
  10.         self.screen = screen
  11.         self.imagex = x
  12.         self.imagey = y
  13.         self.running_right = False
  14.         self.running_left = False
  15.         self.rect = pg.draw.rect(self.screen, (255, 0, 0), [self.imagex, self.imagey, 20, 45])
  16.         self.image = pg.image.load('Images/Animations/PlayerRun/Stickman_stand_still.png').convert_alpha()
  17.         self.images = ['Images/Animations/PlayerRun/Stickman_stand_still.png', 'Images/Animations/PlayerRun/Stickman_run_1.png', 'Images/Animations/PlayerRun/Stickman_run_2.png',
  18.         'Images/Animations/PlayerRun/Stickman_run_3.png', 'Images/Animations/PlayerRun/Stickman_run_4.png']
  19.        
  20.     #Moves the player and begins the animation phase.
  21.     def move_player(self, speed):
  22.         self.pressed = pg.key.get_pressed()
  23.        
  24.         #Move left and start left run animation.
  25.         if self.pressed[pg.K_a]:
  26.             self.imagex -= 5
  27.            
  28.         #Move right and start right run animation
  29.         if self.pressed[pg.K_d]:
  30.             self.running_right = True
  31.             self.imagex += 5
  32.         elif not self.pressed[pg.K_d]:
  33.             self.running_right = False
  34.            
  35.         #Move up and start jump animation.
  36.         if self.pressed[pg.K_w]:
  37.            self.imagey -= 5
  38.        
  39.         #Move down and start either crouch.
  40.         if self.pressed[pg.K_s]:
  41.             self.imagey += 5
  42.    
  43.     #Animates the running movement of the player.
  44.     def runAnim(self):
  45.        
  46.         if self.running_right:
  47.             pass
  48.            
  49.         elif self.running_right == False:
  50.             self.image = pg.image.load('Images/Animations/PlayerRun/Stickman_stand_still.png').convert_alpha()
  51.    
  52.     #draws the player to the screen.
  53.     def draw_entity(self):
  54.         screen.blit(self.image, (self.imagex, self.imagey))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement