eternalfool343

actor.py

Apr 5th, 2021
546
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame
  2.  
  3.  
  4.  
  5.  
  6. class Actor:
  7.     """    
  8.     x, y                --current position of dinosaur
  9.     jump_height         --jump height of the dinosaur  
  10.  
  11.     """
  12.     def __init__(self, x0, y0, velocity = [0,0]):           # Velocity = [x_vel, y_vel]
  13.         self.x = x0                                     # Set Initial Position x0, y0
  14.         self.y = y0
  15.         self.velocity = velocity
  16.  
  17.    
  18.  
  19. class Player(Actor):
  20.     """    
  21.     x, y                --current position of dinosaur
  22.     jump_height         --jump height of the dinosaur  
  23.     velocity = [0,0]    -- Specify Velocity = [x_vel, y_vel]
  24.  
  25.     """
  26.     def __init__(self, x0, y0, jump_height, velocity = [0,0] ):
  27.         super().__init__(x0, y0,  velocity = [0,0])
  28.    
  29.     def create_sprite(self, actor, surface):                        # actor is str, passed to create a img_path and
  30.         self.actor = actor
  31.         self.surface = surface
  32.         image_path = 'assets/imported/' + self.actor + '.png'
  33.         self.image = pygame.image.load(image_path) 
  34.         self.actor_rect = pygame.Rect(50, 50, self.image.get_width(), self.image.get_height())
  35.  
  36.         surface.blit(self.image, self.actor_rect)
  37.            
  38.  
  39.  
  40.     def jump(self):
  41.         self.y -= jump_height
  42.  
  43.  
  44.     def update_position(self, velocity, surface):  
  45.         self.x += velocity[0]
  46.         self.y += velocity[1]
  47.  
  48.         self.actor_rect.x = self.x
  49.         self.actor_rect.y = self.y
  50.  
  51.         surface.blit(self.image, (self.actor_rect.x, self.actor_rect.y) )
  52.         #pygame.display.update(self.actor_rect)
  53.  
  54.     @property      
  55.     def position(self):
  56.         return [self.x, self.y]
  57.  
  58.    
  59.  
  60.  
  61.  
  62. # trex = Player(10, 10 , 5, [1,1])
  63. # print(trex.position)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×