def __init__(self, world_map, multiplayer): World.__init__(self, world_map, multiplayer) self._create_sprites() self.brick_energy() self.set_bounds_energy() self.set_dynamics_energy() self._set_walls()
def __init__ (self, scheduler, evthandler, sfc, player = None): self.player = player World.__init__(self, scheduler, evthandler) evthandler.add_event_handlers({pg.JOYBUTTONDOWN: self._joycb}) evthandler.add_key_handlers([ (conf.KEYS_BACK, lambda *args: conf.GAME.quit_world(), eh.MODE_ONDOWN), (conf.KEYS_QUIT, lambda *args: conf.GAME.quit_world(2), eh.MODE_ONDOWN) ]) self.graphics.add(gm.Graphic(sfc), gm.Colour((0, 0, 0, 180), ((0, 0), conf.RES), -1))
def __init__(self, world_map, multiplayer): self.player_sprites = {'1': None, '2': None} self.enemy_sprites = set() self.wall_rects = [] self.unbreakable_wall_rects = [] self.bullets = set() self.game_over = False World.__init__(self, world_map, multiplayer) self._create_sprites() self._set_walls() self.update_aim_lines()
def __init__( self, scheduler, evthandler ): World.__init__( self, scheduler, evthandler ) self.num_joysticks = 0 #Create a background self.graphics.add(gm.Graphic('background.png', layer = 1)) #Register event listeners evthandler.add_key_handlers([ (conf.KEYS_NEXT, self._load_joysticks, eh.MODE_ONDOWN), (conf.KEYS_BACK, lambda *args: conf.GAME.quit_world(), eh.MODE_ONDOWN) ]) evthandler.add_event_handlers( { pygame.JOYBUTTONDOWN: self._handle_joystick } )
def __init__ (self, scheduler, evthandler, joys): World.__init__(self, scheduler, evthandler) self._dot_sfc = [conf.GAME.img('dot{0}.png'.format( i ), (conf.DOT_RADIUS, conf.DOT_RADIUS)) for i in xrange( 4 )] self.t = 0 self.scheduler.add_timeout(self._update_paths, seconds = conf.PATH_UPDATE_TIME) self.scheduler.interp(lambda t: t, self.update_t) self.graphics.add(gm.Graphic('background.png', layer = conf.GRAPHICS_LAYERS['bg'])) # controls # {type: {id: (action, action_mode)}} self.controls = controls = {} for action, evts in conf.CONTROLS.iteritems(): if isinstance(evts[0], basestring): evts = (evts,) for mode, (e_type, e_id) in enumerate(evts): controls.setdefault(e_type, {})[e_id] = (action, mode) evthandler.add_event_handlers(dict.fromkeys(controls, self._joycb)) evthandler.add_key_handlers([ (conf.KEYS_BACK, self.pause, eh.MODE_ONDOWN) ]) # sun self.phys = Physics() p_data = conf.PLAYER_PLANET p_radius = p_data['radius'] p_sun_dist = p_data['sun dist'] pad = p_data['edge dist'] + p_sun_dist + p_radius s_w, s_h = conf.RES assert 2 * pad <= s_w and 2 * pad <= s_h sun = Sun(conf.SUN_DENSITY, conf.SUN_RADIUS, (uniform(pad, s_w - pad), uniform(pad, s_h - pad))) # npps (non player planets) # inner planets planets = [] planet_data = conf.INNER_PLANET planet_number= planet_data['number'] planet_max_radius = planet_data['max radius'] planet_min_radius = planet_data['min radius'] if planet_number > 0: planet_dist = planet_data['min sun dist'] planet_dist_inc = (planet_data['max sun dist'] - planet_dist)/ planet_number for i in xrange(planet_number): planets.append(Planet(self, planet_data['density'], uniform(planet_min_radius,planet_max_radius), sun, planet_dist + planet_dist_inc * i, uniform(0,6.29))) # outer planets planet_data = conf.OUTER_PLANET planet_number= planet_data['number'] planet_max_radius = planet_data['max radius'] planet_min_radius = planet_data['min radius'] if planet_number > 0: planet_dist = planet_data['min sun dist'] planet_dist_inc = (planet_data['max sun dist'] - planet_dist)/ planet_number for i in xrange(planet_number): planets.append(Planet(self, planet_data['density'], uniform(planet_min_radius,planet_max_radius), sun, planet_dist + planet_dist_inc * i, uniform(0,6.29))) # players angle = uniform(0, 2 * pi) d_angle = 2 * pi / len(joys) joy_ids = [j.get_id() for j in joys] self.players = [] for i in xrange(4): if i in joy_ids: self.players.append(Player(i, self, p_data['density'], p_radius, sun, p_sun_dist, angle)) angle += d_angle else: self.players.append(None) # extra planets planets += [p for p in self.players if p is not None] asteroids = [] self.phys.gravity_sources = [sun] + planets self.entities = self.phys.gravity_sources + asteroids self.graphics.add(*(e.graphic for e in self.entities))
def __init__(self, game, config = None): self.configfile = os.path.join("levels", "demo", "demo.lvl") World.__init__(self, game, config)