def enter(self, enter_params=None): # Get needed settings self.window_width = Settings.instance().settings['window_width'] self.window_height = Settings.instance().settings['window_height'] # Load fonts load_font('fonts\\font.ttf', 'medium', self.cached_fonts, 48) load_font('fonts\\font.ttf', 'title', self.cached_fonts, 256) # Load sounds load_sound('sounds\\enter_menu_item.wav', 'enter_menu_item', self.cached_sounds) # Play music play_music(0, self.music) self.menu_items = { '1_player': MenuItem((self.window_width * 2 // 5, self.window_height * 4 // 8), '>> 1 Player', self.cached_fonts['medium']), '2_players': MenuItem((self.window_width * 2 // 5, self.window_height * 5 // 8), '>> 2 Players', self.cached_fonts['medium']), 'demo': MenuItem((self.window_width * 2 // 5, self.window_height * 6 // 8), '>> Demo', self.cached_fonts['medium']), 'exit': MenuItem((self.window_width * 2 // 5, self.window_height * 7 // 8), '>> Exit', self.cached_fonts['medium']) }
def _load_sounds(self): """Load the sound effects.""" logging.info('Loading sounds') self.sounds = { 'move': helpers.load_sound('move.ogg', volume=settings.SOUNDS_VOLUME), 'rotate': helpers.load_sound('rotate.ogg', volume=settings.SOUNDS_VOLUME), 'place': helpers.load_sound('place.ogg', volume=settings.SOUNDS_VOLUME), 'lines_completed': helpers.load_sound('lines_completed.ogg', volume=settings.SOUNDS_VOLUME), 'new_level': helpers.load_sound('new_level.ogg', volume=settings.SOUNDS_VOLUME) }
def __init__(self, x, y): self.x = x + 8 self.y = y + 8 self.player_down = helpers.load_image('player_down.png', -1) self.player_up = helpers.load_image('player_up.png', -1) self.player_right = helpers.load_image('player_right.png', -1) self.player_left = helpers.load_image('player_left.png', -1) self.image = self.player_down if self.image == self.player_down: self.image1 = 1 else: self.image1 = 2 self.rect = self.image.get_rect(topleft=(self.x, self.y)) self.speed = options.player_speed self.health = 100 self.weapons_slot = [] self.pistol = weapons.Pistol(0, 0) self.pistol_rof = 60.00 / self.pistol.shoot_rate * options.fps self.can_shoot_pistol = 0 self.rifle = weapons.Rifle(0, 0) self.rifle_rof = 60.00 / self.rifle.shoot_rate * options.fps self.can_shoot_rifle = 0 self.machine_gun = weapons.MachineGun(0, 0) self.machine_gun_rof = 60.00 / self.machine_gun.shoot_rate * options.fps self.can_shoot_machine_gun = 0 self.flame_thrower = weapons.FlameThrower(0, 0) self.flame_thrower_rof = 60.00 / self.flame_thrower.shoot_rate * options.fps self.can_shoot_flame_thrower = 0 self.bullets = [] self.blinking = 0 self.recover_time = 15 self.shoot1 = helpers.load_sound('hgun.wav') self.shoot2 = helpers.load_sound('hgun.wav') self.shoot3 = helpers.load_sound('mgun.wav') self.shoot4 = helpers.load_sound('rl1.wav') x = file('data/options', 'rb') y = pickle.load(x) z = pickle.load(x) self.sounds = int(pickle.load(x))
def __init__(self, width=800, height=600): pygame.init() self.width = width self.height = height self.screen = pygame.display.set_mode((self.width, self.height)) self.airhorn_sprites = pygame.sprite.Group() self.nope_sprites = pygame.sprite.Group() self.clock = pygame.time.Clock() self.airhorn_sound = load_sound('airhorn.wav') self.derf_sound = load_sound('derf.wav') self.font = pygame.font.Font(None, 36) self.state = Gamestate()
def _load_sounds(self): """Load the sound effects.""" logging.info('Loading sounds') self.sounds = { 'explosions': [ helpers.load_sound('explosion_1.wav', volume=settings.SOUNDS_VOLUME), helpers.load_sound('explosion_2.wav', volume=settings.SOUNDS_VOLUME) ], 'win': [ helpers.load_sound('win_1.ogg', volume=settings.SOUNDS_VOLUME), helpers.load_sound('win_2.ogg', volume=settings.SOUNDS_VOLUME) ] }
def __init__(self, x, y): self.tank_down = helpers.load_image('tank_down.png', -1) self.tank_up = helpers.load_image('tank_up.png', -1) self.tank_left = helpers.load_image('tank_left.png', -1) self.tank_right = helpers.load_image('tank_right.png', -1) self.image = self.tank_down self.rect = self.image.get_rect(topleft=(x + 8, y + 8)) self.health = 100 self.name = 'tank' self.attack_area = 0 self.attack_area_rect = 0 self.bullets = [] self.damage = 100 self.player_speed = options.player_speed self.speed = 3 self.direction = random.randint(1, 4) self.move_type = 'random' x = file('data/options', 'rb') y = pickle.load(x) z = pickle.load(x) self.sounds = int(pickle.load(x)) self.shoot1 = helpers.load_sound('hgun.wav') self.weapon = 1
def __init__(self): self.volume = 1 self.sounds = {} self.current_track = '' for sound in SOUNDS: self.sounds[sound] = helpers.load_sound(sound + '.wav')
def enter(self, enter_params=None): # Get needed settings self.window_width = Settings.instance().settings['window_width'] self.window_height = Settings.instance().settings['window_height'] self.win_score = Settings.instance().settings['win_score'] # Save enter parameters self.num_players = enter_params['num_players'] self.input_device = enter_params['input_device'] self.difficulty = enter_params.get('difficulty') # Load font load_font('fonts\\font.ttf', 'small_medium', self.cached_fonts, 32) load_font('fonts\\font.ttf', 'medium', self.cached_fonts, 48) load_sound('sounds\\enter_menu_item.wav', 'enter_menu_item', self.cached_sounds) self.menu_items = { 'back': MenuItem((self.window_width // 20, self.window_height * 14 // 15), '< Back', self.cached_fonts['medium']) }
def enter(self, enter_parmas): # Get needed settings self.window_width = Settings.instance().settings['window_width'] self.window_height = Settings.instance().settings['window_height'] # Save enter parameters self.num_players = enter_parmas['num_players'] # Load fonts load_font('fonts\\font.ttf', 'medium', self.cached_fonts, 48) load_font('fonts\\font.ttf', 'large', self.cached_fonts, 64) # Load sounds load_sound('sounds\\enter_menu_item.wav', 'enter_menu_item', self.cached_sounds) self.menu_items = { 'mouse': MenuItem((self.window_width * 2 // 5, self.window_height * 5 // 8), '>> Mouse', self.cached_fonts['medium']), 'keyboard': MenuItem((self.window_width * 2 // 5, self.window_height * 6 // 8), '>> Keyboard', self.cached_fonts['medium']), 'back': MenuItem((self.window_width // 20, self.window_height * 14 // 15), '< Back', self.cached_fonts['medium']) }
def enter(self, enter_parmas): # Get needed settings self.window_width = Settings.instance().settings['window_width'] self.window_height = Settings.instance().settings['window_height'] # Save enter parameters self.num_players = enter_parmas['num_players'] self.input_device = enter_parmas['input_device'] # Load fonts load_font('fonts\\font.ttf', 'medium', self.cached_fonts, 48) load_font('fonts\\font.ttf', 'large', self.cached_fonts, 64) # Load sounds load_sound('sounds\\enter_menu_item.wav', 'enter_menu_item', self.cached_sounds) self.menu_items = { 'beginner': MenuItem((self.window_width * 2 // 5, self.window_height * 3 // 8), '>> Beginner', self.cached_fonts['medium']), 'intermediate': MenuItem((self.window_width * 2 // 5, self.window_height * 4 // 8), '>> Intermediate', self.cached_fonts['medium']), 'expert': MenuItem((self.window_width * 2 // 5, self.window_height * 5 // 8), '>> Expert', self.cached_fonts['medium']), 'back': MenuItem((self.window_width // 20, self.window_height * 14 // 15), '< Back', self.cached_fonts['medium']), }
def enter(self, enter_params=None): # Get needed settings self.window_width = Settings.instance().settings['window_width'] self.window_height = Settings.instance().settings['window_height'] # Load fonts load_font('fonts\\font.ttf', 'medium', self.cached_fonts, 48) load_font('fonts\\font.ttf', 'title', self.cached_fonts, 256) # Load sounds load_sound('sounds\\enter_menu_item.wav', 'enter_menu_item', self.cached_sounds) self.menu_items = { 'resume': MenuItem((self.window_width // 3, self.window_height * 5 // 8), '>> Resume Game', self.cached_fonts['medium']), 'new_game': MenuItem((self.window_width // 3, self.window_height * 6 // 8), '>> New Game', self.cached_fonts['medium']), 'exit': MenuItem((self.window_width // 3, self.window_height * 7 // 8), '>> Exit', self.cached_fonts['medium']) }
def __init__(self,x,y,direction): self.image=helpers.load_image('black bullet.png',-1) self.rect=self.image.get_rect(topleft=(x+5,y+10)) self.sound=helpers.load_sound('hgun.wav') self.direction=direction self.player_speed=options.player_speed self.speed=self.player_speed + 5 self.show=1 self.damage=3
def __init__(self, x, y): self.player = player.Player(x, y) self.enemy_down = helpers.load_image('enemyb_down.png', -1) self.enemy_up = helpers.load_image('enemyb_down.png', -1) self.enemy_left = helpers.load_image('enemyb_down.png', -1) self.enemy_right = helpers.load_image('enemyb_down.png', -1) self.image = self.enemy_down self.rect = self.image.get_rect(topleft=(x + 8, y + 8)) self.health = 50 self.name = 'blue' self.attack_area = 0 self.attack_area_rect = 0 self.weapons_slot = [] self.pistol = weapons.Pistol(0, 0) self.pistol_rof = 60.00 / self.pistol.shoot_rate * options.fps self.can_shoot_pistol = 1 self.bullets = [] self.damage = 15 self.player_speed = options.player_speed self.speed = 3 self.direction = random.randint(1, 4) self.move_type = 'random' x = file('data/options', 'rb') y = pickle.load(x) z = pickle.load(x) self.sounds = int(pickle.load(x)) self.shoot1 = helpers.load_sound('hgun.wav') self.weapon = 1
def enter(self, enter_params=None): # Get needed settings self.window_width = Settings.instance().settings['window_width'] self.window_height = Settings.instance().settings['window_height'] self.paddle_width = Settings.instance().settings['paddle_width'] self.paddle_height = Settings.instance().settings['paddle_height'] self.paddle_tolerance_beginner = Settings.instance( ).settings['paddle_tolerance_beginner'] self.paddle_tolerance_Intermediate = Settings.instance( ).settings['paddle_tolerance_Intermediate'] self.paddle_tolerance_expert = Settings.instance( ).settings['paddle_tolerance_expert'] self.ball_speed_increase_beginner = Settings.instance( ).settings['ball_speed_increase_beginner'] self.ball_speed_increase_intermediate = Settings.instance( ).settings['ball_speed_increase_intermediate'] self.ball_speed_increase_expert = Settings.instance( ).settings['ball_speed_increase_expert'] self.paddle_special_hit_threshold = Settings.instance( ).settings['paddle_special_hit_threshold'] self.paddle_special_hit_increase = Settings.instance( ).settings['paddle_special_hit_increase'] self.net_segments = Settings.instance().settings['net_segments'] self.net_segments_gap = Settings.instance( ).settings['net_segments_gap'] self.net_segments_height = Settings.instance( ).settings['net_segments_height'] self.net_segment_width = Settings.instance( ).settings['net_segment_width'] self.win_score = Settings.instance().settings['win_score'] # Save enter parameters self.num_players = enter_params.get('num_players') self.input_device = enter_params.get('input_device') self.difficulty = enter_params.get('difficulty') self.is_demo = enter_params.get('is_demo') if self.is_demo is None: self.is_demo = False # Load Fonts load_font('fonts\\font.ttf', 'small_medium', self.cached_fonts, 32) load_font('fonts\\font.ttf', 'huge', self.cached_fonts, 128) # Load Sounds load_sound('sounds\\paddle_hit.wav', 'paddle_hit', self.cached_sounds) load_sound('sounds\\score.wav', 'score', self.cached_sounds) load_sound('sounds\\wall_hit.wav', 'wall_hit', self.cached_sounds) load_sound('sounds\\paddle_special_hit.wav', 'paddle_special_hit', self.cached_sounds) # Play music play_music(1, self.music) # Create Entites self.ball = Ball(self.window_width // 2, self.window_height // 2, Settings.instance().settings['ball_radius']) self.player1 = Paddle(self.paddle_width // 2, self.paddle_height // 2 + 100, self.paddle_width, self.paddle_height) self.player2 = Paddle( self.window_width - self.paddle_width // 2, self.window_height - self.paddle_height // 2 - 100, self.paddle_width, self.paddle_height) self.ball.set_initial_speed(self.serving_player == 2) # Set tolerance according to difficulty tolerance = random.randint(self.paddle_tolerance_beginner[0], self.paddle_tolerance_beginner[1]) / 100 self.speed_increase = self.ball_speed_increase_beginner if self.difficulty == 'intermediate': tolerance = random.randint( self.paddle_tolerance_Intermediate[0], self.paddle_tolerance_Intermediate[1]) / 100 self.speed_increase = self.ball_speed_increase_intermediate if self.difficulty == 'expert': tolerance = random.randint(self.paddle_tolerance_expert[0], self.paddle_tolerance_expert[1]) / 100 self.speed_increase = self.ball_speed_increase_expert self.player2.set_tolerance(tolerance) # Load particle system self.particle_system = ParticleSystem( self.ball.get_position()[0], self.ball.get_position()[1], ParticleShape.SQUARE, Settings.instance().settings['particle_size'], Settings.instance().settings['particle_birth_rate'], Settings.instance().settings['particle_speed'], Settings.instance().settings['particle_death_age']) gradient = Gradient( Settings.instance().settings['particle_gradient_color_01'], Settings.instance().settings['particle_gradient_last_color']) gradient.add_color( Settings.instance().settings['particle_gradient_color_02'], Settings.instance().settings['particle_gradient_color_02_pos']) gradient.add_color( Settings.instance().settings['particle_gradient_color_03'], Settings.instance().settings['particle_gradient_color_03_pos']) gradient.add_color( Settings.instance().settings['particle_gradient_color_04'], Settings.instance().settings['particle_gradient_color_04_pos']) self.particle_system.set_gradient(gradient) self.particle_system.set_death_variance( Settings.instance().settings['particle_death_variant']) self.particle_system.set_speed_variance( Settings.instance().settings['particle_speed_variant'])
config = configparser.ConfigParser() config.read("settings.ini") hero_speed = config.getfloat('PLAYER', 'hero_speed') jump_force = config.getfloat('PLAYER', 'jump_force') dash_speed = config.getint('PLAYER', 'dash_speed') wall_jump = json.loads(config.get("PLAYER", "wall_jump")) down_timer = config.getfloat("CAMERA", "down_timer") width, height = json.loads(config.get("MAIN", "res")) h_width, h_height = json.loads(config.get("PLAYER", "size")) fps = config.getint("MAIN", "fps") # Загрузка звуков walk_sound = load_sound("data/sounds/walk.wav") walk_sound.set_volume(0.5) walk_time = get_length(walk_sound) jump_sound = load_sound("data/sounds/jump.wav") jump_sound.set_volume(0.4) dash_sound = load_sound("data/sounds/dash.wav") dash_sound.set_volume(0.4) sliding_sound = load_sound("data/sounds/wall_slide.wav") sliding_sound.set_volume(0.4) slide_time = get_length(sliding_sound) idle_right = [ load_image('data/PassiveReaper_Right/PassiveIdleReaper-Sheet.png', h_width, h_height), load_image('data/PassiveReaper_Right/PassiveIdleReaper-Sheet2.png', h_width, h_height),
def main(): # the main function pygame.init() pygame.font.init() pygame.mixer.init() # not sure why i have to do this shit screen = pygame.display.set_mode((800, 480)) pygame.display.set_caption('pig fever') pygame.mouse.set_visible(0) # create the background bg, bg_rect = load_image('grass.jpg') # display the background while setup finishes screen.blit(bg, bg_rect) # blit the background pygame.display.flip( ) # updates the areas that are changed using double buffer displays # objective text font = pygame.font.SysFont('Arial', 50) intro_text = font.render("Kill All the Carrots!", 1, (0, 0, 0)) intro_text_pos = intro_text.get_rect() intro_text_pos.centerx = bg_rect.centerx bg.blit(intro_text, intro_text_pos) # # text for finishing the game font = pygame.font.SysFont('Arial', 70) end_text = font.render("PIG IS FED! GOOD JOB!", 1, (150, 0, 0)) end_text_pos = end_text.get_rect() end_text_pos.centerx = bg_rect.centerx end_text_pos.bottom = bg_rect.bottom # prep game objects eating_sound = load_sound('owmylegs.wav') pig = Pig() carrot_objects = [] for c in range(10): c = Carrot() carrot_objects.append(c) # Place all the carrot sprites in a container sprite pig_sprites = pygame.sprite.RenderPlain((pig)) carrot_sprites = pygame.sprite.RenderPlain((carrot_objects)) clock = pygame.time.Clock() # created to control the game's framerate # main loop while 1: clock.tick(60) # handle events for event in pygame.event.get(): if event.type == QUIT: return elif event.type == KEYDOWN and event.key == K_ESCAPE: return elif event.type == MOUSEBUTTONDOWN: collisions = pig.rect.collidelistall(carrot_objects) if len(collisions) > 0: for c in collisions: carrot_objects[c].eaten() eating_sound.play() carrot_objects[c].kill() elif event.type == MOUSEBUTTONUP: pig.uneat() if len(carrot_sprites) == 0: bg.blit(end_text, end_text_pos) pig_sprites.update() carrot_sprites.update() # call update method on all sprites screen.blit( bg, bg_rect) # calls bg image to erase everything from the last frame pig_sprites.draw(screen) carrot_sprites.draw(screen) # draws the sprites pygame.display.flip() # Makes everything visible at once
def __init__(self): """ create the class, and create local variables based on the base variables that can be modified. """ super().__init__() self.logger = logging.getLogger('mineEye.hero.Hero') self.world = None self.name = 'Hero' self.base_hp = 250 self.base_speed = 10 self.jump_height = 15 self.double_jump_height = 15 self.max_bombs = 3 # number of bombs in clip self.bomb_damage = 100 self.bomb_range = 128 self.bomb_refill_requirement = 4 # number of kills before being given another bomb self.melee_damage_multiplier = 1 self.ranged_damage_multiplier = 1 self.melee_range_multiplier = 1 self.can_doublejump = False self.take_falldamage = True self.speed_boost_on_kill = False self.speed_boost_length = 60 # ticks self.speed_boost_counter = 0 self.multiple_weapon_drops = False self.weapon_pickup_range = 48 self.melee_weapon = None self.ranged_weapon = None # Mutable variables that can change but may need to be reset self.hp = self.base_hp self.actual_speed = self.base_speed self.bombs = self.max_bombs self.bomb_refill_counter = 0 self.upgrades = [] # Flags to help control motion self.start_jump = False self.start_double_jump = False self.jumping = False self.double_jumping = False self.jump_count = 0 self.moving_left = False self.moving_right = False self.last_motion = 'right' # Sprite and PygAnim stuff self.animation_obj = {} self.conductor = None self.rect = pygame.Rect(0, 0, 48, 48) self.rect.center = (settings['WIDTH']/2, settings['HEIGHT']/2) self.create_animation_dict() # Sound stuff self.melee_swing_sound = h.load_sound('melee-attack.wav')