class Sprite(pygame.sprite.Sprite): def __init__(self, image): #initialize the class with the base class pygame.sprite.Sprite.__init__(self) self.size = 50 try: self.ss = SpriteSheet(image) self.image = self.ss.image_at((0, 0, 32, 32), (255, 0, 255)) self.image.convert() self.image = pygame.transform.scale(self.image, [self.size] * 2) except: self.image = pygame.Surface([self.size] * 2) self.image.fill((0, 0, 0)) # print self.image self.speed = self.size # self.image.fill((255, 255, 255)) self.keys = [K_UP, K_DOWN, K_LEFT, K_RIGHT] self.rect = self.image.get_rect() def update(self, actions): # if actions: print '----' # self.rect.y += 1 for action in actions: if action.key in self.keys: if action.key == K_UP: self.rect.y -= self.speed elif action.key == K_DOWN: self.rect.y += self.speed elif action.key == K_LEFT: self.rect.x -= self.speed elif action.key == K_RIGHT: self.rect.x += self.speed
class Fruit(Sprite): def __init__(self, screen, type_fruit): super(Fruit, self).__init__() self.is_dead = False self.type_fruit = type_fruit self.points = 0 self.position = [(35, 50, 14, 14), (52, 50, 14, 14), (67, 50, 14, 14), (83, 50, 14, 14), (100, 50, 14, 14), (115, 50, 14, 14), (132, 50, 14, 14), (147, 50, 14, 14)] self.location_x = 600 self.location_y = 585 self.screen = screen self.sprite_sheet = SpriteSheet('sprites/pacman.png') self.image = self.sprite_sheet.image_at(self.position[self.type_fruit], None) self.image = pygame.transform.scale(self.image, (30, 30)) self.rect = self.image.get_rect() self.rect.x = self.location_x self.rect.y = self.location_y def draw(self): self.screen.screen.blit(self.image, self.rect) def set_points(self): if self.type_fruit == 0: self.points = 100 elif self.type_fruit >= 4: self.points = (self.type_fruit - 3) * 1000 elif self.type_fruit == 1: self.points = 300 elif self.type_fruit == 2: self.points = 500 else: self.points = 700
def __init__(self, **argd): self.__dict__.update(**argd) super(MainScreen, self).__init__(**argd) # create a display image. standard pygame stuff self.display = pygame.display.set_mode(self.size, 0) self.background = pygame.Surface(SCREEN_RECT.size) # Initialize camera if ARGS.camera: self.init_cams(0) # Load graphics deafy_sheet = SpriteSheet("data/Undertale_Annoying_Dog.png") cat_sheet = SpriteSheet("data/cat.png") Deafy.images = [ deafy_sheet.image_at((2, 101, 22 - 2, 119 - 101), colorkey=-1, width_height=(20 * 2, 18 * 2), flip_x=True), deafy_sheet.image_at((2, 204, 26 - 2, 216 - 204), colorkey=-1, width_height=(24 * 2, 12 * 2), flip_x=True), deafy_sheet.image_at((2, 182, 23 - 2, 200 - 182), colorkey=-1, width_height=(21 * 2, 18 * 2), flip_x=True), deafy_sheet.image_at((25, 182, 44 - 25, 200 - 182), colorkey=-1, width_height=(19 * 2, 18 * 2), flip_x=True), deafy_sheet.image_at((2, 101, 22 - 2, 119 - 101), colorkey=-1, width_height=(20 * 2, 18 * 2), flip_x=True, flip_y=True), ] Sky.images = [load_image('sky.png', (32, 32))] Ground.images = [load_image('grass.png', (32, 32))] GroundObstacle.images = [ load_image('grass.png', (32, 32)), load_image('sky.png', (32, 32)) ] CatObstacle.images = [ cat_sheet.image_at((0, 0, 54, 42), colorkey=-1), cat_sheet.image_at((1, 158, 54, 42), colorkey=-1), cat_sheet.image_at((1 + 54, 158, 54, 42), colorkey=-1), cat_sheet.image_at((1 + 54 * 2, 158, 54, 42), colorkey=-1), cat_sheet.image_at((1 + 54 * 3, 158, 54, 42), colorkey=-1), ] # Load sounds Deafy.sounds = [ load_sound("normal.ogg"), load_sound("jump.ogg"), load_sound("victory.ogg") ] # Initialize Game Groups self.all = pygame.sprite.RenderUpdates() self.background_group = pygame.sprite.RenderUpdates() self.obstacle_group = pygame.sprite.RenderUpdates() # Sprites in this group are rendered after background so that they appear on the top. self.front_group = pygame.sprite.RenderUpdates() # assign default groups to each sprite class Deafy.containers = self.all, self.front_group Ground.containers = self.all, self.background_group Sky.containers = self.all, self.background_group GroundObstacle.containers = self.all, self.obstacle_group CatObstacle.containers = self.all, self.front_group Dialog.containers = self.all # initialize stage self.stage = Stage(num=1) self.current_items = [] # TODO: Maybe the height and width are the other way around self.ground_sprites = [ Ground(pos=(w * BACKGROUND_OBJECT_WIDTH, h * BACKGROUND_OBJECT_HEIGHT)) for w in range(SCREEN_WIDTH / BACKGROUND_OBJECT_WIDTH + 1) for h in range(GROUND_Y_LIMITS[0] / BACKGROUND_OBJECT_HEIGHT + 1, GROUND_Y_LIMITS[1] / BACKGROUND_OBJECT_HEIGHT + 1) ] self.sky_sprites = [ Sky(pos=(w * BACKGROUND_OBJECT_WIDTH, h * BACKGROUND_OBJECT_HEIGHT)) for w in range(SCREEN_WIDTH / BACKGROUND_OBJECT_WIDTH + 1) for h in range(SKY_Y_LIMITS[0] / BACKGROUND_OBJECT_HEIGHT + 1, SKY_Y_LIMITS[1] / BACKGROUND_OBJECT_HEIGHT + 1) ] self.deafy = Deafy(pos=DEAFY_SCREEN_POS) self.ground_obstacle_sprites = [] self.cat_obstacles = [] # Now initialize the FacialLandmarkDetector self.fld = FacialLandmarkDetector(SCREEN_WIDTH, SCREEN_HEIGHT, FACIAL_LANDMARK_PREDICTOR_WIDTH) self.dx = INITIAL_DX self.visible_xrange = [0, SCREEN_WIDTH] # to track of which dialog frame shold be rendered self.dialog_frame = 0 # To trach whether dialog is displayed now. If so, disable user control. self.is_dialog_active = True
class ButtonTray: """ a strip of icon buttons anchored to the corner of the editor window """ def __init__(self, icon_filename, surface): self.button_names = (RUN, STOP, SAVE, LOAD, CHANGE_COLOR) self.surface = surface self.button_count = 5 self.button_size = 16 self.button_margin = 2 width = ((self.button_size * self.button_count) + (self.button_margin * (self.button_count + 1))) height = self.button_size + self.button_margin * 2 self.tray_size = (width, height) self.top_left = [(surface.get_size()[X] - width - 3), (surface.get_size()[Y] - height) - 3] self.tray = pygame.Rect(self.top_left, self.tray_size) self.sprites = SpriteSheet(icon_filename) # the icons don't use alpha transparency - bg color is fixed #self.up_buttons = self.sprites.load_strip( # pygame.Rect(0, 0, self.button_size, self.button_size), # self.button_count) #self.down_buttons = self.sprites.load_strip( # pygame.Rect(self.button_size * self.button_count, 0, # self.button_size, self.button_size), # self.button_count) self.buttons = {} up_pos = [0, 0] down_pos = [self.button_size * self.button_count, 0] size = (self.button_size, self.button_size) self.buttons = {} for name in self.button_names: self.buttons[name] = \ {UP: self.sprites.image_at(pygame.Rect(up_pos, size)), DOWN: self.sprites.image_at(pygame.Rect(down_pos, size))} up_pos[X] += self.button_size down_pos[X] += self.button_size self.button_state = { RUN: UP, SAVE: UP, STOP: UP, LOAD: UP, CHANGE_COLOR: UP } def click(self, pos): # returns the button constant corresponding to the pos (x,y) coords # or None if pos lies outside the tray if self.tray.collidepoint(pos): # convert x coord to the button number button = int((pos[X] - self.top_left[X]) / (self.button_size + self.button_margin)) + 1 if button in self.button_names: self.button_state[button] = DOWN return button return None def release(self): # revert all the buttons to their up state for button in self.button_names: self.button_state[button] = UP def draw(self, fg_color, bg_color): pygame.draw.rect(self.surface, fg_color, self.tray) pos = [ self.top_left[X] + self.button_margin, self.top_left[Y] + self.button_margin ] for b in self.button_names: button_image = self.buttons[b][self.button_state[b]] self.surface.blit(button_image, pos) pos[X] += self.button_size + self.button_margin
class Ghost(Sprite): def __init__(self, screen, color): super(Ghost, self).__init__() self.screen = screen # the number of the color will be 0 through 5 # 0 = pink, 1 = red, 2 = orange, 3 = blue, 4 = white, 5 = blue self.color = color self.right = (4, self.color, 15, 15) self.right_in = (20, self.color, 15, 15) self.left = (35, self.color, 15, 15) self.left_in = (52, self.color, 15, 15) self.up = (68, self.color, 15, 15) self.up_in = (84, self.color, 15, 15) self.down = (100, self.color, 15, 15) self.down_in = (115, self.color, 15, 15) self.is_blue = False self.blue_last = 0 self.blue_wait = 5000 self.is_white = False self.white_last = 0 self.white_wait = 1000 self.white = (163, 65, 15, 15) self.white_in = (180, 65, 15, 15) self.blue = (132, 65, 15, 15) self.blue_in = (148, 65, 15, 15) self.eye = False self.is_dead = False self.destroyed = False self.destroy_last = 0 self.destroy_wait = 1000 self.eye_right = (132, 81, 15, 15) self.eye_left = (148, 81, 15, 15) self.eye_up = (163, 81, 15, 15) self.eye_down = (180, 81, 15, 15) self.position = [self.up, self.up_in] self.location_x = 100 self.location_y = 220 self.screen = screen self.sprite_sheet = SpriteSheet('sprites/pacman.png') self.image = self.sprite_sheet.image_at(self.position[0], None) self.image = pygame.transform.scale(self.image, (30, 30)) self.rect = self.image.get_rect() self.rect.x = self.location_x self.rect.y = self.location_y self.ismoving = False self.ismoving_up = False self.ismoving_down = False self.ismoving_right = False self.ismoving_left = False self.wait_count = 0 self.time = pygame.time.get_ticks() self.animation_counter = 0 self.moving_speed = 4 self.intro = False self.intro_blinky = False self.intro_pinky = False self.intro_inky = False self.intro_clyde = False self.title_blinky = False self.title_pinky = False self.title_inky = False self.title_clyde = False self.title_last = 0 self.wait = 1000 self.wait_count = 100 self.last = 0 self.route = ['dG', 'dH', 'fH', 'hH', 'iH', 'iG', 'jG', 'jF'] self.speed = 1 self.dijkstra_graph = {} self.node_count = 1 self.next_route = True self.move_nodes = True self.final_distance = 0 self.move_count = 0 def update(self): if not self.screen.game_active: self.moving_down() self.moving_up() self.moving_left() self.moving_right() self.moving() if self.is_dead: self.ismoving = False self.position = (19, 130, 15, 15) if self.screen.ghosts_destroyed == 1: self.position = (3, 130, 15, 15) if self.screen.ghosts_destroyed == 2: self.position = (19, 130, 15, 15) if self.screen.ghosts_destroyed == 3: self.position = (35, 130, 16, 15) if self.screen.ghosts_destroyed == 4: self.position = (50, 130, 17, 15) self.image = self.sprite_sheet.image_at(self.position, None) if self.screen.ghosts_destroyed == 3 and not self.destroyed: self.screen.ghosts_destroyed = 4 if self.screen.ghosts_destroyed == 2 and not self.destroyed: self.screen.ghosts_destroyed = 3 if self.screen.ghosts_destroyed == 1 and not self.destroyed: self.screen.ghosts_destroyed = 2 if self.screen.ghosts_destroyed == 0 and not self.destroyed: self.screen.ghosts_destroyed = 1 self.destroyed = True now = pygame.time.get_ticks() if self.destroy_last == 0: self.destroy_last = now if self.destroy_last + self.destroy_wait < now: self.position = self.eye_right self.image = self.sprite_sheet.image_at(self.position, None) self.image = pygame.transform.scale(self.image, (30, 30)) self.ismoving = True self.is_dead = False self.eye = True if self.screen.game_active: self.moving() # print(self.node_count) # print(self.route) self.next_route = False if self.node_count >= len(self.route)-1: self.next_route = True self.node_count = 1 current = self.route[self.node_count-1] # aA next_destination = self.route[self.node_count] # print(next_destination) destinations = self.dijkstra_graph.get(self.route[self.node_count-1]) # dijkstra_route[i] this is aA # print(self.route) # print(next_destination) self.final_distance = destinations.get(next_destination) # print(self.final_distance) # these if statements compare the letters of each destination I.E aA and cB # if the first letter is smaller then it should be going down # if the second letter is smaller then it should be going right if current[0] < next_destination[0] and current[1] == next_destination[1]: # print('going down') self.ismoving = True self.ismoving_down = True self.ismoving_left = False self.ismoving_up = False self.ismoving_right = False if current[0] > next_destination[0] and current[1] == next_destination[1]: # print('going up') self.ismoving = True self.ismoving_down = False self.ismoving_left = False self.ismoving_up = True self.ismoving_right = False if current[1] < next_destination[1] and current[0] == next_destination[0]: # print('going right') self.ismoving = True self.ismoving_down = False self.ismoving_left = False self.ismoving_up = False self.ismoving_right = True if current[1] > next_destination[1] and current[0] == next_destination[0]: # print('going left') self.ismoving = True self.ismoving_down = False self.ismoving_left = True self.ismoving_up = False self.ismoving_right = False # print(self.move_count) # print(self.final_distance) if self.move_count < self.final_distance and self.ismoving_up: # print('yes') self.rect.centery -= self.speed elif self.move_count >= self.final_distance and self.ismoving_up: # print('no') self.node_count += 1 self.move_count = 0 if self.move_count < self.final_distance and self.ismoving_down: # print('yes') self.rect.centery += self.speed elif self.move_count >= self.final_distance and self.ismoving_down: # print('no') self.node_count += 1 self.move_count = 0 if self.move_count < self.final_distance and self.ismoving_right: # print('yes') self.rect.centerx += self.speed elif self.move_count >= self.final_distance and self.ismoving_right: # print('no') self.node_count += 1 self.move_count = 0 if self.move_count < self.final_distance and self.ismoving_left: # print('yes') self.rect.centerx -= self.speed elif self.move_count >= self.final_distance and self.ismoving_left: # print('no') self.node_count += 1 self.move_count = 0 self.move_count += 1 def draw(self): self.screen.screen.blit(self.image, self.rect) def change_location(self, x_location, y_location): self.rect.x = x_location self.rect.y = y_location def change_type(self, position): self.position = position def moving_right(self): if self.ismoving_right and not self.screen.game_active: self.rect.x = self.rect.x + self.moving_speed def moving_left(self): if self.ismoving_left and not self.screen.game_active: self.rect.x = self.rect.x - self.moving_speed def moving_up(self): if self.ismoving_up and not self.screen.game_active: self.rect.y = self.rect.y - self.moving_speed def moving_down(self): if self.ismoving_down and not self.screen.game_active: self.rect.y = self.rect.y + self.moving_speed def moving(self): if self.ismoving: if self.ismoving_down: self.position = [self.down, self.down_in] if self.ismoving_up: self.position = [self.up, self.up_in] if self.ismoving_right: self.position = [self.right, self.right_in] if self.ismoving_left: self.position = [self.left, self.left_in] if self.is_blue: now = pygame.time.get_ticks() self.position = [self.blue, self.blue_in] if self.blue_last == 0: self.blue_last = now if self.blue_last + self.blue_wait < now: self.is_white = True self.position = [self.blue, self.white_in] now_two = pygame.time.get_ticks() if self.white_last == 0: self.white_last = now_two if self.white_last + self.white_wait < now_two: self.is_white = False self.is_blue = False self.screen.ghosts_destroyed = 0 if self.eye and self.ismoving_left: self.position = [self.eye_left, self.eye_left] if self.eye and self.ismoving_right: self.position = [self.eye_right, self.eye_right] if self.eye and self.ismoving_up: self.position = [self.eye_up, self.eye_up] if self.eye and self.ismoving_down: self.position = [self.eye_down, self.eye_down] now = pygame.time.get_ticks() if self.last == 0: self.last = now if self.last + self.wait_count < now: self.position = self.position[self.animation_counter] self.image = self.sprite_sheet.image_at(self.position, None) self.image = pygame.transform.scale(self.image, (30, 30)) self.animation_counter += 1 self.wait_count += 250 if self.animation_counter > 1: self.animation_counter = 0
class PacMan(Sprite): def __init__(self, screen, pacmen, ghosts, maze, scoreboard): super(PacMan, self).__init__() self.maze = maze self.scoreboard = scoreboard self.pacmen = pacmen self.ghosts = ghosts self.next_direction = '' self.direction = '' self.no_node = False self.right_stopper = False self.left_stopper = False self.up_stopper = False self.down_stopper = False self.dont_stop = False self.right_allowed = False self.left_allowed = False self.up_allowed = False self.down_allowed = False self.a = False self.b = False self.c = False self.d = False self.e = False self.f = False self.g = False self.h = False self.i = False self.j = False self.k = False self.l = False self.m = False # each of these are coordinates to the location and size # of the sprite on the sheet self.is_big = False self.big_open = (35, 15, 30, 35) self.big_mid = (65, 15, 34, 35) self.big_close = (97, 15, 35, 34) self.up_open = (4, 30, 16, 16) self.up_mid = (19, 30, 16, 16) self.close = (34, 0, 15, 15) self.down_open = (4, 47, 16, 16) self.down_mid = (19, 47, 16, 16) self.left_open = (4, 15, 16, 16) self.left_mid = (19, 15, 16, 16) self.right_open = (4, 0, 15, 15) self.right_mid = (20, 0, 15, 15) self.destroy_wait = 100 self.destroy_last = 0 self.animate = 0 self.is_dead = False self.destroy = [(50, 0, 15, 15), (67, 0, 15, 15), (83, 0, 15, 15), (98, 0, 16, 15), (115, 0, 16, 15), (130, 0, 16, 15), (146, 0, 16, 15), (161, 0, 16, 15), (176, 0, 16, 15), (191, 0, 16, 15), (208, 0, 16, 16)] self.position = self.big_open self.location_x = 0 self.location_y = 220 self.screen = screen self.sprite_sheet = SpriteSheet('sprites/pacman.png') self.image = self.sprite_sheet.image_at(self.position, None) if not self.is_big: self.image = pygame.transform.scale(self.image, (30, 30)) self.rect = self.image.get_rect() self.rect.x = self.location_x self.rect.y = self.location_y self.ismoving = False self.ismoving_up = False self.ismoving_down = False self.ismoving_right = False self.ismoving_left = False self.wait_count = 100 self.last = 0 self.time = pygame.time.get_ticks() self.animation_counter = 1 self.moving_speed = 4.00 def update(self): if self.screen.game_active: if self.ismoving_right or self.ismoving_left and self.no_node: self.ismoving_up = False self.ismoving_down = False if self.ismoving_up or self.ismoving_down and self.no_node: self.ismoving_right = False self.ismoving_left = False if self.ismoving_right and self.right_stopper: self.ismoving_right = False self.ismoving = False self.change_type(self.right_mid) if self.ismoving_left and self.left_stopper: self.ismoving_left = False self.ismoving = False self.change_type(self.left_mid) if self.ismoving_up and self.up_stopper: self.change_type(self.up_mid) self.ismoving_up = False self.ismoving = False if self.ismoving_down and self.down_stopper: self.ismoving_down = False self.ismoving = False self.change_type(self.down_mid) if self.direction == 'right' and self.right_allowed or ( self.next_direction == 'right' and self.right_allowed): self.ismoving_down = False self.ismoving_up = False self.ismoving_left = False self.ismoving_right = True self.ismoving = True elif self.direction == 'left' and self.left_allowed or ( self.next_direction == 'left' and self.left_allowed): self.ismoving_down = False self.ismoving_up = False self.ismoving_right = False self.ismoving_left = True self.ismoving = True elif self.direction == 'up' and self.up_allowed or ( self.next_direction == 'up' and self.up_allowed): self.ismoving_down = False self.ismoving_left = False self.ismoving_right = False self.ismoving_up = True self.ismoving = True elif self.direction == 'down' and self.down_allowed or ( self.next_direction == 'down' and self.down_allowed): self.ismoving_up = False self.ismoving_left = False self.ismoving_right = False self.ismoving_down = True self.ismoving = True self.moving_down() self.moving_up() self.moving_left() self.moving_right() self.moving() if self.is_dead: now = pygame.time.get_ticks() if self.destroy_last == 0: self.destroy_last = now if self.destroy_last + self.destroy_wait < now: self.position = self.destroy[self.animate] self.image = self.sprite_sheet.image_at(self.position, None) if not self.is_big: self.image = pygame.transform.scale(self.image, (30, 30)) self.animate += 1 self.destroy_wait += 75 if self.animate >= 11: self.remove(self.pacmen) # self.screen.reset_the_game(self.maze, self.scoreboard, self, self.ghosts) self.screen.reset_game = True def draw(self): self.screen.screen.blit(self.image, self.rect) def change_location(self, x_location, y_location): self.rect.x = x_location self.rect.y = y_location def change_type(self, position): self.position = position def moving_right(self): if self.ismoving_right: self.rect.x = self.rect.x + self.moving_speed def moving_left(self): if self.ismoving_left: self.rect.x = self.rect.x - self.moving_speed def moving_up(self): if self.ismoving_up: self.rect.y = self.rect.y - self.moving_speed def moving_down(self): if self.ismoving_down: self.rect.y = self.rect.y + self.moving_speed def moving(self): if self.ismoving: if self.ismoving_down: self.position = [ self.down_open, self.down_mid, self.close, self.down_mid ] if self.ismoving_up: self.position = [ self.up_open, self.up_mid, self.close, self.up_mid ] if self.ismoving_right: self.position = [ self.right_open, self.right_mid, self.close, self.right_mid ] if self.ismoving_left: self.position = [ self.left_open, self.left_mid, self.close, self.left_mid ] if not self.screen.game_active and self.is_big: self.position = [ self.big_open, self.big_mid, self.big_close, self.big_mid ] now = pygame.time.get_ticks() if self.last == 0: self.last = now if self.last + self.wait_count < now: self.position = self.position[self.animation_counter] self.image = self.sprite_sheet.image_at(self.position, None) if not self.is_big: self.image = pygame.transform.scale(self.image, (30, 30)) self.animation_counter += 1 self.wait_count += 75 if self.animation_counter >= 4: self.animation_counter = 0 def destroy_pacman(self): self.ismoving = False self.ismoving_down = False self.ismoving_left = False self.ismoving_right = False self.ismoving_up = False self.is_dead = True self.update()
def __init__(self, **argd): self.__dict__.update(**argd) super(MainScreen, self).__init__(**argd) # create a display image. standard pygame stuff self.display = pygame.display.set_mode(self.size, 0) self.background = pygame.Surface(GAME_SCREEN_RECT.size) # Create text display helper class. self.text = Text() # Initialize the stop flag. When the game stops, we need to stop the subprocess as well. Set the flag to any # value other than 0 to stop the subprocesses. self.stop_flag = Value('i', 0) # Load graphics deafy_sheet = SpriteSheet("data/Undertale_Annoying_Dog.png") cat_sheet = SpriteSheet("data/cat.png") Deafy.images = [ deafy_sheet.image_at((2, 101, 22 - 2, 119 - 101), colorkey=-1, width_height=(20 * 2, 18 * 2), flip_x=True), deafy_sheet.image_at((2, 204, 26 - 2, 216 - 204), colorkey=-1, width_height=(24 * 2, 12 * 2), flip_x=True), deafy_sheet.image_at((2, 182, 23 - 2, 200 - 182), colorkey=-1, width_height=(21 * 2, 18 * 2), flip_x=True), deafy_sheet.image_at((25, 182, 44 - 25, 200 - 182), colorkey=-1, width_height=(19 * 2, 18 * 2), flip_x=True), deafy_sheet.image_at((2, 101, 22 - 2, 119 - 101), colorkey=-1, width_height=(20 * 2, 18 * 2), flip_x=True, flip_y=True), ] Sky.images = [load_image('space-1.png', BATTLE_SCREEN_SIZE)] GroundObstacle.images = [ load_image('grass.png', (32, 32)), load_image('sky.png', (32, 32)) ] CatOpponent.images = [ cat_sheet.image_at((0, 0, 54, 42), colorkey=-1), cat_sheet.image_at((1, 158, 54, 42), colorkey=-1), cat_sheet.image_at((1 + 54, 158, 54, 42), colorkey=-1), cat_sheet.image_at((1 + 54 * 2, 158, 54, 42), colorkey=-1), cat_sheet.image_at((1 + 54 * 3, 158, 54, 42), colorkey=-1), ] self.default_face_photo = load_image( 'Barack-Obama-Funny-Face-Image.jpg') # Load sounds Deafy.sounds = [ load_sound("normal.ogg"), load_sound("jump.ogg"), load_sound("victory.ogg") ] CatOpponent.sounds = [ load_sound("cat_meow.wav"), load_sound("Cat-meow-nervous.wav"), load_sound("Angry-cat-sound.wav") ] self.background_sounds = [ load_sound("2A03_fluidvolt-Pallid_Underbrush.wav"), load_sound("2A03_Kevvviiinnn-Superfusion.wav"), load_sound("Class_gyms-Pastorale.wav"), load_sound("Class_Kulor-SpaceDolphinsSpaceCave.wav"), load_sound("Class_Zephemeros-Asymmetrical.wav"), load_sound("FDS_Kevvviiinnn_-_The_Devourer's_Wrath.wav"), load_sound("FDS_rushjet1_-_fdx.wav"), load_sound("FDS_SriK_-_F%!&_Dis_S#!%.wav"), load_sound("miku-joker.wav"), load_sound("MMC5_moviemovies1-Rubicon.wav"), load_sound( "N163_Jayster_-_TMNT_Tournament_Fighters_Scrapyard_Swing.wav"), load_sound("VRC6_Anon-3DGalax.wav"), load_sound( "VRC6_ArchJ-MegaManRemixesArchj - Track 01 Mega Man Elecman.wav" ), load_sound( "VRC6_Ares64-smurfity smurf - Track 01 (Smurfs (GB) Title).wav" ), load_sound( "VRC6_Ares64-smurfity smurf - Track 02 (Smurfs (GB) Volcano).wav" ), load_sound( "VRC6_Ares64-smurfity smurf - Track 03 (Smurfs (GB) River Smurf).wav" ), load_sound( "VRC6_Raijin-Thunderforce III - Haides (Truth) Devil Crash - Main Theme - Track 01 (Thunderforce III Truth).wav" ), load_sound( "VRC6_Raijin-Thunderforce III - Haides (Truth) Devil Crash - Main Theme - Track 02 (Devil Crash Main Theme).wav" ) ] self.background_channel = pygame.mixer.Channel(BGM_CHANNEL_ID) self.background_channel.set_endevent(END_BGM_EVENT) # Initialize Game Groups self.all = pygame.sprite.RenderUpdates() self.background_group = pygame.sprite.RenderUpdates() self.obstacle_group = pygame.sprite.RenderUpdates() # Sprites in this group are rendered after background so that they appear on the top. self.front_group = pygame.sprite.RenderUpdates() self.player_group = pygame.sprite.Group( ) # Not an ui group, just for collision detection. # assign default groups to each sprite class Deafy.containers = self.all, self.front_group, self.player_group Ground.containers = self.all, self.background_group Sky.containers = self.all, self.background_group GroundObstacle.containers = self.all, self.obstacle_group CatOpponent.containers = self.all, self.front_group, self.player_group Bullet.containers = self.all, self.front_group HPBar.containers = self.all, self.background_group Face.containers = self.all, self.background_group dialog.Dialog.containers = self.all, self.background_group self.deafy_player_photos = [] self.cat_player_photos = [] # Initialize camera if ARGS.camera: # HeadPoseEstimator self.hpe = HeadPoseEstimator(CAMERA_INPUT_WIDTH, CAMERA_INPUT_HEIGHT) if ARGS.deafy_camera_index is not None: # Facial landmark detector. self.deafy_fld = FacialLandmarkDetector(CAMERA_INPUT_WIDTH, CAMERA_INPUT_HEIGHT, name="Deafy") self.init_cams(ARGS.deafy_camera_index, DEAFY_CAMERA_DISPLAY_LOCATION) self.deafy_cam_on = True self.deafy_player_face = Face(CAMERA_INPUT_SIZE, FACE_DEAFY_BOTTOMLEFT) self.deafy_queue = Queue() self.deafy_features_q = Queue() else: self.deafy_fld = None self.deafy_cam_on = False self.deafy_player_face = None self.deafy_queue = None self.deafy_features_q = None if ARGS.cat_camera_index is not None: # Facial landmark detector. self.cat_fld = FacialLandmarkDetector(CAMERA_INPUT_WIDTH, CAMERA_INPUT_HEIGHT, name="Cat") self.init_cams(ARGS.cat_camera_index, CAT_CAMERA_DISPLAY_LOCATION) self.cat_cam_on = True self.cat_player_face = Face(CAMERA_INPUT_SIZE, FACE_CAT_BOTTOMLEFT) self.cat_queue = Queue() self.cat_features_q = Queue() else: self.cat_fld = None self.cat_cam_on = False self.cat_player_face = None self.cat_queue = None self.cat_features_q = None