def __init__(self, res, universe, pos, angle=0, vel=(0, 0), inventory={ 'r': 0, 'g': 0, 'b': 0 }): super().__init__(universe, pos, vel, radius=self.RADIUS, on_hit=self.hit) self.res = res self.sprites = { k: res.image['ship'].subsurface(self.RECTS[k]) for k in self.RECTS } self.initial_pos = vfloat(pos) # for teleporting home self.initial_vel = vfloat(vel) # for teleporting home self.angle = angle self.thrusting = False self.connected_planet = None # The planet we're within range of universe.sprites.append(self) universe.camera_targets.append(self) universe.player = self self.inventory = dict(inventory) self.selected_slot = None self.fire_countdown = 0 self.firing = False
def __init__(self, universe, pos, vel=(0.0, 0.0), radius=0, on_hit=None): self.universe = universe self.pos = vfloat(pos) self.vel = vfloat(vel) self.acc = np.array((0.0, 0.0)) self.on_hit = on_hit self.connected_planet = None self.radius = radius universe.things.append(self)
def __init__(self, ui, pos, offset, sheet, sounds, off_full, off_empty, on_full, on_empty, early_cut=0, value=0.5, responsive=True, visible=False): super().__init__(ui, pos, sheet, sounds, off_full, off_empty, on_full, on_empty, early_cut, value, responsive, visible, sticky=False) self.offset = vfloat(offset)
def draw(self, screen, camera): rotated_sprite = pygame.transform.rotozoom( self.sheet.subsurface(self.rect), self.theta * 180 / np.pi, camera.zoom) pos = vfloor( camera.cam(self.pos) - vfloat(rotated_sprite.get_size()) / 2) return screen.blit(rotated_sprite, pos)
def tick(self, dt): self.thrusting = self.thrusting and pygame.mouse.get_pressed()[0] self.firing = self.firing and pygame.mouse.get_pressed()[2] # Point at the mouse delta_to_mouse = self.universe.uncam(vfloat( pygame.mouse.get_pos())) - self.pos self.angle = np.arctan2(delta_to_mouse[1], delta_to_mouse[0]) self.fire(dt) super().tick(dt) self.warp_home()
def draw(self, screen, camera): axis = np.array((np.cos(self.angle), np.sin(self.angle))) * camera.zoom pos = camera.cam(self.pos) postfix = "_glow" if self.thrusting else "" rotated_U = pygame.transform.rotozoom(self.sprites["U" + postfix], -self.angle * (180 / np.pi) - 90, camera.zoom) scaled_orb_small = pygame.transform.rotozoom( self.sprites["orb_small" + postfix], 0, camera.zoom) scaled_orb_large = pygame.transform.rotozoom( self.sprites["orb_large" + postfix], 0, camera.zoom) r = screen.blit( scaled_orb_small, vfloor(pos - vfloat(scaled_orb_small.get_size()) / 2 - axis * 28)) r = r.union( screen.blit( scaled_orb_large, vfloor(pos - vfloat(scaled_orb_large.get_size()) / 2 - axis * 3))) return r.union( screen.blit(rotated_U, vfloor(pos - vfloat(rotated_U.get_size()) / 2)))
def __init__(self, res, planet_factory): self.res = res self.planet_factory = planet_factory self.background = res.image['background_base'].copy() self.shadow = res.image['shadow_outline'] self.scaled_shadow = self.shadow self.screen_rect = self.background.get_rect( ) # if wrapping_rect is null, use the background rect self.clear() self.player = None self.ui_sheet = res.image['ui'] self.zoom = 1 self.camera = np.array((0.0, 0.0)) self.camera_urgency = 1 self.target_zoom = 1 self.target_reached = False self.target_camera = np.array((0.0, 0.0)) self.rect_offset = vfloat( self.screen_rect.size ) / 2 # To move the origin from the top left to the center of the screen self.skip_next_tick = False
def __init__(self, universe, pos, biomemap, colormap, city_spritesheet, atmosphere, clouds, clouds_night): self.universe = universe if universe: universe.things.append(self) universe.sprites.append(self) self.pos = vfloat(pos) self.theta = np.random.uniform(0, 360) self.cloud_theta = np.random.uniform(0, 360) self.omega = np.random.uniform(-1.0, 1.0) * self.ROTATION_SPEED self.cloud_omega = np.random.uniform( -1.0, 1.0) * self.ROTATION_SPEED + self.omega self.scale = 1 self.colormap = colormap self.biomemap = biomemap self.cityscape = Cityscape(city_spritesheet) self.atmosphere = atmosphere self.clouds = clouds self.clouds_night = clouds_night self.day_canvas = pygame.Surface(self.CANVAS_SIZE, SRCALPHA, 32) self.night_canvas = pygame.Surface(self.CANVAS_SIZE, SRCALPHA, 32) self.planet_sprite = biomemap.make_surface() self.parameters = [0, 0, 0, 0] self.update()
def contains(self, pos): rel_pos = vfloor( self.ui.universe.uncam(vfloat(pos)) - self.pos - self.offset) return self.sprite_contains(rel_pos)