def __init__(self, screen_height, screen_width): super().__init__(screen_height, screen_width) self.background = pygame.image.load('Images/bg.jpg') self.platforms.empty() self.enemys.empty() self.level_limit = -700 self.dino_gun = True half_screen_width = self.screen_width // 2 level_platforms = [ [ pygame.Rect(0, self.screen_height - 40, half_screen_width - 200, 40), (0, 0, 0), 0, -0.099 ], # 1st ground [ pygame.Rect(0, self.screen_height - 300, (self.screen_width // 2) - 200, 40), (0, 0, 0), 0, -0.099 ], # special area [ pygame.Rect((self.screen_width // 2) + 200, self.screen_height - 40, 1800, 40), (0, 0, 0), 0, -0.099 ], # ground 2 [ pygame.Rect(self.screen_width // 2 - 150, self.screen_height // 2 + 150, 100, 30), (0, 0, 0), 0, -0.12 ], # stair 1 [ pygame.Rect(self.screen_width // 2 - 60, self.screen_height // 2 + 100, 100, 30), (0, 0, 0), 0, -0.12 ], # stair 2 [ pygame.Rect(self.screen_width // 2 + 50, self.screen_height // 2 + 50, 100, 30), (0, 0, 0), 0, -0.12 ] # stair 3 ] for platform in level_platforms: self.platforms.add(Platform.from_list(platform)) self.enemys.add( Slime(700, 441, VEC(3, 0), pygame.Rect(600, 400, 200, 40))) self.enemys.add( Slime(20, 181, VEC(3, 0), pygame.Rect(0, screen_height - 400, 200, 40)))
def __init__(self, x, y, width, height, walking_path, image_dir, vel=VEC(0, 0)): super().__init__(x, y, height, width, image_dir, vel) self.bounds = walking_path self.health = STARTING_HEALTH
def update_location(self, screen_height): self.acc.y = self.grav self.acc.x += self.vel.x * self.friction self.vel += self.acc self.pos += self.vel + self.acc self.acc = VEC(0, self.grav) if self.pos.y > screen_height: self.lose_life() self.update_rectangle()
def __init__(self, start): (start_x, start_y) = start super().__init__(start_x, start_y, 52, 52, 'Images/Dino') self.player_acc = 0.5 self.vel = VEC(0, 0) self.grav = 0.8 self.acc = VEC(0, self.grav) self.jump_count = 0 self.standing = True self.footbox = (self.pos.x + 19, self.pos.y + 50, 16, 4) self.image_heart = pygame.image.load('Images/Dino/Heart.png') self.image_life = pygame.image.load('Images/Dino/Lives.png') self.gun = True self.touching_platform = False self.friction = -0.12 self.hearts = 3 self.lives = 3 self.start_x = start_x self.start_y = start_y self.bounds = pygame.Rect(0, 0, 800, 480) self.dead = False
def stop(self): self.acc = VEC(0, self.grav) self.standing = True self.walk_count = 0
def move_right(self): self.acc = VEC(0, self.grav) self.acc.x = self.player_acc self.facing_left = False self.standing = False
def move_left(self): self.acc = VEC(0, self.grav) self.acc.x = -self.player_acc self.facing_left = True self.standing = False
def reset(self): self.dead = False self.pos = VEC(self.start_x, self.start_y) self.hearts = 3