def test_rect(): r1 = Rect(Point(0, 0), 1, 1) r2 = Rect(0, 0, 1, 1) r3 = Rect(Point(2, 2), 1, 1) assert r1 == r2 assert not r1.contains(Point(-1, -1)) assert r2.contains(Point(0, 0)) assert r2.contains(Point(1, 1)) assert r1.intersects(r2) assert not r1.intersects(r3)
def testRect(self): r1 = Rect(Point(0, 0), 1, 1) r2 = Rect(0, 0, 1, 1) r3 = Rect(Point(2, 2), 1, 1) self.assertEqual(r1, r2) self.assertTrue(r1 == r2) self.assertFalse(r1.contains(Point(-1, -1))) self.assertTrue(r2.contains(Point(0, 0))) self.assertTrue(r2.contains(Point(1, 1))) self.assertTrue(r1.intersects(r2)) self.assertFalse(r1.intersects(r3))
def __init(self, db, island_id, preview): """ Load the actual island from a file @param preview: flag, map preview mode """ p_x, p_y, width, height = db( "SELECT MIN(x), MIN(y), (1 + MAX(x) - MIN(x)), (1 + MAX(y) - MIN(y)) FROM ground WHERE island_id = ?", island_id - 1001)[0] # rect for quick checking if a tile isn't on this island # NOTE: it contains tiles, that are not on the island! self.rect = Rect(Point(p_x, p_y), width, height) self.ground_map = {} for (x, y, ground_id, action_id, rotation) in db( "SELECT x, y, ground_id, action_id, rotation FROM ground WHERE island_id = ?", island_id - 1001): # Load grounds if not preview: # actual game, need actual tiles ground = Entities.grounds[str( '%d-%s' % (ground_id, action_id))](self.session, x, y) ground.act(rotation) else: ground = MapPreviewTile(x, y, ground_id) # These are important for pathfinding and building to check if the ground tile # is blocked in any way. self.ground_map[(ground.x, ground.y)] = ground self._init_cache() self.settlements = [] self.wild_animals = [] self.num_trees = 0 # define the rectangle with the smallest area that contains every island tile its position min_x = min(zip(*self.ground_map.keys())[0]) max_x = max(zip(*self.ground_map.keys())[0]) min_y = min(zip(*self.ground_map.keys())[1]) max_y = max(zip(*self.ground_map.keys())[1]) self.position = Rect.init_from_borders(min_x, min_y, max_x, max_y) if not preview: # this isn't needed for previews, but it is in actual games self.path_nodes = IslandPathNodes(self) # repopulate wild animals every 2 mins if they die out. Scheduler().add_new_object(self.check_wild_animal_population, self, Scheduler().get_ticks(120), -1) """TUTORIAL:
def __init__(self, id, x, y): self.id = id self.loading_area = Point(x, y) self.position = Rect(x, y, 10, 10) self.radius = 11
def __init__(self, id, x, y): self.id = id self.loading_area = Point(x, y) self.island = TestIsland() self.position = Rect(x, y, 10, 10)