def __init__(self, no_ui=False, controller='player', force_fire=False, throttle_frames=True): # initialize pygame pygame.init() self.no_ui = no_ui self.controller = controller # 'player' or 'agent' self.force_fire = force_fire self.throttle_frames = throttle_frames # for grid targeting self.grid_width = round( (self.WIDTH - Explosion.get_max_radius(self.WIDTH) / 2) / Explosion.get_max_radius(self.WIDTH)) self.grid_height = round((self.HEIGHT - self.BASE_HEIGHT * 1.4) / Explosion.get_max_radius(self.WIDTH)) if self.no_ui: self.ctx = pygame.Surface((self.WIDTH, self.HEIGHT)) else: pygame.display.set_caption(self.WINDOW_TITLE) pygame.mouse.set_cursor(*pygame.cursors.diamond) self.ctx = pygame.display.set_mode((self.WIDTH, self.HEIGHT)) half = self.WIDTH / 18 self.target_xs = [n * self.WIDTH / 9 - half for n in range(1, 10)] self.points = 0 self.round_over = True self.steps = 0 self.interceptors = [] self.missiles = [] self.explosions = [] self.cities = [ City(self.ctx, self.target_xs[n - 1], self.HEIGHT - self.GROUND_HEIGHT) for n in (2, 3, 4, 6, 7, 8) ] self.bases = [ Base(self.ctx, self.target_xs[n - 1], self.HEIGHT - self.GROUND_HEIGHT) for n in (1, 5, 9) ] self.keys = [False for _ in range(3)]
def grid_2_pixel(self, x_idx, y_idx): r = Explosion.get_max_radius(self.WIDTH) return r / 2 + (x_idx * r), r / 2 + (y_idx * r)