def __init__(self, screen, on_next): super(OnWinScene, self).__init__(screen, on_next, './assets/ganar_nivel.ogg') self.loop = False mantillin_sprites = SpriteSheet("mantillin").load_strip( (432, 0, 108, 121.5), 1) hearts_sprites = SpriteSheet("hearts_un").load_strip((0, 0, 51, 48), 6) self.mantillin = sprite.Group([ Particle(mantillin_sprites, (SCREEN_WIDTH / 2 - mantillin_sprites[0].get_width() / 8, SCREEN_HEIGHT / 3 + mantillin_sprites[0].get_height()), 0, 0, 0), Particle( hearts_sprites, (SCREEN_WIDTH / 2 + 1.25 * hearts_sprites[0].get_width(), SCREEN_HEIGHT / 3 + 1.5 * hearts_sprites[0].get_height()), 0, 0, 0) ]) self.text_title = HeadingFont(60).render("YOU WON", True, (3, 169, 244)) self.text_continue = PixelFont(26).render("press enter to continue", True, (255, 255, 255)) self.star = image.load("assets/star.png").convert_alpha()
def __init__(self, parent, start_position=Vector2(0.0, 0.0)): self.width = globals.screen.get_width() self.height = globals.screen.get_height() self.font = pygame.font.SysFont('arial', 12) UIFrame.__init__(self, start_position, self.width, self.height, parent) #WorldObject.__init__(self, start_position, self.screen_size_x, self.screen_size_y, velocity, image_list) #self.pause_menu = PauseMenu(font, self.screen_size_x, self.screen_size_y, screen) # # Make a chat box. # self.chat_box = ChatBox(player_heads_up_display=self) # Load sprite sheets. self.health = 0 self.max_health = 0 crosshair_sheet = SpriteSheet("resources/images/Crosshair Sheet.png") sprite_sheet = SpriteSheet("resources/images/Sprite Sheet1.png") # Load crosshair. self.crosshair = BlitData( crosshair_sheet.imageAt(pygame.Rect(176, 158, 46, 48))) # load health bar info self.hp_overlay = BlitData( sprite_sheet.imageAt(pygame.Rect(652, 373, 290, 90)), (0, 0)) self.hp_bar = BlitData( sprite_sheet.imageAt(pygame.Rect(722, 485, 213, 40)), (64, 22)) self.mana_bar = BlitData( sprite_sheet.imageAt(pygame.Rect(722, 529, 146, 20)), (68, 65), (0, 0, 159, 20)) # set colorkey so black pixels will be transparent # self.image.set_colorkey(BLACK) # set black to transparent # self.image.fill(BLACK) # ammo and weapon data self.ammo_string = "send me text" self.weapon_string = "send me text" self.ammo_string_surface = self.font.render(self.ammo_string, True, [255, 255, 255]) self.weapon_string_surface = self.font.render(self.weapon_string, True, [255, 255, 255]) self.ammo_blit = BlitData(self.ammo_string_surface, (globals.screen.get_width() / 1.16, globals.screen.get_height() / 1.11)) self.weapon_blit = BlitData(self.weapon_string_surface, (globals.screen.get_width() / 1.16, globals.screen.get_height() / 1.066)) # order this list in which one you want blit first. top picture = last in the list. #self.blit_list = [self.hp_overlay, self.hp_bar, self.ammo_blit, self.weapon_blit, self.crosshair] self.blit_list = [ self.hp_overlay, self.hp_bar, self.mana_bar, self.ammo_blit, self.weapon_blit, self.crosshair ]
def run_game(): # Initialize pygame, settings, and screen object. pygame.mixer.pre_init(44100, -16, 2, 2048) pygame.mixer.init() pygame.init() game_settings = GameSettings() screen = pygame.display.set_mode((game_settings.screen_width, game_settings.screen_height)) pygame.display.set_caption("Pac Man Portal") # Open sprite sheet sprite_sheet = SpriteSheet(file_name='images/spritesheet.png') # Make the Play and Scores button. play_button = Button(screen=screen, msg="Play", order=0) score_button = Button(screen=screen, msg="High Scores", order=1) # Open high score file try: high_score_file = open("high_score_file.txt", "r+") except FileNotFoundError: high_score_file = open("high_score_file.txt", "w+") # Open maze layout file maze_file = open('mazelayout.txt', 'r') # Make sound manager sounds = Sounds() # Initialize game stats and scoreboard stats = GameStats(game_settings=game_settings) sb = Scoreboard(screen=screen, game_settings=game_settings, stats=stats, sprite_sheet=sprite_sheet, high_score_file=high_score_file, sounds=sounds) # Initialize pacman pacman = Pacman(screen=screen, game_settings=game_settings, stats=stats, sb=sb, image_list=sprite_sheet.pacman_image, death_anim_list=sprite_sheet.pacman_death_image, sounds=sounds) # Initialize maze maze = Maze(screen=screen, game_settings=game_settings, maze_file=maze_file, sprite_sheet=sprite_sheet, pacman=pacman, sounds=sounds) # Initialize the event handler event_handler = EventHandler(pacman=pacman, play_button=play_button, score_button=score_button, stats=stats, sb=sb, maze=maze, sounds=sounds) # Initialize the display manager display = Display(screen=screen, game_settings=game_settings, stats=stats, sb=sb, sprite_sheet=sprite_sheet, play_button=play_button, score_button=score_button, maze=maze, pacman=pacman, event_handler=event_handler, sounds=sounds) # Start the main loop for the game while True: event_handler.check_events() if stats.game_active: pacman.update(maze=maze, display=display) maze.update_ghosts() maze.update_bullets() maze.update_portals() display.update_screen()
def __init__(self, bullet_image_list): sprite_sheet_1 = SpriteSheet("resources/images/Sprite Sheet1.png") image_list = [ sprite_sheet_1.imageAt(pygame.Rect(732, 316, 58, 30)), sprite_sheet_1.imageAt(pygame.Rect(811, 315, 84, 40)) ] reload_time = 2 accuracy = .1 damage = 10 ammo = 30 max_ammo = 30 delay = .8 bullet_velocity = 1000 width = 58 height = 30 look_left_offset = 16 gun_x_position = -9.0 gun_y_position = -13.0 Gun.__init__(self, bullet_velocity, delay, damage, ammo, max_ammo, reload_time, accuracy, image_list, gun_x_position, gun_y_position, width, height, look_left_offset) ServerPistol.__init__(self) self.bullet_image_list = bullet_image_list
def __init__(self, bullet_image_list): bullet_velocity = 800 sprite_sheet_1 = SpriteSheet("resources/images/Sprite Sheet1.png") image_list = [ sprite_sheet_1.imageAt(pygame.Rect(966, 332, 35, 21)), sprite_sheet_1.imageAt(pygame.Rect(471, 93, 102, 40)) ] gun_x_position = 7.0 gun_y_position = 0.0 delay = 1 damage = 5 ammo = 30 max_ammo = 30 reload_time = 2.0 accuracy = .07 width = 35 height = 21 look_left_offset = -16 Gun.__init__(self, bullet_velocity, delay, damage, ammo, max_ammo, reload_time, accuracy, image_list, gun_x_position, gun_y_position, width, height, look_left_offset) ServerShotgun.__init__(self) self.bullet_image_list = bullet_image_list
def __init__(self): sprites = SpriteSheet("pecha").load_strip((0, 0, 109, 85), 4) super(Pechatron, self).__init__(sprites, (SCREEN_WIDTH / 2, SCREEN_HEIGHT * .2), 0.1) self.movement_vectors = [(1, 0)] self.max_life = 100 self.life = 100
def load_shields(self): sprites = SpriteSheet("shields").load_strip((0, 0, 87, 84), 4) return [ Shield([sprites[i]], (.20 * (i + 1) * SCREEN_WIDTH, SCREEN_HEIGHT * 0.75)) for i in range(len(sprites)) ]
def __init__(self, rect, order): self.surface = None self.rect = rect self.order = int(order) self.sound_pickup = self.sound_pickup = pygame.mixer.Sound( self.__SOUND_PICKUP) self.__frames = SpriteSheet(self.__IMAGE_PATH, (25, 25)).frames self.reset() self.index = Lamp._current_index Lamp._current_index += 1 print "Index %s is order %s " % (self.index, self.order)
def __init__(self, start_position, ready=False): MenuObject.__init__(self, start_position) self.ready = False if not ready else True # Import ready status indicator images. ready_status_indicator_sheet = SpriteSheet( 'resources/images/ready_status_indicators.png') ready_status_image_list = [ ready_status_indicator_sheet.imageAt(pygame.Rect(0, 0, 15, 15)), ready_status_indicator_sheet.imageAt(pygame.Rect(15, 0, 15, 15)) ] self.image_list = ready_status_image_list
def init(): global camera global current_screen global online_game global screen #menu images global button_img_list global join_game_img_list global forward_button_img_list global back_button_img_list global text_field_img_list global ready_button_img_list global small_forward_button_img_list global small_back_button_img_list global close_button_img_list #cycle button contents global map_names #sounds global button_1_sound current_screen = "main menu" screen_size = pygame.display.list_modes()[0] screen = pygame.display.set_mode(screen_size, DOUBLEBUF) #import button images button_sheet = SpriteSheet("resources/images/ButtonSpriteSheet.png") button_img_list = [button_sheet.imageAt(pygame.Rect(475, 306, 80, 19), None)] join_game_img_list = [button_sheet.imageAt(pygame.Rect(497, 281, 33, 10))] forward_button_img_list = [button_sheet.imageAt(pygame.Rect(0, 76, 50, 278), None)] back_button_img_list = [button_sheet.imageAt(pygame.Rect(54, 76, 50, 278), None)] small_forward_button_img_list = [button_sheet.imageAt(pygame.Rect(494, 226, 18, 15)), button_sheet.imageAt(pygame.Rect(494, 243, 18, 15))] small_back_button_img_list = [button_sheet.imageAt(pygame.Rect(516, 242, 18, 15)), button_sheet.imageAt(pygame.Rect(516, 225, 18, 15))] text_field_img_list = [button_sheet.imageAt(pygame.Rect(479, 278, 75, 12), None), button_sheet.imageAt(pygame.Rect(479, 293, 75, 12), None)] ready_button_img_list = [button_sheet.imageAt(pygame.Rect(0, 0, 157, 38), None), button_sheet.imageAt(pygame.Rect(0, 38, 157, 38), None)] close_button_img_list = [button_sheet.imageAt(pygame.Rect(108, 77, 44, 44), None)] #populate cycle_button elements map_names = [Label(euclid.Vector2(0, 0), "Matt World"), Label(euclid.Vector2(0, 0), "Fun Zone"), Label(euclid.Vector2(0, 0), "Snake Juice")] #sounds button_1_sound = pygame.mixer.Sound("resources/sounds/menu_button.wav")
def __init__(self, screen, on_next): super(OnLoseScene, self).__init__(screen, on_next, './assets/muerte.ogg') mantillin_sprites = SpriteSheet("mantillin").load_strip( (540, 0, 108, 121.5), 1) self.mantillin = sprite.Group([ Particle(mantillin_sprites, (SCREEN_WIDTH / 2 - mantillin_sprites[0].get_width() / 8, SCREEN_HEIGHT / 2), 0, 0, 0) ]) self.text_title = HeadingFont(60).render("GAME OVER", True, (233, 30, 99)) self.text_continue = PixelFont(26).render("press enter to continue", True, (255, 255, 255)) self.star = image.load("assets/star.png").convert_alpha()
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 __init__(self, screen): super(StartScene, self).__init__(screen) mantillin_sprites = SpriteSheet("mantillin").load_strip( (0, 0, 108, 121.5), 4) self.text_title = HeadingFont(45).render("UNAL", True, (3, 169, 244)) self.text_subtitle = HeadingFont(60).render("INVADERS", True, (233, 30, 99)) self.text_start = PixelFont(26).render("press enter to start", True, (255, 255, 255)) self.star = pygame.image.load("assets/star.png").convert_alpha() self.mantillin = sprite.Group([ Particle(mantillin_sprites, (SCREEN_WIDTH / 2 - mantillin_sprites[0].get_width() / 8, SCREEN_HEIGHT / 3 + 2 * self.text_subtitle.get_height()), 0, 0, 0) ])
def __init__(self, name, x, y, animation_speed=200): super().__init__() self.sprite_sheet = SpriteSheet(f'{name}.png') self.image = pygame.image.load('cell.png') self.rect = self.image.get_rect() self.position = [x, y] self.feet = pygame.Rect(0, 0, self.rect.width * 0.5, 12) # vie self.health = 100 self.max_health = 100 # animation self.old_position = self.position self.current_animation_index = 0 self.animation_speed = animation_speed self.cooldown = 0 self.speed = 1
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 __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 __init__(self, bullet_image_list): #load image for bigbertha image_list = [] # override gun's image list sprite_sheet_1 = SpriteSheet("resources/images/Sprite Sheet1.png") image_list.append( sprite_sheet_1.imageAt(pygame.Rect(726, 131, 146, 34))) image_list.append( sprite_sheet_1.imageAt(pygame.Rect(726, 187, 146, 34))) bullet_velocity = 1100 delay = .8 damage = 420 ammo = 10 max_ammo = 10 reload_time = 1.5 accuracy = 0.2 Gun.__init__(self, bullet_velocity, delay, damage, ammo, max_ammo, reload_time, accuracy, image_list) ServerGrenadeLauncher.__init__(self) self.bullet_image_list = bullet_image_list
def __init__(self, position): sprites = SpriteSheet("aliens").load_strip((264, 0, 70, 54), 4) super(TennisAlien, self).__init__(sprites, position, 0.25)
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 __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
def run_game(): # Initialize pygame, settings, and screen object. pygame.mixer.pre_init(44100, -16, 2, 2048) pygame.mixer.init() pygame.init() clock = pygame.time.Clock() clock.tick(60) ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption("Alien Invader") # Import sprite sheet sprite_sheet = SpriteSheet(file_name='images/spritesheet.png') # Make the Play and Scores button. play_button = Button(screen=screen, msg="Play", order=0) score_button = Button(screen=screen, msg="High Scores", order=1) # Open high score file try: high_score_file = open("high_score_file.txt", "r+") except FileNotFoundError: high_score_file = open("high_score_file.txt", "w+") # Make sound manager sounds = Sounds() # Create an instance to store game statistics and create a scoreboard. stats = GameStats(ai_settings=ai_settings) sb = Scoreboard(ai_settings=ai_settings, screen=screen, stats=stats, sprite_sheet=sprite_sheet, high_score_file=high_score_file) # Make the game objects. ship = Ship(ai_settings=ai_settings, screen=screen, sprite_sheet=sprite_sheet, stats=stats, sb=sb, sounds=sounds) explosions = Group() barriers = [] fleet = Fleet(ai_settings=ai_settings, screen=screen, sprite_sheet=sprite_sheet, sounds=sounds) bullets = Bullets(ai_settings=ai_settings, screen=screen, sprite_sheet=sprite_sheet, stats=stats, sb=sb, ship=ship, fleet=fleet, barriers=barriers, explosions=explosions, sounds=sounds) # Make the event handler event_handler = EventHandler(ai_settings=ai_settings, play_button=play_button, score_button=score_button, stats=stats, sb=sb, ship=ship, bullets=bullets, fleet=fleet, sounds=sounds) # Make the display manager display = Display(ai_settings=ai_settings, screen=screen, sprite_sheet=sprite_sheet, play_button=play_button, score_button=score_button, stats=stats, sb=sb, ship=ship, bullets=bullets, fleet=fleet, barriers=barriers, explosions=explosions, event_handler=event_handler) # Start the main loop for the game. while True: event_handler.check_events(display=display) if stats.game_active: ship.update() bullets.update_bullets(display=display) fleet.update_aliens(ship=ship, display=display, bullets=bullets) fleet.update_ufos() display.update_screen()
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 __init__(self, position): gun = SpriteSheet('bullets').load_strip((0, 0, 23, 22), 4) super(TennisBullet, self).__init__(gun, position, 10, 5, (-1, 1)) self.life = 10
from settings import (SCREEN_WIDTH, SCREEN_HEIGHT, SPRITE_SCALE) from sprite_sheet import SpriteSheet from player import Player from enemy import Enemy from beam import Beam #사운드 초기화 pygame.mixer.init() pygame.init() screen = pygame.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT]) #스프라이트 로드 #스프라이트는 opengameart.org sheet = SpriteSheet("sprites\\sheet.png", "sprites\\sheet.xml") #배경 서피스 설정 bg = pygame.image.load("sprites\\bg_darkPurple.png") bg_width = bg.get_width() bg_height = bg.get_height() bg_surface = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT)) for y in range(0, SCREEN_HEIGHT, bg_height): for x in range(0, SCREEN_WIDTH, bg_width): bg_surface.blit(bg, (x, y)) #게임 속도 설정을 위한 시계 clock = pygame.time.Clock() #event는 int로 정의되는데, #USEREVENT가 가장 마지막에 위치하므로 +1로 새로운 이벤트 정의
def __init__(self, always_visible=False, x_offset=0, y_offset=0, box_width=None, box_height=None, max_chars=65, player_heads_up_display=None, screen=None): self.screen = screen self.always_visible = always_visible self.max_chars = max_chars self.view_offset = 0 # The part of the text log you're viewing. 0 is the most recent on the bottom. # These values move the ChatBox from it's default position at the bottom left hand corner of the screen. self.x_offset = x_offset self.y_offset = y_offset self.hidden = not self.always_visible # while this is true the ChatBox shouldn't be displayed. self.alpha = 255 self.delaying_to_fade = False self.is_fading = False # while this is true, the ChatBox text is fading to transparency. self.fade_delay = 3 # seconds after the ChatBox is deselected until the text starts to fade. self.fade_time = 2 # seconds that it fades for after the fadeDelay self.last_deselect_time = 0 # time that the fade process started. self.last_fade_start_time = 0 self.selected = False self.fade_proportion = 0 # This will hold the proportion to convert the time to terms of opacity (0-255) self.font = pygame.font.SysFont('arial', 12) self.cursor_blink_time = 1.5 # the cursor will change every half of this number self.last_cursor_blink = 0 self.cursor_is_blinking = False self.cursor_surface = self.font.render("|", True, [255, 255, 255]) self.text_content = [] # list of strings. lower index = older self.input = None # a string of input to send to the textBox. self.surface_content = [ ] # a list of surface slices. lower index = older self.border_offset = 14 # offset text by ten pixels to account for the border of the chatBox self.blit_dict = {} self.alpha_blit_dict = {} temp_sprite_sheet = SpriteSheet("resources/images/Sprite Sheet1.png") self.box_image = temp_sprite_sheet.imageAt(pygame.Rect( 5, 15, 370, 135)) # this image is cursed to never change color. self.unfocused_image = temp_sprite_sheet.imageAt( pygame.Rect(6, 158, 368, 130)) if box_width is not None and box_height is not None: self.box_image = pygame.transform.scale(self.box_image, (box_width, box_height)) self.unfocused_image = pygame.transform.scale( self.box_image, (box_width, box_height)) self.image = self.box_image # everything will be blit onto here. self.shift_is_pressed = False if hasattr(globals, 'online_game'): self.last_message_received = 0 self.get_new_messages_thread = RepeatTask(1, self.get_new_messages) self.get_new_messages_thread.start() self.player_heads_up_display = player_heads_up_display self.last_paused = datetime.now()
def load_sprite_images(self): """ gets images from sprite sheets """ # sprite sheets effectSheet = SpriteSheet("resources/images/Effects Spritesheet.png") explosionSheet = SpriteSheet("resources/images/explosion.png") lunar_pioneer_sheet = SpriteSheet("resources/images/lunar pioneer.png") background_objects_sheet = SpriteSheet( "resources/images/grandfather clock.png") dust_sheet = SpriteSheet("resources/images/Dust Spritesheet.png") #lightning self.lightning_animation = [ effectSheet.imageAt(pygame.Rect(654, 886, 34, 14)), effectSheet.imageAt(pygame.Rect(705, 885, 32, 14)), effectSheet.imageAt(pygame.Rect(750, 872, 62, 40)), effectSheet.imageAt(pygame.Rect(826, 871, 68, 37)), effectSheet.imageAt(pygame.Rect(911, 881, 72, 29)) ] #putting explosion into big bertha berthaImage.append(explosionSheet.imageAt(pygame.Rect(22, 115, 72, 63))) berthaImage.append( explosionSheet.imageAt(pygame.Rect(110, 108, 99, 81))) berthaImage.append( explosionSheet.imageAt(pygame.Rect(384, 116, 103, 88))) berthaImage.append( explosionSheet.imageAt(pygame.Rect(509, 27, 110, 80))) berthaImage.append(explosionSheet.imageAt(pygame.Rect(650, 29, 84, 72))) #lunar pioneer images self.lunar_pioneer_images = [ lunar_pioneer_sheet.imageAt(pygame.Rect(35, 25, 20, 20)), lunar_pioneer_sheet.imageAt(pygame.Rect(101, 26, 20, 20)) ] #grandfather clock images self.grandfather_clock = [ background_objects_sheet.imageAt(pygame.Rect(7, 12, 18, 71)), background_objects_sheet.imageAt(pygame.Rect(39, 12, 18, 71)), background_objects_sheet.imageAt(pygame.Rect(71, 12, 18, 71)), background_objects_sheet.imageAt(pygame.Rect(39, 12, 18, 71)) ] #spawn images self.spawn_animation = [ effectSheet.imageAt(pygame.Rect(291, 695, 2, 217)), effectSheet.imageAt(pygame.Rect(281, 695, 2, 217)), effectSheet.imageAt(pygame.Rect(270, 695, 2, 217)), effectSheet.imageAt(pygame.Rect(270, 695, 2, 217)), effectSheet.imageAt(pygame.Rect(260, 695, 4, 217)), effectSheet.imageAt(pygame.Rect(242, 695, 12, 216)), effectSheet.imageAt(pygame.Rect(215, 695, 22, 217)), effectSheet.imageAt(pygame.Rect(180, 695, 30, 217)), effectSheet.imageAt(pygame.Rect(148, 695, 22, 217)), effectSheet.imageAt(pygame.Rect(108, 695, 30, 217)), effectSheet.imageAt(pygame.Rect(53, 695, 48, 217)), effectSheet.imageAt(pygame.Rect(4, 695, 46, 217)) ] self.spawn_animation = normalize_rects(self.spawn_animation) #dust cloud #dust_sheet.imageAt(pygame.Rect(544, 250, 82, 17)) # this image is just broken for no reason. self.dust_cloud = [ dust_sheet.imageAt(pygame.Rect(156, 28, 150, 41)), dust_sheet.imageAt(pygame.Rect(351, 20, 189, 58)), dust_sheet.imageAt(pygame.Rect(2, 130, 196, 61)), dust_sheet.imageAt(pygame.Rect(257, 141, 194, 57)), dust_sheet.imageAt(pygame.Rect(3, 230, 198, 57)), dust_sheet.imageAt(pygame.Rect(257, 253, 197, 57)) ]
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
def __init__(self): sprites = SpriteSheet('bonus').load_strip((0, 0, 93, 49), 2) super(Bonus, self).__init__(sprites, (-93, SCREEN_HEIGHT * .1), 5, 5, 0)
def __init__(self, position): gun = SpriteSheet('bullets').load_strip((102, 0, 24, 22), 6) super(BonusBullet, self).__init__(gun, position, 10, 0, (0, 1))
def __init__(self): sprites = SpriteSheet("ship").load_strip((0, 0, 87, 100), 4) super(Character, self).__init__(sprites, (SCREEN_WIDTH / 2, SCREEN_HEIGHT * 0.9), 1, 25, 5)