def __init__(self, spawn_x, spawn_y, sign=None, w=1.0): self.waddle_dee_size = 32 self.waddle_dee_rect = pygame.Rect(spawn_x, spawn_y, self.waddle_dee_size, self.waddle_dee_size) Enemy.__init__(self, self.waddle_dee_rect, sign, w) if self.stats.speed > 1: self.base_speed = self.stats.speed
def spawn_enemy(settings, screen, enemies, images, id): """Spawn one enemy.""" enemy = Enemy(settings, screen, images, id) enemy.x = settings.screen_width enemy.y = random.randint(0, settings.screen_height - enemy.rect.height) enemy.rect.x = enemy.x enemy.rect.y = enemy.y enemies.add(enemy)
def battle(player, ai_level): clear_screen() print("Prepare for battle!") enemy = Enemy(ai_level) check = False player_is_blocking = False result = None while not check: clear_screen() print(f'You are fighting a level {ai_level} enemy, it\'s remaining health is {enemy.hp}, your remaining health is {player.current_hp}hp!\n') print('-'*40) print("Options:") print(" 1: Attack!") print(" 2: Block") print(" 3: Run!") option = option_selector(3) if option == 1: otpt = enemy.calculate_damage(player.attack_damage) print(f'You did {otpt["damage"]} damage! Your enemy is now at {otpt["hp"]}hp!') elif option == 2: player_is_blocking = True elif option == 3: print("You run away.. coward.") check = True result = "run" print('-'*20) if enemy.hp <= 0: check = True player.coins += ai_level*100 player.xp += ai_level*10 + random.randint(1,50) player.current_hp = player.max_hp result = "won" else: otpt = player.calculate_damage(enemy.attack_damage, player_is_blocking) if player.current_hp <= 0: check=True player.current_hp = player.max_hp result = "loss" clear_screen() if result == "won": print("You won the battle!") player.wins += 1 elif result == "loss": print("You lost the battle..") player.losses += 1 elif result == "run": print("You ran away from battle!") player.losses += 1 input("Press enter to continue...") return ["menu_request:main_menu", player]
def __init__(self): self.middle_rects = self.create_middle_rects(5, 15) # Initialize entities self.player = Player(20, 20, 100, PLAYER_COLOR) self.enemy = Enemy(SCREEN_WIDTH - 20 - 20, 20, 100, ENEMY_COLOR) self.ball = Ball(12, 600) # Initialize fonts self.score_font = pygame.font.Font("8bit.ttf", SCORE_SIZE) self.player_score_label = self.score_font.render( str(self.player.score), True, SCORE_COLOR) self.enemy_score_label = self.score_font.render( str(self.enemy.score), True, SCORE_COLOR)
def cinq(screen): murs = [] #ca marche pas psk y'a pas de mur sur les coyté jcrois for y in range(160, 288, 32): x = 0 mur = Mur(screen, x, y, "mur") murs.append(mur) for y in range(160, 288, 32): x = 448 if y != 224: mur = Mur(screen, x, y, "mur") murs.append(mur) for x in range(0, 128, 32): y = 128 mur = Mur(screen, x, y, "mur") murs.append(mur) for x in range(32, 456, 32): y = 160 if x != 32 and x != 64: mur = Mur(screen, x, y, "mur") murs.append(mur) for x in range(0, 456, 32): y = 288 mur = Mur(screen, x, y, "mur") murs.append(mur) murs.append(Mur(screen, 128, 256, "pierre")) murs.append(Mur(screen, 128, 224, "pierre")) murs.append(Mur(screen, 256, 192, "pierre")) murs.append(Mur(screen, 256, 224, "pierre")) murs.append(Mur(screen, 384, 256, "pierre")) murs.append(Mur(screen, 384, 224, "pierre")) enemies = [ Enemy(screen, 128, 192, 2, 1), Enemy(screen, 256, 256, 2, 1), Enemy(screen, 384, 192, 2, 3) ] potions = [ Potion(screen, 416, 224, "heal"), Potion(screen, 416, 256, "heal") ] portes = [Porte(screen, 448, 224)] eaus = [] return murs, enemies, potions, portes, eaus
def classic(screen): murs = [] for x in range(0, 480, 32): y = 0 mur = Mur(screen, x, y, "mur") murs.append(mur) for x in range(0, 480, 32): y = 448 mur = Mur(screen, x, y, "mur") murs.append(mur) for y in range(32, 448, 32): x = 0 mur = Mur(screen, x, y, "mur") murs.append(mur) for y in range(32, 448, 32): x = 448 if y != 224: mur = Mur(screen, x, y, "mur") murs.append(mur) enemies = [ Enemy(screen, 64, 64, 1, 1), Enemy(screen, 160, 64, 1, 2), Enemy(screen, 256, 64, 1, 3), Enemy(screen, 352, 64, 3, 1), ] potions = [ Potion(screen, 64, 384, "heal"), Potion(screen, 160, 384, "xp"), Potion(screen, 256, 384, "atk"), ] portes = [Porte(screen, 448, 224)] eaus = [] return murs, enemies, potions, portes, eaus
def add_enemies(): n = randint(3, 7) dx = rand_dx() r = 15 x_0 = rand_x(n, r, dx) y = rand_y() enemies = [] for i in range(n): x = x_0 + (r * n - r * i) * dx enemy = Enemy(x, y, r - i, 0, dx) enemies.append(enemy) squadron.append(enemies)
def play_level(self): self._init_groups() self.entities.add(self.player) level = self.level_manager.get_level() # Set up stats text x_offset = self.game_width + 10 y_offset = 10 self.level_text = LevelText(self, x_offset, y_offset, level.name) y_offset += self.level_text.rect.height + 30 self.stat_header = StatsHeaderText(self, x_offset, y_offset) y_offset += self.stat_header.rect.height + 10 self.stat_text_health = StatsHealthText(self, x_offset, y_offset) y_offset += self.stat_text_health.rect.height + 10 self.stat_text_dmg = StatsDamageText(self, x_offset, y_offset) level_grid = level.load() # Set up the background tiles background_tile = self.load_image('BlueTileFloor.png') self.background = pg.Surface(self.screen_rect.size) for x in range(0, self.game_width, self.tile_size): for y in range(0, self.game_height, self.tile_size): grid_x = int(x / self.tile_size) grid_y = int(y / self.tile_size) if level_grid[grid_y][grid_x] == 'W': Wall(self, x, y) elif level_grid[grid_y][grid_x] == 'E': Enemy(self, x, y) elif level_grid[grid_y][grid_x] == 'P': # todo: change the player around so that we can initialize it with a position self.player.rect.x = x self.player.rect.y = y elif level_grid[grid_y][grid_x] == 'C': Collectable(self, x, y) self.background.blit(background_tile, (x, y)) self.window.blit(self.background, (0, 0)) self.window.blit(self.sidebar_surface, (self.game_width, 0)) pg.display.flip() self.state = GameState.PLAYING
def __init__(self, data, sprites): # Localização inicial do jogador self.spawn = data["player"] # Tiles do mapa self.map = data["map"] self.width, self.height = len(data["map"][0]), len(data["map"]) self.tex = 64 # Cores self.color = tuple(data["colors"]["floor"]), data["colors"]["ceil"] self.dark = data["colors"]["dark"] # Música de fundo self.music = data["music"] # Inimigos e itens self.entities = [ Enemy(pos, sprites[enemy], enemy == "boss") for enemy, pos in data["enemies"] ] + [ Item(pos, sprites["items"].sprites[item], item) for item, pos in data["items"] ]
def six(screen): murs = [] for x in range(0, 480, 32): y = 0 mur = Mur(screen, x, y, "mur") murs.append(mur) for x in range(0, 480, 32): y = 448 mur = Mur(screen, x, y, "mur") murs.append(mur) for y in range(32, 448, 32): x = 0 mur = Mur(screen, x, y, "mur") murs.append(mur) for y in range(32, 448, 32): x = 448 if y != 224: mur = Mur(screen, x, y, "mur") murs.append(mur) enemies = [ Enemy(screen, 256, 192, 1, 5), Enemy(screen, 288, 192, 1, 6), Enemy(screen, 256, 224, 1, 7), Enemy(screen, 288, 224, 1, 8), Enemy(screen, 416, 224, 1, 9), Enemy(screen, 416, 256, 1, 9), Enemy(screen, 416, 192, 1, 9) ] potions = [ Potion(screen, 256, 192, "atkboss"), Potion(screen, 288, 192, "atkboss"), Potion(screen, 256, 224, "atkboss"), Potion(screen, 288, 224, "atkboss") ] portes = [Porte(screen, 448, 224)] eaus = [] return murs, enemies, potions, portes, eaus
def survival_mode(): if player.health < 5: player.health = 5 player.enemy_list = [] player.bullet_list = [] kills = 0 player.rect[1] = 73 player.rect[0] = 10 font = pygame.font.Font("DotGothic16-Regular.ttf", 10) while True: p_kills = str(kills) t = "KILLS: " + p_kills text = font.render(t, True, (0, 190, 145)) if player.health > 0: display.fill((0, 29, 42)) display.blit(bg, (-30, 0)) display.blit(text, (200, 0)) display.blit(player.img, (player.rect[0], player.rect[1])) player.move() player.check_boundaries(display) for i in range(player.health): display.blit(heart_img, (i * heart_img.get_width() * 1.25, 15)) for bul in player.bullet_list: display.blit(bul.img, (bul.rect[0], bul.rect[1])) bul.move(player, display) for enemy in player.enemy_list: if bul.rect.colliderect(enemy.rect): player.enemy_list.remove(enemy) kills += 1 if len(player.enemy_list) <= 9: player.enemy_list.append( Enemy( enemy1_img1, 1, display.get_width(), randint( 20, display.get_height() - enemy1_img1.get_height()), 1200)) else: player.enemy_list.remove(player.enemy_list[-1]) for enemy in player.enemy_list: display.blit(enemy.img, (enemy.rect[0], enemy.rect[1])) enemy.move(player) enemy.shoot() for bul in enemy.bullet_list: display.blit(bul.img, (bul.rect[0], bul.rect[1])) bul.move(enemy) if bul.rect.colliderect(player.rect): player.health -= 1 if len(enemy.bullet_list) > 0: enemy.bullet_list.remove(bul) ## Checks for input for e in pygame.event.get(): if e.type == QUIT: pygame.quit() sys.exit() if e.type == KEYDOWN: if e.key == K_ESCAPE: main_menu() if e.key == K_RIGHT: player.movement[0] += player.speed if e.key == K_LEFT: player.movement[0] -= player.speed if e.key == K_UP: player.movement[1] -= player.speed if e.key == K_DOWN: player.movement[1] += player.speed if e.key == K_SPACE: player.bullet_list.append( Bullet( p_bullet, 10, player.rect[0] + player.img.get_width() + 1, player.rect[1] + player.img.get_height() / 2 - 4)) if e.type == KEYUP: if e.key == K_RIGHT: player.movement[0] = 0 if e.key == K_LEFT: player.movement[0] = 0 if e.key == K_UP: player.movement[1] = 0 if e.key == K_DOWN: player.movement[1] = 0 screen.blit(pygame.transform.scale(display, WIN), (0, 0)) pygame.display.update() clock.tick(FPS) else: death_screen()
def tutorial(): ## Sets the font font = pygame.font.Font("DotGothic16-Regular.ttf", 10) ## Tutorial messages t1 = "Use the arrow keys to move around!" t2 = "Use space to shoot!" t3 = "Kill enemies to get points!" ## Makes the text able to be rendered text1 = font.render(t1, True, (0, 190, 145)) text2 = font.render(t2, True, (0, 190, 145)) text3 = font.render(t3, True, (0, 190, 145)) ## Sets sone player values for tutorial only player.rect[0] = 10 player.rect[1] = 73 player.max_bullets = 1 player.enemy_list.append( Enemy(enemy1_img1, 1, display.get_width(), randint(20, display.get_height() - enemy1_img1.get_height()), 600)) ## Checks how far player is in tutorial milestones = 0 wait_timer = 250 ## Loop while True: ## Fills/Clears screen display.fill((0, 29, 42)) ## Displays background image display.blit(bg, (-30, 0)) ## Sees how far the player is in the tutorial/Displays tutorial messages if milestones == 0: display.blit(text1, (35, 0)) if milestones == 1: display.blit(text2, (75, 0)) if milestones == 2: display.blit(text3, (35, 0)) if milestones == 3: wait_timer -= 1 if wait_timer <= 0: main_menu() ## Render sprites # Renders player display.blit(player.img, (player.rect[0], player.rect[1])) # Renders ammo images for i in range(player.max_bullets): display.blit(bullet_counter_img, (i * bullet_counter_img.get_width() * 1.25, 0)) # Renders player health for i in range(player.health): display.blit(heart_img, (i * heart_img.get_width() * 1.25, 15)) # Renders player bullet images for bul in player.bullet_list: display.blit(bul.img, (bul.rect[0], bul.rect[1])) # Moves the bullets bul.move(player, display) for enemy in player.enemy_list: if bul.rect.colliderect(enemy.rect): player.enemy_list.remove(enemy) if milestones == 2: milestones += 1 # Moves the player/Checks to make sure the player isn't out of bounds player.move() player.check_boundaries(display) # Renders enemy if milestones >= 2: for enemy in player.enemy_list: display.blit(enemy.img, (enemy.rect[0], enemy.rect[1])) # Moves enemy enemy.move(player) ## Checks for input for e in pygame.event.get(): if e.type == QUIT: pygame.quit() sys.exit() if e.type == KEYDOWN: if e.key == K_ESCAPE: main_menu() if e.key == K_RIGHT: player.movement[0] += player.speed if milestones == 0: milestones += 1 if e.key == K_LEFT: player.movement[0] -= player.speed if milestones == 0: milestones += 1 if e.key == K_UP: player.movement[1] -= player.speed if milestones == 0: milestones += 1 if e.key == K_DOWN: player.movement[1] += player.speed if milestones == 0: milestones += 1 if e.key == K_SPACE: player.bullet_list.append( Bullet( p_bullet, 10, player.rect[0] + player.img.get_width() + 1, player.rect[1] + player.img.get_height() / 2 - 4)) if milestones == 1: milestones += 1 if e.type == KEYUP: if e.key == K_RIGHT: player.movement[0] = 0 if e.key == K_LEFT: player.movement[0] = 0 if e.key == K_UP: player.movement[1] = 0 if e.key == K_DOWN: player.movement[1] = 0 ## Updates the screen screen.blit(pygame.transform.scale(display, WIN), (0, 0)) pygame.display.update() clock.tick(FPS)
class PingPong: def __init__(self): self.middle_rects = self.create_middle_rects(5, 15) # Initialize entities self.player = Player(20, 20, 100, PLAYER_COLOR) self.enemy = Enemy(SCREEN_WIDTH - 20 - 20, 20, 100, ENEMY_COLOR) self.ball = Ball(12, 600) # Initialize fonts self.score_font = pygame.font.Font("8bit.ttf", SCORE_SIZE) self.player_score_label = self.score_font.render( str(self.player.score), True, SCORE_COLOR) self.enemy_score_label = self.score_font.render( str(self.enemy.score), True, SCORE_COLOR) def update(self, delta): # Update entities self.player.update(delta) self.enemy.update(delta) self.ball.update(delta) # Check if the ball collides with one of both paddles ball_collides_player = (self.ball.rect.colliderect(self.player.rect) and self.ball.velocity.x < 0) ball_collides_enemy = (self.ball.rect.colliderect(self.enemy.rect) and self.ball.velocity.x > 0) if ball_collides_player: self.ball.rect.x = self.player.rect.topright[0] # Clamp the value between 0 and player's height hit_relative_y = max( 0, min(self.ball.rect.topleft[1] - self.player.rect.topright[1], self.player.rect.height)) self.ball.change_angle(hit_relative_y, self.player.rect.height) self.enemy.calculate_next_position(self.ball) elif ball_collides_enemy: self.ball.rect.x = self.enemy.rect.x - self.ball.radius * 2 self.ball.velocity.x *= -1 self.ball.predicted_y = -1 # Increase score and update the label if self.ball.rect.topleft[0] <= 0: self.player.score += 1 self.player_score_label = self.score_font.render( str(self.player.score), True, SCORE_COLOR) self.ball.reset() elif self.ball.rect.topright[0] >= SCREEN_WIDTH: self.enemy.score += 1 self.enemy_score_label = self.score_font.render( str(self.enemy.score), True, SCORE_COLOR) def render(self, screen): # Render scores self.render_scores(screen) self.render_middle_rects(screen) # Render entities self.player.render(screen) self.enemy.render(screen) self.ball.render(screen) """ Returns an array of the rects that appear in the middle of the screen """ def create_middle_rects(self, width, number): rects = [] height = SCREEN_HEIGHT / number / 2 for i in range(number): y = i * height * 2 + height / 2 rect = pygame.Rect((SCREEN_WIDTH - width) / 2, y, width, height) rects.append(rect) return rects def render_middle_rects(self, screen): for rect in self.middle_rects: pygame.draw.rect(screen, MIDDLE_RECTS_COLOR, rect) def render_scores(self, screen): screen.blit(self.player_score_label, PLAYER_SCORE_POSITION) screen.blit(self.enemy_score_label, ENEMY_SCORE_POSITION)
running = True fps = 30 window = Window(600, 300) base = Base(window) player1 = Player(window) font = pygame.font.SysFont(None, 30) clock = pygame.time.Clock() for count in range(10): color = (randint(0, 255), randint(0, 255), randint(0, 255)) random_size = (randint(25, 100), 25) enemy = Enemy(window, color, random_size) rects.append(enemy) while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP and player1.yc != 10 and enemy.x != player1.x + player1.width: player1.move() # Determines if Player has collided with the base, if true, then the player stays on it if player1.y == player1.jump_threshold: player1.yc = 10 elif player1.yc == 10 and player1.y + player1.height == base.y: player1.yc = 0
def recv(usersChan): global coop, gameOver,murs,potions,portes,eaus,enemies while True: if gameOver == True: print("gameOver") exit() return try: data = usersChan.recv_pyobj(flags=zmq.NOBLOCK) if data["changement"]: user.pos = data["coop"]["pos"] murs, potions= [], [] portes = [] eaus = [] enemies = [] for mur in data["murs"]: murs.append(Mur(screen,*mur["pos"],mur["genre"])) for potion in data["potions"]: potions.append(Potion(screen,*potion["pos"],potion["type"])) for porte in data["portes"]: portes.append(Porte(screen,*porte["pos"])) for eau in data["eaus"]: eaus.append(Eau(screen,*eau["pos"])) for enemy in data["enemies"]: enemies.append(Enemy(screen,*enemy["pos"],enemy["level"],enemy["type"])) coop.pos = data["user"]["pos"] coop.vie = data["user"]["vie"] coop.attaque = data["user"]["attaque"] coop.defense = data["user"]["defense"] coop.level = data["user"]["level"] coop.xp= data["user"]["xp"] ### Supprimer objets qui ne sont pas en communs entre 2 listes python for potion in potions: ok = False for p in data["potions"]: if potion.pos == p["pos"]: ok = True if ok == False: potions.remove(potion) for enemy in enemies: ok = False for e in data["enemies"]: if enemy.pos == e["pos"]: enemy.vie = e["vie"] ok = True if ok == False: enemies.remove(enemy) refresh() except zmq.ZMQError as err: pass
def addEnemy(self, dt): enemy = Enemy(50, 50, resources.enemySprite, self.mainbatch) enemy.initialize(self.bpm) self.entities.append(enemy) clock.schedule_once(self.addEnemy, 60.0 / self.bpm) self.bpm += 1.0
] # sprite groups all_sprites = pygame.sprite.Group() obstacles = pygame.sprite.Group() enemies = pygame.sprite.Group() # create obstacles for pos in obs: o = Obstacle(pos) all_sprites.add(o) obstacles.add(o) # create enemies for pos in ens: e = Enemy(pos, ENEMY_SPEED) all_sprites.add(e) enemies.add(e) def play(play_id, level): "Function for actual gameplay" global cont start_time = pygame.time.get_ticks() # reset crossed attribute of obstacles and enemies for ent in (enemies.sprites() + obstacles.sprites()): ent.crossed[play_id] = False running = True points = 0 completed[play_id] = 0
def __init__(self, tilemap, **kwargs): super(TileMapWidget, self).__init__(**kwargs) self.jobs = [] self.space = Space() self.space.gravity = (0.0, 0.0) self.objects = [] self.in_battle = False self.entities = [] self.player_characters = [] self.player_flags = [ 'testing' ] # eventually this will be in DB for progress_flags self.enemy_characters = [] self.event_in_progress = None self.last_focus = None self.current_battler = None self.current_character = None self.battle_entities = list() self.spent_battlers = set() self.focus_target = None self.map = tilemap tilemap.load(Window.size) self.size = (float(self.map.px_width), float(self.map.px_height)) self.layer_widgets = {} # for layer in self.map.layers: # layer_widget = Widget() # with layer_widget.canvas: # if hasattr(layer, 'color') and layer.color: # c = get_color_from_hex(layer.color) # c[-1] = .2 # Color(*c) # else: # Color(1, 1, 1, 1) # if not layer.visible: # continue # for cell in layer: # if cell is None: # continue # x = cell.px # # OpenGL vs. TMX, y is reversed # y = cell.py # # Rectangle(pos=(x, y), size=[32, 32]) # # Color(rgba=[1, 0, 0, .5]) # if cell.tile: # texture = cell.tile.texture # size = cell.px_width, cell.px_height # Rectangle(pos=(x, y), texture=texture, size=size, allow_stretch=True) # else: # Rectangle(pos=(cell.px, cell.py), size=(cell.width, cell.height)) # self.add_widget(layer_widget) # self.layer_widgets.update({layer.name: layer_widget}) for layer in self.map.layers: image = os.path.join( MAP_PATH, str(self.map.file_name).split('.')[0] + '_' + layer.name + '.png') print('Layer Image File at?', image) layer_widget = MapLayer(source=image) if exists(image): self.add_widget(layer_widget) self.layer_widgets.update({layer.name: layer_widget}) # for c in self.map.fog_of_war: # # print('cell', c) # cell = self.map.layers.by_name['below'].cells[c] # shape = CellPoly(cell) # shape.sensor, shape.collision_type = True, 1020 # self.space.add(shape) # self.canvas.add(Rectangle(pos=(cell.px, cell.py), size=(cell.px_width, cell.px_width))) # self.canvas.add(shape.color) # # just being more explicit with this condition, because data existing equates to True too. # if self.map.fog_of_war[c] != True: # # print('not true!', c) # shape.color.rgba = [0, 0, 0, .2] primary = None for floor_data in App.get_running_app().db.query(MapObject).filter( MapObject.map_id == self.map.id, MapObject.type == 'floor_entity').all(): entity_widget = FloorEntity(floor_data, self, self.map, **floor_data.properties) self.space.add(entity_widget.body, entity_widget.shape) for enemy_data in App.get_running_app().db.query(MapObject).filter( MapObject.map_id == self.map.id, MapObject.type == 'enemy').all(): entity_widget = Enemy(enemy_data, self, self.map, **enemy_data.properties) self.entities.append(entity_widget) self.enemy_characters.append(entity_widget) for npc_data in App.get_running_app().db.query(MapObject).filter( MapObject.map_id == self.map.id, MapObject.type == 'npc').all(): entity_widget = NPC(npc_data, self, self.map, **npc_data.properties) self.entities.append(entity_widget) for player_data in App.get_running_app().db.query(MapObject).filter( MapObject.map_id == self.map.id, MapObject.type == 'player').all(): entity_widget = Player(player_data, self, self.map, **player_data.properties) self.entities.append(entity_widget) self.player_characters.append(entity_widget) if player_data.properties.get('primary'): print('found primary') primary = entity_widget if primary is not None: self.current_character = primary elif self.player_characters: self.current_character = self.player_characters[0] self.focus_target = self.current_character self.current_character.state = IdleReadyState(self.current_character) print(self.current_character, self.current_character.state) for entity in self.entities: entity.opacity = 1 self.space.add(entity.shape, entity.detector) self.layer_widgets['sprite_layer'].add_widget(entity) for player in self.player_characters: player.opacity = 1 self.space.add(player.interactor) print('we have {} entities'.format(len(self.entities))) self.layer_widgets['sprite_layer'].bind( on_touch_down=self.handle_touch) self.switch_to_real_time_state() self.space.add_collision_handler(16, 105, self.aggro_collide, None, None, None) # self.space.add_collision_handler(105, 216, # lambda s, v: self.set_visible(s, v, True), None, None, lambda s, v: self.set_visible(s, v, False)) # self.space.add_collision_handler(14, 216, # lambda s, v: self.set_visible(s, v, True), None, None, lambda s, v: self.set_visible(s, v, False)) # self.space.add_collision_handler(216, 1020, # lambda s, v: self.clear_fog(s, v), None, None, lambda s, v: self.exit_fog(s, v)) self.space.add_collision_handler(116, 14, self.add_object, None, None, self.remove_object) self.space.add_collision_handler(16, 6, self.add_collidable, None, None, self.remove_collidable)
def All(): return [ [ ### Wave 1 1, #timer [ # items items.spore, items.spore, ], [ Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*playerHunter), Enemy(*playerHunter) ] # enemies ], [ ### Wave 2 25, #timer [ # items items.spore, items.spore, items.spore, ], [ Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*playerHunter), Enemy(*playerHunter), Enemy(*playerHunter), ] # enemies ], [ ### Wave 3 60, #timer [ # items items.spore, items.spore, items.spore, items.spore, ], [ Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*playerHunter), Enemy(*playerHunter), Enemy(*playerHunter), Enemy(*playerHunter), ] # enemies ], [ ### Wave 4 75, #timer [ # items items.spore, items.spore, items.spore, items.spore, items.spore, ], [ Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*playerHunter), Enemy(*playerHunter), Enemy(*playerHunter), Enemy(*playerHunter), Enemy(*playerHunter), Enemy(*playerHunter), Enemy(*playerHunter), ] # enemies ], [ ### Wave 5 100, #timer [ # items items.spore, items.spore, items.spore, items.spore, items.spore, items.spore, ], [ Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*nodeHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*shroomHunter), Enemy(*playerHunter), Enemy(*playerHunter), Enemy(*playerHunter), Enemy(*playerHunter), Enemy(*playerHunter), Enemy(*playerHunter), Enemy(*playerHunter), Enemy(*playerHunter), Enemy(*playerHunter), Enemy(*playerHunter), Enemy(*playerHunter), ] # enemies ] ]
def main(): """ Main Program """ pygame.init() # # Set the height and width of the screen size = [constants.SCREEN_WIDTH, constants.SCREEN_HEIGHT] # # Set display screen screen = pygame.display.set_mode(size) pygame.display.set_caption("Game") # # Create world world = World() sprite_group = pygame.sprite.Group() sprite_group_2 = pygame.sprite.Group() # # Create the player player = Player() enemy = Enemy() # # Create Walls wall = Wall(500, 400, 100, 100) wall2 = Wall(100, 100, 50, 50) # # Group sprite_group.add(wall) sprite_group.add(wall2) sprite_group_2.add(enemy) player.walls = sprite_group player.enemies = sprite_group_2 # Loop until the user clicks the close button. done = False # # Get keys pressed_right = None pressed_left = None pressed_up = None pressed_down = None # Used to manage how fast the screen updates clock = pygame.time.Clock() # -------- Main Program Loop ----------- while not done: for event in pygame.event.get(): # User did something if event.type == pygame.QUIT: # If user clicked close done = True # Flag that we are done so we exit this loop elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: done = True elif event.key == pygame.K_RIGHT: pressed_right = True elif event.key == pygame.K_LEFT: pressed_left = True elif event.key == pygame.K_UP: pressed_up = True elif event.key == pygame.K_DOWN: pressed_down = True elif event.type == pygame.KEYUP: if event.key == pygame.K_RIGHT: pressed_right = False elif event.key == pygame.K_LEFT: pressed_left = False elif event.key == pygame.K_UP: pressed_up = False elif event.key == pygame.K_DOWN: pressed_down = False player.update(pressed_right, pressed_left, pressed_up, pressed_down) # # Go ahead and update the screen with what we've drawn. world.world_shift(player.rect.x, player.rect.y) screen.fill(constants.WHITE) screen.blit(world.image, world.rect) sprite_group.draw(screen) screen.blit(player.image, player.rect) pygame.draw.rect(screen, constants.GREEN, (10, 10, 60, 10)) enemy.move_enemy(player.rect.x, player.rect.y) # screen.blit(enemy.image, enemy.rect) sprite_group_2.draw(screen) pygame.display.flip() # Limit to 60 frames per second clock.tick(60) # Be IDLE friendly. If you forget this line, the program will 'hang' # on exit. pygame.quit()
def troix(screen): murs = [] for x in range(0, 480, 32): y = 0 mur = Mur(screen, x, y, "mur") murs.append(mur) for x in range(0, 480, 32): y = 416 mur = Mur(screen, x, y, "mur") murs.append(mur) for x in range(0, 480, 32): y = 32 mur = Mur(screen, x, y, "mur") murs.append(mur) for x in range(0, 480, 32): y = 384 mur = Mur(screen, x, y, "lave") murs.append(mur) for x in range(0, 480, 32): y = 64 mur = Mur(screen, x, y, "lave") murs.append(mur) for x in range(0, 480, 32): y = 448 mur = Mur(screen, x, y, "mur") murs.append(mur) for y in range(32, 448, 32): x = 0 mur = Mur(screen, x, y, "mur") murs.append(mur) for y in range(32, 448, 32): x = 448 if y != 224: mur = Mur(screen, x, y, "mur") murs.append(mur) for y in range(96, 384, 32): x = 288 mur = Mur(screen, x, y, "lave") murs.append(mur) for y in range(96, 384, 32): x = 320 mur = Mur(screen, x, y, "lave") murs.append(mur) for y in range(96, 384, 32): x = 256 mur = Mur(screen, x, y, "lave") murs.append(mur) enemies = [] for y in range(96, 384, 32): x = 224 nmy = Enemy(screen, x, y, 1, 4) enemies.append(nmy) potions = [ Potion(screen, 384, 192, "heal"), Potion(screen, 384, 256, "heal") ] portes = [Porte(screen, 448, 224)] eaus = [] return murs, enemies, potions, portes, eaus
def main(): global SCREEN_WIDTH, SCREEN_HEIGHT, FRAMERATE, BACKGROUND # Set win to current window and setup pygame win = setup(SCREEN_WIDTH, SCREEN_HEIGHT) # Setup pygame clock for framerate clock = pygame.time.Clock() # Define music pygame.mixer.music.load('resources/music.mp3') pygame.mixer.music.play(-1) # Score counter score = 0 # Wave counter wave = 1 # Deaths counter deaths = 0 # Create an empty list for projectiles projectiles = [] # Create an empty list for enemies enemies = [] # Create an empty list for players players = [] # Setup cooldown for shooting shoot_cooldown = 0 # Create an instance of Player (multiple instances are respawns) players.append(Player(x=randint(0, SCREEN_WIDTH - 70), y=410)) # Create an instance of Enemy enemies.append( Enemy(x=randint(0, SCREEN_WIDTH - 70), y=410, start_x=0, end_x=SCREEN_WIDTH)) while True: # Framerate clock.tick(FRAMERATE) if not check_events(): break # Define player as 0th element from array try: player = players[0] except IndexError: deaths += 1 players.append(Player(x=randint(0, SCREEN_WIDTH - 70), y=410)) player = players[0] # Controls if player: shoot_cooldown = controls(player=player, projectiles=projectiles, screen_width=SCREEN_WIDTH - 70, shoot_cooldown=shoot_cooldown, max_shoot_cooldown=8 - (wave // 2)) # Update entities enemies, kills = Enemy.update_all(enemies=enemies, projectiles=projectiles) projectiles = Projectile.update_all(projectiles=projectiles, screen_width=SCREEN_WIDTH) players = Player.update_all(players=players, enemies=enemies) # Update score score += kills # Spawn new enemies if len(enemies) == 0: wave += 1 for n in range(0, randint(wave, round(wave * 1.5))): enemies.append( Enemy(x=randint(0, SCREEN_WIDTH - 70), y=410, start_x=0, end_x=SCREEN_WIDTH)) # Health increse increase = randint(score, score + score * wave // 2) player.max_health += increase player.health += player.max_health // 2 # Draw next frame redraw_game_window(win=win, background=BACKGROUND, score=score, wave=wave, deaths=deaths, player=player, enemies=enemies, projectiles=projectiles)
def quatre(screen): murs = [Mur(screen, 224, 416, "pierre")] for x in range(0, 480, 32): y = 0 mur = Mur(screen, x, y, "mur") murs.append(mur) for x in range(0, 480, 32): y = 448 mur = Mur(screen, x, y, "mur") murs.append(mur) for x in range(0, 480, 32): y = 64 if x != 224 and x != 352: mur = Mur(screen, x, y, "mur") murs.append(mur) for x in range(0, 480, 32): y = 416 mur = Mur(screen, x, y, "mur") murs.append(mur) for x in range(0, 224, 32): y = 32 mur = Mur(screen, x, y, "mur") murs.append(mur) for x in range(384, 456, 32): y = 32 mur = Mur(screen, x, y, "mur") murs.append(mur) for x in range(0, 480, 32): y = 384 mur = Mur(screen, x, y, "mur") murs.append(mur) for y in range(32, 448, 32): x = 0 mur = Mur(screen, x, y, "mur") murs.append(mur) for y in range(32, 448, 32): x = 448 if y != 224: mur = Mur(screen, x, y, "mur") murs.append(mur) for y in range(96, 384, 32): x = 288 mur = Mur(screen, x, y, "lave") murs.append(mur) for y in range(96, 384, 32): x = 320 mur = Mur(screen, x, y, "lave") murs.append(mur) for y in range(96, 384, 32): x = 256 mur = Mur(screen, x, y, "lave") murs.append(mur) for y in range(96, 384, 32): x = 128 if y != 256: mur = Mur(screen, x, y, "eau") murs.append(mur) for y in range(96, 384, 32): x = 160 if y != 256: mur = Mur(screen, x, y, "eau") murs.append(mur) for x in range(128, 192, 32): y = 256 mur = Mur(screen, x, y, "pont") murs.append(mur) murs.append(Mur(screen, 224, 352, "pierre")) murs.append(Mur(screen, 224, 320, "pierre")) murs.append(Mur(screen, 416, 96, "pierre")) enemies = [ Enemy(screen, 224, 64, 1, 4), Enemy(screen, 352, 64, 1, 4), Enemy(screen, 64, 128, 1, 1), Enemy(screen, 96, 256, 1, 1), Enemy(screen, 416, 256, 1, 3), Enemy(screen, 384, 96, 1, 3) ] for x in range(224, 384, 32): y = 32 nmy = Enemy(screen, x, y, 1, 4) enemies.append(nmy) potions = [Potion(screen, 192, 224, "atk")] portes = [Porte(screen, 448, 224)] eaus = [] return murs, enemies, potions, portes, eaus
if keys_press[pg.K_ESCAPE]: mode = 'menu' if keys_press[pg.K_w]: direction[1] -= 1 if keys_press[pg.K_s]: direction[1] += 1 if keys_press[pg.K_a]: direction[0] -= 1 if keys_press[pg.K_d]: direction[0] += 1 player.aimTo(*mouse_pos) if mouse_press: player.shoot(bullets, images, time) if time % 50 == 0 and len(enemies) < 6: enemies.append( Enemy((SCREEN_W // 2, -50), images, creation_time=time)) temp = [] for enemy in enemies: enemy.move(time, SCREEN_W, SCREEN_H) enemy.animate(time) enemy.show(SCREEN, SCALE) if (enemy.alive): temp.append(enemy) enemies = temp player.move(*direction) player.animate(time) player.show(SCREEN, SCALE)
for mur in data["murs"]: murs.append(Mur(screen,*mur["pos"],mur["genre"])) for potion in data["potions"]: potions.append(Potion(screen,*potion["pos"],potion["type"])) for porte in data["portes"]: portes.append(Porte(screen,*porte["pos"])) for eau in data["eaus"]: eaus.append(Eau(screen,*eau["pos"])) for enemy in data["enemies"]: enemies.append(Enemy(screen,*enemy["pos"],enemy["level"],enemy["type"])) # Thread parralléle qui récuperre les données def recv(usersChan): global coop, gameOver,murs,potions,portes,eaus,enemies while True: if gameOver == True: print("gameOver") exit() return try: data = usersChan.recv_pyobj(flags=zmq.NOBLOCK)