Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- class Actor:
- """
- x, y --current position of dinosaur
- jump_height --jump height of the dinosaur
- """
- def __init__(self, x0, y0, velocity = [0,0]): # Velocity = [x_vel, y_vel]
- self.x = x0 # Set Initial Position x0, y0
- self.y = y0
- self.velocity = velocity
- class Player(Actor):
- """
- x, y --current position of dinosaur
- jump_height --jump height of the dinosaur
- velocity = [0,0] -- Specify Velocity = [x_vel, y_vel]
- """
- def __init__(self, x0, y0, jump_height, velocity = [0,0] ):
- super().__init__(x0, y0, velocity = [0,0])
- def create_sprite(self, actor, surface): # actor is str, passed to create a img_path and
- self.actor = actor
- self.surface = surface
- image_path = 'assets/imported/' + self.actor + '.png'
- self.image = pygame.image.load(image_path)
- self.actor_rect = pygame.Rect(50, 50, self.image.get_width(), self.image.get_height())
- surface.blit(self.image, self.actor_rect)
- def jump(self):
- self.y -= jump_height
- def update_position(self, velocity, surface):
- self.x += velocity[0]
- self.y += velocity[1]
- self.actor_rect.x = self.x
- self.actor_rect.y = self.y
- surface.blit(self.image, (self.actor_rect.x, self.actor_rect.y) )
- #pygame.display.update(self.actor_rect)
- @property
- def position(self):
- return [self.x, self.y]
- # trex = Player(10, 10 , 5, [1,1])
- # print(trex.position)
RAW Paste Data