def AfterLife(): # Screen setup screen = window.setWindow() player = classes.Player() stage = classes.Stage() enemy = classes.Enemy() # Screen update rate clock = pygame.time.Clock() # Main game loop running = True while running: # Screen update rate clock.tick(60) # Event listener loop for event in pygame.event.get(): # Game controls player.movimientos(event, stage) # Terminate game when window is closed if event.type == pygame.QUIT: running = False # Game Graphics stage.pintarFondo(stage.fondos, screen) enemy.spawn(stage, player) enemy.pintarEnemigo(screen, stage, player) player.pintarJugador(player.estado, screen, stage) enemy.move(screen, stage, player) player.HUD(screen, stage, enemy) pygame.display.update()
def spawn(FPS, total_frames): four = FPS * 4 if total_frames % four == 0: r = random.randint(1, 2) x = 1 if r == 2: x = 1200 - 40 enemy = classes.Enemy(x, 720 - 40, 40, 40, "img/enemy.jpg")
def spawn(FPS, total_frames): four_seconds = FPS * 4 if (total_frames % four_seconds == 0): r = random.randint(1, 2) x = 1 if r == 2: x = 1920 - 49 classes.Enemy(x, 500, "images/enemy.jpg")
def create_enemy(self): x = random.randint(100, 1000) y = random.randint(100, 1000) enemy_segments = [ cl.Enemy_segment(x, y, self.frame._canvas), cl.Enemy_segment(x + SEG_SIZE, y, self.frame._canvas), cl.Enemy_segment(x + 2 * SEG_SIZE, y, self.frame._canvas) ] enemy = cl.Enemy(enemy_segments, self.frame._canvas) return enemy
def start_game(): """Основной цикл игры""" music_repeat = pygame.USEREVENT + 1 time_spawn_enemy = pygame.USEREVENT + 2 level_end_timer = pygame.USEREVENT + 3 can_end_level = True init_music() pygame.time.set_timer(music_repeat, 42736) pygame.time.set_timer(time_spawn_enemy, 10000) global_perms.PLAYER = classes.Player(0, 0) enemy_pos, base, count_enemy = launch_level() while global_perms.GAME_RUNNING: for event in pygame.event.get(): if event.type == pygame.QUIT: terminate() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: pause_game() else: global_perms.PLAYER.action = event.key elif event.type == pygame.KEYUP: if event.key == global_perms.PLAYER.action: global_perms.PLAYER.action = None elif event.type == level_end_timer: pygame.time.set_timer(level_end_timer, 0) global_perms.LEVEL_ID += 1 if global_perms.LEVEL_ID == global_perms.MAX_LEVEL: global_perms.GAME_RUNNING = False else: end_level_screen() can_end_level = True enemy_pos, base, count_enemy = launch_level() elif event.type == time_spawn_enemy: i = len( enemy_pos) if len(enemy_pos) < count_enemy else count_enemy for j in range(i): pos = enemy_pos[j] classes.Enemy(pos[0] * 32, pos[1] * 32, global_perms.ALL_SPRITES, global_perms.ENEMY_GROUP) count_enemy -= 1 elif event.type == music_repeat: pygame.mixer.music.play() if len(global_perms.ENEMY_GROUP) == count_enemy == 0 and can_end_level: pygame.time.set_timer(level_end_timer, 5000) can_end_level = False update_and_draw_screen() draw_texts(count_enemy) pygame.display.flip() global_perms.CLOCK.tick(global_perms.FPS) if global_perms.IS_GAME_OVER: return 1 else: return 0
def newEnemy_4(): enemy = classes.Enemy(name = "enemy", \ Hp = 4000, \ image = enemyImgList[0], \ movePattern = custom.enemyMovePattern_4, \ enemyBulletImage = [enemyBulletImgList[9]], \ putBulletPattern = [custom.enemyPutBulletPattern_4], \ shootBulletPattern = [custom.enemyshootBulletPattern_4], \ dropItem = (8, 10)) parameter.getAllSprites().add(enemy) parameter.getEnemySprites().add(enemy)
def newEnemy_3(): enemy = classes.Enemy(name = "enemy", \ Hp = 30, \ image = enemyImgList[1], \ movePattern = custom.enemyMovePattern_3, \ enemyBulletImage = [enemyBulletImgList[8]], \ putBulletPattern = [custom.enemyPutBulletPattern_3], \ shootBulletPattern = [custom.enemyshootBulletPattern_3], \ dropItem = (1, 4)) parameter.getAllSprites().add(enemy) parameter.getEnemySprites().add(enemy)
def spawn(FPS, total_frames, SCREENHEIGHT, score): #Setting up variables that will help determine the time intervals #from which the enemies should be spawned at four_seconds = FPS * 4 one_second = FPS * 1 if score > 300: if total_frames % one_second == 0: r = random.randint(1, 2) x = 1 if r == 2: x = 1400 - 120 enemy = classes.Enemy(x, SCREENHEIGHT - 110, 120, 120, "C:\\Users\\Joseph Molina\\Desktop\\CST\\ghost.png") else: if total_frames % four_seconds == 0: #random spawn sights r = random.randint(1, 2) x = 1 if r == 2: x = 1400 - 120 enemy = classes.Enemy(x, SCREENHEIGHT - 110, 120, 120, 'C:\\Users\\Joseph Molina\\Desktop\\CST\\ghost.png')
def generateEnemy(w, h, enemies, target, type): #Create an "Enemy" or "Enemy "object that will chase the target. side = r.randint(0, 3) if side == 0: x = -20 y = r.randint(0, h) elif side == 1: x = w + 20 y = r.randint(0, h) elif side == 2: y = -20 x = r.randint(0, w) elif side == 3: y = h + 20 x = r.randint(0, w) if type == 0: enemies.append(classes.Enemy(x, y, target)) elif type == 1: enemies.append(classes.EnemyShooter(x, y, target))
count_tutorial = 0 count_menu = 0 count_rastart_mode = '' count_rastart = 0 # данные, нужные для более универсального # представления персонажей на разных мониторах width_mob = x_mobs = width // 45 y_mobs = height // 2 height_mob = height // 5 speed_mob = 700 # объекты движующиеся enemy = classes.Enemy(x_mobs, y_mobs, width_mob, height_mob, speed_mob) hero = classes.Hero(width - x_mobs * 2, y_mobs, width_mob, height_mob, speed_mob) hero_2 = classes.Hero(x_mobs, y_mobs, width_mob, height_mob, speed_mob) ball = classes.Ball((400, 560), screen, 35, hero, enemy, hero_2) enemy.add_ball(ball) # объекты дисплейные background = classes.DrawBackground() sprite_tutorial = classes.tutorial_sprite() sprite_menu = classes.menu_sprite() restart_sprite = classes.restart_sprite() # подравнивание меню под экран classes.transforms(sprite_tutorial, width, height) classes.transforms(sprite_menu, width, height)
" MP: " + str(player.mpu)) #player's color theme is blue print(c.red + enemy.name + " HP: " + str(enemy.hp) + " " + enemy.name + " MP: " + str(enemy.mpu)) #enemy's is red global prompt prompt = input(c.yellow + "Attack(1), Heal(2) " + c.base2 + ">>>" + c.magenta).strip() agiScan() def enemyMove(): move = randint(1, 2) if move == 1: enemyAttack() elif move == 2: enemyHeal() def run(): global player, monster while True: fight() if __name__ == "__main__": cl.Player = cl.DefaultPlayer cl.Enemy = cl.Slime player = cl.Player() enemy = cl.Enemy() player.name = "Jon Appleseed" #if player doesn't have a name, make it Jon Appleseed. run()
def enemy_add(width_en): width_enemy = 60 height_enemy = 70 xy = [random.randint(1, width_en), 410 - height_enemy] speed = 5 enemys.append(classes.Enemy(xy, width_enemy, height_enemy, speed))
trad_lazer = cass.Laser(colors.red, None, 200, 1, 6) # preset firing patterns, insert into weapons normal_gun = (cass.FirePattern(average_bullet, 10, 0), cass.FirePattern(average_bullet, 15, 0)) normal_lazer = (cass.FirePattern(trad_lazer, 0, 0), cass.FirePattern(trad_lazer, 0, 1)) normal_electron = (cass.WorldObject(colors.item_yellow, "lightning", None, 0, 0, 0, None, 5, 1, 1, 1, 3)) #for lightning objects the speed variable is used for any forward momentum, #angle is the variance of its flow forward, IE how not straight the line will be std_lightning = (cass.FirePattern(normal_electron, 0, 0)) first_lazer = cass.Weapon("First Lazer", "The name says it all", 20, 1, "Left", 2, 500, normal_lazer, False, False, False) first_gun = cass.Weapon("GUN", "The name says it all", 20, 2, "Right", 10, 400, normal_gun, False, False, False) minigun = cass.Weapon("MINIGUN", "The name says it all", 200, 2, "Right", 2, 400, normal_gun, False, False, False) lightning_cannon = cass.Weapon("lighting cannon", "shoots lignting at enemies", 200, 4, "right", 20, 300, std_lightning, False, False, False) sturdy_brick = cass.GameWall(0, 0, -125, 1, 0, 0, 0, 0, False, [100, 100, 255], False) dummy = cass.Enemy("target dummy", "read the name", 0, 0, 0, 0, 20, 20, 20, 20, 20, 2, 0, 0, 0, 0, "practicioner", 0, "inanimate", None, None, None, None) #"dummytransparent.png")
timer += 1 if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: pause = True if event.key == pygame.K_SPACE and can_super == True: mouse_position = pygame.mouse.get_pos() temp_bullet = classes.Bullet(screen, black, mouse_position, (40,40), 1, 0, 0) super_bullet.add(temp_bullet) #each time the timer is called the countdown is minus 1. When it reaches 0 this if statement can be called, super_countdown = 10 #once called the countdown is reset to 10 and this if statement can no longer be called can_super = False if super_countdown == 0: #for timer can_super = True if level >= 1: enemy_list.append(classes.Enemy(screen, green, 30, 5, (40,40), 10, 3, False)) if level >= 3: enemy_list.append(classes.Enemy(screen, red, 50, 10, (50,50), 20, 4, False)) if level >= 5: enemy_list.append(classes.Enemy(screen, blue, 70, 20, (50,50), 40, 5, False)) #each round this adds the possible enemies that can be spawned to the enemy list if level >= 7: #as you level up this possible list gets bigger enemy_list.append(classes.Enemy(screen, purple, 100, 30, (30,30), 60, 7, False)) if level >= 8: enemy_list.append(classes.Enemy(screen, gold, 150, 50, (70,70), 80, 3, False)) if level >= 10 and on_boss_start == True: on_boss_start = False boss = True #these change what some of the loops do boss_intro = True boss_music = pygame.mixer.music.load("PygameBossMusic.mp3") #once level 10 is reached the boss battle is initiated, this code can only run once pygame.mixer.music.play(-1) for enemy in enemy_sprites:
def create_enemy(): global enemy enemy = c.Enemy(1) enemy.print_stats()