def main(): pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) #,RESIZABLE) pygame.display.set_caption("Alien Invasion") play_button = Button(ai_settings, screen, "Play") stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) ship = Ship(ai_settings, screen) moon = Moon(ai_settings, screen) earth = Earth(ai_settings, screen) stars = Group() bullets = Group() aliens = Group() gf.create_fleet(ai_settings, screen, ship, aliens) gf.create_multilayer_star(ai_settings, screen, stars) while True: gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets) if stats.game_active: ship.update() gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets) gf.update_aliens(ai_settings, stats, sb, screen, ship, aliens, bullets) stats.update_highscore() gf.update_screen(ai_settings, screen, stats, stars, sb, [moon, earth], [ship], play_button, aliens, bullets)
def startSimulation(self): nbCells = int(self.txtNbCell.toPlainText()) albedoCloud = float(self.txtAlbedo.toPlainText()) greenHouse = float(self.txtGreenHouse.toPlainText()) fTempInit = float(self.txtTempInit.toPlainText()) matSize = int(math.sqrt(nbCells)) tempInit = np.zeros((matSize, matSize)) tempInit.fill(fTempInit) self.grpInitialParameters.setEnabled(False) self.grpIterCtrl.setEnabled(True) self.grpCurrentIter.setEnabled(True) # Creating the Earth object self.earth = Earth(nbCells, albedoCloud, greenHouse, tempInit) self.matOverall = np.zeros(1) matAvgPerZone = self.earth.getAvgPerZone() self.matOverall[0] = self.computeOverallAvg(matAvgPerZone) self.graphCurrent.show() self.graphCurrent.update_figure(0, matAvgPerZone) self.graphOverall.show() self.graphOverall.update_figure(1, self.matOverall)
def run_game(): pygame.init() pygame.mixer.music.load('music/Phantom from Space.mp3') pygame.mixer.music.play(-1) pygame.mixer.music.set_volume(0.5) sw_settings = Settings() screen = pygame.display.set_mode( (sw_settings.screen_width, sw_settings.screen_height)) pygame.display.set_caption("Earth's Defender") earth = Earth(sw_settings, screen) moon = Moon(sw_settings, screen) sun = Sun(sw_settings, screen) play_button = Button(sw_settings, screen, "Play") pause_message = PauseMessage(sw_settings, screen, "Pause") game_stats = GameStats(sw_settings) scoreboard = Scoreboard(sw_settings, screen, game_stats) ship = Ship(sw_settings, screen) alien_boss = AlienBoss(sw_settings, screen) bullets = Group() aliens = Group() aliens_bullets = Group() asteroids = Group() gf.create_fleet(sw_settings, screen, ship, aliens) while True: gf.check_events(sw_settings, screen, game_stats, scoreboard, play_button, pause_message, ship, aliens, bullets, aliens_bullets, asteroids) if game_stats.game_active and game_stats.game_pause: ship.update() gf.update_bullets(sw_settings, screen, game_stats, scoreboard, ship, aliens, bullets, aliens_bullets, asteroids, alien_boss) gf.update_aliens(sw_settings, game_stats, scoreboard, screen, ship, aliens, bullets, aliens_bullets, asteroids) gf.check_alien_fires(sw_settings, screen, aliens, aliens_bullets) gf.update_aliens_bullets(sw_settings, game_stats, scoreboard, screen, ship, aliens, bullets, aliens_bullets, asteroids) gf.check_asteroid_fall(sw_settings, screen, asteroids) gf.update_asteroids(sw_settings, game_stats, scoreboard, screen, ship, aliens, bullets, aliens_bullets, asteroids) gf.update_alien_boss(sw_settings, screen, game_stats, alien_boss, aliens, aliens_bullets, bullets, asteroids) gf.update_screen(sw_settings, screen, earth, moon, sun, game_stats, scoreboard, ship, aliens, bullets, aliens_bullets, asteroids, play_button, pause_message, alien_boss)
def __init__(self): pygame.init() self.clock = pygame.time.Clock() self.font = pygame.font.SysFont("Arial", 18) self.settings = Settings() self.screen = pygame.display.set_mode( (self.settings.screen_width, self.settings.screen_height)) pygame.display.set_caption("Alienz") self.logger = Logger(self) self.earth = Earth(self) self.bullets = pygame.sprite.Group() self.ships = pygame.sprite.Group() self.enemies = pygame.sprite.Group() self.is_encounter_active = False self.encounter = Encounter(self)
def action(self): x = self.__outer.x y = self.__outer.y earth = Earth(self.__outer._ecosystem, x, y, water_amount=self.__outer.water_amount) self.__outer._ecosystem.plant_map[x][y] = earth self._status = bt.Status.FAIL
def initialize_forest(self): """Adds initial organisms to the map.""" directions = list(Direction) # Water map for pool_size in WATER_POOLS: rand_x = random.randint(0, self.width - 1) rand_y = random.randint(0, self.height - 1) while self.water_map[rand_x][rand_y]: rand_x = random.randint(0, self.width - 1) rand_y = random.randint(0, self.height - 1) water_pools_added = 0 positions = [(rand_x, rand_y)] WATER_POOLS_POSITIONS.append((rand_x, rand_y)) while water_pools_added < pool_size and positions: # Breadth first add water pools around x, y = positions.pop(0) if not self.water_map[x][y]: water = Water(self, x, y) self.water_map[x][y] = water water_pools_added += 1 # Insert all neighbors random.shuffle( directions) # shuffle for a bit random shapes for dir in directions: new_x = x + dir.value[0] new_y = y + dir.value[1] # Check if out of bounds if new_x < 0 or new_x >= self.width or new_y < 0 or new_y >= self.height: continue if self.water_map[new_x][new_y]: continue positions.append((new_x, new_y)) # Plant map for x in range(self.width): for y in range(self.height): # check if water if self.water_map[x][y]: continue if random.random() <= TREE_PERCENTAGE: tree = Tree(self, x, y) self.plant_map[x][y] = tree if random.random() <= HIVES_PER_TREE: hive = Hive(self, x, y) self.animal_map[x][y].append(hive) bee_amount = random.randint(HIVE_BEE_MIN_AMOUNT, HIVE_BEE_MAX_AMOUNT) bee = Bee(self, x, y, hive=hive, scout=True, age=random.randint(0, 24 * 150)) hive.bees.append(bee) self.animal_map[x][y].append(bee) for _ in range(bee_amount): bee = Bee(self, x, y, hive=hive, scout=False, age=random.randint(0, 24 * 150)) self.animal_map[x][y].append(bee) hive.bees.append(bee) elif random.random() <= GRASS_INIT_PERCENTAGE: grass = Grass(self, x, y, random.randint(-80, 100), None, self.get_initial_water_level(x, y)) self.plant_map[x][y] = grass else: earth = Earth(self, x, y, self.get_initial_water_level(x, y)) self.plant_map[x][y] = earth # Flower map from organisms import Type for x in range(self.width): for y in range(self.height): if self.water_map[x][y]: continue if random.random() <= FLOWER_PERCENTAGE: if self.plant_map[x][y] and self.plant_map[x][ y].type == Type.TREE: continue for _ in range(random.randint(1, 4)): flower = Flower(self, x, y, random.randint(-50, 100), nectar=random.randint(0, 100), has_seed=random.choice([True, False])) self.flower_map[x][y].append(flower) # Animal map import numpy as np # Rabbits for _ in range(BURROW_AMOUNT): x = random.randint(0, self.width - 1) y = random.randint(0, self.height - 1) while self.water_map[x][y]: x = random.randint(0, self.width - 1) y = random.randint(0, self.height - 1) burrow = Burrow(self, x, y) self.animal_map[x][y].append(burrow) rabbit_amount = random.randint(BURROW_RABBIT_MIN_AMOUNT, BURROW_RABBIT_MAX_AMOUNT) for _ in range(rabbit_amount): dx = random.randint(-3, 3) dy = random.randint(-3, 3) if x + dx < 0 or x + dx >= self.width or y + dy < 0 or y + dy >= self.height: continue if self.water_map[x + dx][y + dy]: continue rabbit = Rabbit(self, x + dx, y + dy, random.choice([True, False]), adult=True, burrow=burrow, age=random.randint(24 * 30, 24 * 30 * 3), reproduction_timer=random.randint(0, 24 * 6), genetics_factor=np.random.normal(1, 0.1)) self.animal_map[x + dx][y + dy].append(rabbit) # Foxes for _ in range(FOX_AMOUNT): x = random.randint(0, self.width - 1) y = random.randint(0, self.height - 1) while self.water_map[x][y]: x = random.randint(0, self.width - 1) y = random.randint(0, self.height - 1) fox = Fox(self, x, y, random.choice([True, False]), adult=True, age=random.randint(24 * 30 * 2, 24 * 30 * 6), genetics_factor=np.random.normal(1, 0.1)) self.animal_map[x][y].append(fox)