def __init__(self, surface) : ''' fuel_image : str - fuel collectable part_images : [str] - part collectables velocity : int - how fast is collectable dropping? state : int - moving? resting? collected? collidables : [Rect] - things to bump into parts_dropped : int - how many parts dropped so far? fuel_dropped : int - how many fuel cells dropped? item_type : int - is current item a part or fuel? ''' BlittableObject.__init__(self, surface) self.fall_velocity = int(Collectables.FALL_VELOCITY * self.scale) self.collidables = None self.next_item = 0 self.velocity = 0 self.falling = True self.items = (('images/rocket_part_2.png', Collectables.SHIP_PART), ('images/rocket_part_3.png', Collectables.SHIP_PART), ('images/rocket_part_4.png', Collectables.SHIP_PART), ('images/Fuel.png', Collectables.FUEL), ('images/Fuel.png', Collectables.FUEL), ('images/Fuel.png', Collectables.FUEL), ('images/Fuel.png', Collectables.FUEL)) self.spawn()
def __init__(self, surface): ''' ship_images : [str] - ship buildup stages built_parts : int - how many ship parts attached? fuel : int - how many fuel cells inserted? velocity : int - how fast is ship moving? max_velocity : int - ship speed limit, adjusted to screen sound : Sound - ship Sound player object launchpad : (int,int) - where to ground ship ''' BlittableObject.__init__(self, surface) self.launchpad = (self.surf_width / 2, self.surf_height) self.max_velocity = int(Ship.MAX_VELOCITY * self.scale) #Must agree with the collectable list!! self.ship_images = ('images/rocket_stage_1.png', 'images/rocket_stage_2.png', 'images/rocket_stage_3.png', 'images/rocket_completed.png', 'images/rocket_fuel_1.png', 'images/rocket_fuel_2.png', 'images/rocket_fuel_3.png', 'images/rocket_fueled.png') self.velocity = 0 self.sound = None self.set_image(self.ship_images[0]) self.rect.midbottom = self.launchpad self.collected_items = 1 self.takeoff_image = self.load_image(Ship.FLAME_IMAGE, self.rect.size) self.takeoff_image_rect = self.takeoff_image.get_rect() self.takeoff_image_rect.topleft = self.rect.bottomleft
def __init__(self, main_screen, surface): ''' Dict used for improved readability of code, especially incase we had wanted more options button_strings : [str...] - text on menu buttons button_options : [function...] - function to run on button click num_buttons : int - number of menu items button_rects : [Rect...] - menu item rectangle boundaries button_text : [Surface...] - Font surface objects for menu items ''' self.button_string_options = { "game_not_running" : ["New Game", "Quit to Desktop"], "game_running" : ["Resume Game", "New Game", "Quit to Desktop"]} self.button_click_options = { "game_not_running" : [main_screen.new_game, main_screen.quit_program], "game_running" :[main_screen.menu_toggle, main_screen.new_game, main_screen.quit_program]} BlittableObject.__init__(self, surface) if main_screen.running: running = "game_running" else: running = "game_not_running" self.button_strings = self.button_string_options[running] self.button_options = self.button_click_options[running] self.num_buttons = len(self.button_options) self.button_rects = None self.button_text = None button_width = int(Menu.BUTTON_SCALE[0] * self.surf_width) button_height = int(Menu.BUTTON_SCALE[1] * self.surf_height) self.set_image(Menu.BUTTON_IMAGE, (button_width, button_height)) self.rect_setup(button_width, button_height)
def __init__(self, canvas, quit_program): BlittableObject.__init__(self, canvas) self.reset() #stores the method to completely quit the game, so Menu can call it when needed self.quit_program = quit_program self.menu_toggle() #set up a store for the state of important keys, this is managed by the update handler in main.py self.key_register={"Left":False,"Up":False,"Right":False,"Shoot":False}
def __init__(self, surface): BlittableObject.__init__(self, surface) self.up_speed = int(Player.UP_SPEED * self.scale) self.side_speed = int(Player.SIDE_SPEED * self.scale) self.down_speed = int(Player.DOWN_SPEED * self.scale) self.set_image(Player.PLAYER_IMAGE) self.rect.bottomleft = (self.surf_width / 2, self.surf_height) self.velocity = [0, self.down_speed] self.image_ref = 0 self.orientation = 0 #Loads all of images initially to allow quick and easy switching during update. self.image_list = [[ self.load_image(Player.PLAYER_IMAGE, self.rect.size), self.load_image(Player.FLYING_PLAYER_IMAGE, self.rect.size) ], [ self.image_flip( self.load_image(Player.PLAYER_IMAGE, self.rect.size), True, False), self.image_flip( self.load_image(Player.FLYING_PLAYER_IMAGE, self.rect.size), True, False) ]] self.hit_image_list = [[ self.load_image(Player.HIT_PLAYER_IMAGE, self.rect.size), self.load_image(Player.HIT_FLYING_PLAYER_IMAGE, self.rect.size) ], [ self.image_flip( self.load_image(Player.HIT_PLAYER_IMAGE, self.rect.size), True, False), self.image_flip( self.load_image( Player.HIT_FLYING_PLAYER_IMAGE, self.rect.size), True, False) ]] self.lives = Player.START_LIVES self.hit_animation_timer = 0
def __init__(self, surface): BlittableObject.__init__(self, surface) self.up_speed = int(Player.UP_SPEED * self.scale) self.side_speed = int(Player.SIDE_SPEED * self.scale) self.down_speed = int(Player.DOWN_SPEED * self.scale) self.set_image(Player.PLAYER_IMAGE) self.rect.bottomleft = (self.surf_width/2, self.surf_height) self.velocity = [0, self.down_speed] self.image_ref = 0 self.orientation = 0 #Loads all of images initially to allow quick and easy switching during update. self.image_list = [[self.load_image(Player.PLAYER_IMAGE, self.rect.size), self.load_image(Player.FLYING_PLAYER_IMAGE, self.rect.size)], [self.image_flip(self.load_image(Player.PLAYER_IMAGE, self.rect.size), True, False), self.image_flip(self.load_image(Player.FLYING_PLAYER_IMAGE, self.rect.size), True, False)]] self.hit_image_list = [[self.load_image(Player.HIT_PLAYER_IMAGE, self.rect.size), self.load_image(Player.HIT_FLYING_PLAYER_IMAGE, self.rect.size)], [self.image_flip(self.load_image(Player.HIT_PLAYER_IMAGE, self.rect.size), True, False), self.image_flip(self.load_image(Player.HIT_FLYING_PLAYER_IMAGE, self.rect.size), True, False)]] self.lives = Player.START_LIVES self.hit_animation_timer = 0
def __init__(self, main_screen, surface): ''' Dict used for improved readability of code, especially incase we had wanted more options button_strings : [str...] - text on menu buttons button_options : [function...] - function to run on button click num_buttons : int - number of menu items button_rects : [Rect...] - menu item rectangle boundaries button_text : [Surface...] - Font surface objects for menu items ''' self.button_string_options = { "game_not_running": ["New Game", "Quit to Desktop"], "game_running": ["Resume Game", "New Game", "Quit to Desktop"] } self.button_click_options = { "game_not_running": [main_screen.new_game, main_screen.quit_program], "game_running": [ main_screen.menu_toggle, main_screen.new_game, main_screen.quit_program ] } BlittableObject.__init__(self, surface) if main_screen.running: running = "game_running" else: running = "game_not_running" self.button_strings = self.button_string_options[running] self.button_options = self.button_click_options[running] self.num_buttons = len(self.button_options) self.button_rects = None self.button_text = None button_width = int(Menu.BUTTON_SCALE[0] * self.surf_width) button_height = int(Menu.BUTTON_SCALE[1] * self.surf_height) self.set_image(Menu.BUTTON_IMAGE, (button_width, button_height)) self.rect_setup(button_width, button_height)
def __init__(self, surface, game_level): BlittableObject.__init__(self, surface) self.set_image(Enemy.IMAGE) self.set_speed(game_level) self.set_pos()
def draw(self) : #blit collectable item to screen if self.next_item <= len(self.items) : BlittableObject.draw(self)
def __init__(self, canvas, x, y): BlittableObject.__init__(self, canvas) size = (int(Platforms.PLATFORM_SIZE[0] * self.surf_width), int(Platforms.PLATFORM_SIZE[1]*self.surf_height)) self.set_image(Platforms.IMAGE, size) self.rect.topleft = (x * self.surf_width, y * self.surf_height)
def draw(self): #blit to screen if not self.rect.bottom < 0: #ship still on screen BlittableObject.draw(self) self.surface.blit(self.takeoff_image, self.takeoff_image_rect)
def __init__(self, canvas, x, y): BlittableObject.__init__(self, canvas) size = (int(Platforms.PLATFORM_SIZE[0] * self.surf_width), int(Platforms.PLATFORM_SIZE[1] * self.surf_height)) self.set_image(Platforms.IMAGE, size) self.rect.topleft = (x * self.surf_width, y * self.surf_height)