Ejemplo n.º 1
0
    def __init__(self):
        self.screen = pg.display.set_mode(SIZE)
        self.clock = pg.time.Clock()
        self.running = True
        self.paused = False
        self.debug = False
        self.shift = False
        self.follow = False
        self.minimap = False
        self.FPS = 60
        self.bg = Background(SIZE)
        self.camera = Camera(w=WIDTH, h=HEIGHT)
        self.blocks = []
        self.fading = []
        self.fading_zombies = []
        self.screenshot_counter = 0
        self.destroyers = pg.sprite.Group()
        self.player = Ninja(position=(200, 100), screen=self.bg.rect)
        zombie1 = Zombie((100, 500), self.bg.rect, False)
        zombie2 = Zombie((700, 50), self.bg.rect, True)
        self.zombies = pg.sprite.Group(zombie1, zombie2)

        self.reset()

        self.run()
Ejemplo n.º 2
0
    def run(self):
        self.start_screen()
        params = self.menu.run()
        running = True
        self.hitokiri = Hitokiri(self.hitokiri_sprites, position=(300, 290), horisontal_move=False,
                                 weapont_sprites=self.weapont_sprites, life=params['life'])
        self.hart = Hart(self.screen, self.hitokiri)
        font = pygame.font.Font(None, 30)
        while running:
            self.screen.fill([255, 255, 255])
            self.screen.blit(self.backround_image, (0, 0))
            ss = random.randint(1, params['random'])  # параметр из меню
            if ss == 2:
                Zombie(self.zombie_sprites, horisontal_move=True, position=(20, 280), hitokiri=self.hitokiri,
                       weapont_sprites=self.weapont_sprites, hitokiri_sprites=self.hitokiri_sprites)
            if ss == 3:
                Zombie(self.zombie_sprites, direction=-1, horisontal_move=True, position=(WIDTH - 20, 280),
                       hitokiri=self.hitokiri,
                       weapont_sprites=self.weapont_sprites, hitokiri_sprites=self.hitokiri_sprites)
            for event in pygame.event.get():
                # при закрытии окна
                if event.type == pygame.QUIT:
                    terminate()

                # меняем состояние хитокири:
                if event.type == pygame.KEYDOWN:
                    self.hitokiri.set_state_down(event)
                if event.type == pygame.KEYUP:
                    self.hitokiri.set_state_up(event)
                if event.type == pygame.MOUSEBUTTONUP:
                    pass
            self.weapont_sprites.update()
            self.weapont_sprites.draw(self.screen)
            self.hitokiri_sprites.update()
            self.zombie_sprites.update()
            self.zombie_sprites.draw(self.screen)
            self.hitokiri_sprites.draw(self.screen)
            text_m = font.render(f'SIZE: {self.hitokiri.zomby_kill} ',
                                 0, (255, 255, 255))
            self.hart.write(10, 10) # жизни
            self.screen.blit(text_m, (10, 50)) # очки
            # если жизни кончились, то выходим из цикла
            if self.hitokiri.life < 1:
                running = False
            pygame.display.flip()
            self.clock.tick(FPS * params['fps'])
        # концовка, экран не перерисовывается
        # сверху пишется "game over"
        text_go = self.font_zombie.render('GAME OVER', 1, (255, 215, 0))
        self.screen.blit(text_go, (280, 130))
        pygame.display.flip()
        running = True
        while running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT or event.type == pygame.KEYDOWN:
                    terminate()
Ejemplo n.º 3
0
def create_zombie(ai_settings, screen, zombies, zombie_number, row_number):
    zombie = Zombie(ai_settings, screen)
    zombie_width = zombie.rect.width
    zombie.x = zombie_width + 2 * zombie_width * zombie_number
    zombie.rect.x = zombie.x
    zombie.rect.y = zombie.rect.height + 2 * zombie.rect.height * row_number
    zombies.add(zombie)
Ejemplo n.º 4
0
Archivo: main.py Proyecto: cipz/CoronaZ
def main(args):
    zombie = Zombie(args['field'], args['position'], args['infected'], args['infection_radius'],
                    args['infection_cooldown'])

    mqtt_server_addr = args['server'][0]
    mqtt_queue = args['server'][1]

    producer = get_producer_connection(mqtt_server_addr, KAFKA_CONNECTION_TRIES)

    kill = Event()

    zombie_broadcast = Thread(target=thread_zombie_broadcast, args=(kill, zombie, args['zombie_port']))
    zombie_listen = Thread(target=thread_zombie_listen, args=(kill, zombie, args['zombie_port']))

    server_con_thread = Thread(target=thread_server_con, args=(kill, zombie, mqtt_server_addr, mqtt_queue, producer))

    zombie_broadcast.start()
    zombie_listen.start()
    server_con_thread.start()

    if args['interactive']:
        interactive(zombie)
    else:
        automatic(zombie, args)

    zombie.alive = False

    kill.set()

    zombie_broadcast.join()
    zombie_listen.join()
    server_con_thread.join()
    logging.info('program ended')
Ejemplo n.º 5
0
def run_game():
	tick = 0;
	while 1:
		if game_settings.game_active:
			gf.check_events(screen, game_settings, squares, plants, bullets);
			# screen.fill(game_settings.bg_color);
			tick += 1;
			if tick % 30 == 0:
				zombies.add(Zombie(screen, game_settings));

			zombies_hit = groupcollide(zombies, bullets, False, False); #zombies_hit = dictionary of sprites; bullets will go straight through the zombies if both are false

			# print zombies_hit
			for zombie in zombies_hit: #empty dictionary - zombies are objects put in zombies list (.add() above)
				# print zombie;
				if zombie.yard_row == zombies_hit[zombie][0].yard_row:
					# print "Same row!";
					bullets.remove(zombies_hit[zombie][0]);
					zombie.hit(1); #calling the zombie's local hit method - passed 1 damage - .hit adjusts their health
					if (zombie.health <= 0):
						zombies.remove(zombie); #removes zombie from game
						game_settings.zombie_in_row[zombie.yard_row] -= 1; #removes the 1 zombie from the row as its' killed - plant will keep shooting until # of zombies in row = 0


		gf.update_screen(screen, game_settings, background, zombies, squares, plants, bullets, tick);
		pygame.display.flip();
Ejemplo n.º 6
0
def fire(stats, ai_settings, snow_pea, screen, bullets, zombies,
         buckethead_zombies, float_zombies):
    # 自动发射豌豆,生成僵尸
    stats.bullet_accumulate += 1
    if stats.bullet_accumulate >= ai_settings.bullet_max_accumulate:
        stats.bullet_accumulate = 0
        new_bullet = Bullet(snow_pea, screen)
        bullets.add(new_bullet)
    stats.zombie_accumulate += 1
    if stats.zombie_accumulate >= ai_settings.zombie_max_accumulate and stats.zombie_number > 0:
        stats.zombie_number -= 1
        stats.zombie_accumulate = 0
        new_zombie = Zombie(screen)
        zombies.add(new_zombie)
    stats.buckethead_zombie_accumulate += 1
    if stats.level_2:
        if stats.buckethead_zombie_accumulate >= ai_settings.buckethead_zombie_max_accumulate and stats.buckethead_zombie_number > 0:
            stats.buckethead_zombie_number -= 1
            stats.buckethead_zombie_accumulate = 0
            new_zombie = Buckethead_Zombie(screen)
            buckethead_zombies.add(new_zombie)
    stats.float_zombie_accumulate += 1
    if stats.level_3:
        if stats.float_zombie_accumulate >= ai_settings.float_zombie_max_accumulate and stats.float_zombie_number > 0:
            stats.float_zombie_number -= 1
            stats.float_zombie_accumulate = 0
            new_zombie = Float_Zombie(screen)
            float_zombies.add(new_zombie)
Ejemplo n.º 7
0
def create_new_world():
    global boy, zombies
    boy = Boy()
    zombies = [Zombie() for i in range(100)]

    game_world.add_object(boy, 1)
    game_world.add_objects(zombies, 1)
def run_game():
	tick = 0;
	while 1:
		gf.check_events(screen,game_settings, squares, plants,bullets,icons);
		if game_settings.game_active:
			tick += 1;
			if tick % 30 == 0:
				zombies.add(Zombie(screen,game_settings));

			zombies_hit = groupcollide(zombies, bullets, False, False);
			# print zombies_hit;
			for zombie in zombies_hit:
				# print zombie;
				# print zombies_hit[zombie];
				if zombie.yard_row == zombies_hit[zombie][0].yard_row:
					# print "Same row!!!";
					bullets.remove(zombies_hit[zombie][0]);
					zombie.hit(1);
					if(zombie.health <= 0):
						zombies.remove(zombie);
						game_settings.zombie_in_row[zombie.yard_row] -= 1;
						game_settings.zombies_killed += 1;
			# Create a dictionary with a key of Zombie and a value of a list of Plants that zombie has colided with
			zombies_eating = groupcollide(zombies, plants, False, False);
			# Loop through the dictionary
			for zombie in zombies_eating:
				# Set a var for the Plant (to save our eyes)
				damaged_plant = zombies_eating[zombie][0];
				# Check to see if the zombie and plant are in the same row
				if zombie.yard_row == damaged_plant.yard_row:
					# Zombie has run into a plant in it's row
					# start/continue eating... stop moving if neccessary
					zombie.moving = False;
					# Check to see if zombie takes a bite
					if time.time() - zombie.started_eating > zombie.damage_time:
						# print "Zombie just took a bite";
						# Run chomp
						zombie.zombie_chomp(damaged_plant);
						# plant.take_damage();
						# update zombies last bite time
						zombie.started_eating = time.time()
						# remove the plant if it's 0 or below
						if damaged_plant.health <= 0:
							plants.remove(damaged_plant);
							# start the zombie march again
							zombie.moving = True;

# zombies_eating = {
# 	"key": 2,
# 	<Zombie>: [
# 			<Plant>,
# 			<Plant>,
# 			<Plant>,
# 			<Plant>
# 		]
# }

		gf.update_screen(screen,game_settings,background,zombies,squares,plants,bullets,tick,icons);		
		pygame.display.flip();
Ejemplo n.º 9
0
 def create_game(self):
     return Zombie(
                   grid_height = 4,
                   grid_width = 4,
                   obstacle_list = [(2,2)],
                   zombie_list = [(3,0)],
                   human_list = [(3,1)]
                   )
Ejemplo n.º 10
0
def create_fighter(ai_settings, screen, fighter, zombies):
    zombie = Zombie(ai_settings, screen)
    number_zombies_x = get_number_zombies_x(ai_settings, zombie.rect.width)
    number_rows = get_number_rows(ai_settings, fighter.rect.height, zombie.rect.height)

    for row_number in range(number_rows):
        for zombie_number in range(number_zombies_x):
            create_zombie(ai_settings, screen, zombies, zombie_number, row_number)
Ejemplo n.º 11
0
def generate_zombie_start():
    global Zombie_Generate_num

    for i in range(1, 6):
        m = Zombie((get_canvas_width() + random.randint(0, 5) * 10,
                    get_canvas_height() - i * 100), 'Zombie')
        gfw.world.add(gfw.layer.zombie, m)
        Zombie_Generate_num += 1
def create_horde(settings, screen, zombies, survivor):
    zombie = Zombie(settings, screen)
    number_zombies_x = get_number_zombies_x(settings, zombie.rect.width)
    for row_number in range(
            get_number_rows(settings, survivor.rect.height,
                            zombie.rect.height)):
        for zombie_number in range(number_zombies_x):
            create_zombie(settings, screen, zombies, zombie_number, row_number)
Ejemplo n.º 13
0
def update():
    gfw.world.update()

    global zombie_time
    zombie_time -= gfw.delta_time
    if zombie_time <= 0:
        gfw.world.add(gfw.layer.zombie, Zombie())
        zombie_time = 5
Ejemplo n.º 14
0
def enter():
    server.boy = Boy()
    game_world.add_object(server.boy, 1)

    server.zombie = Zombie()
    game_world.add_object(server.zombie, 1)

    server.ground = Ground()
    game_world.add_object(server.ground, 0)
Ejemplo n.º 15
0
 def spwanZombies(time):
     if p.zombieCount < p.wave * 5:
         if random.randint(1, 100) > 75:
             z = Zombie(p, 10, p.x, p.y)
             e.drawables.add(z)
             e.objects.append(z)
             e.collisions[z] = (p, p.ouch)
             p.zombieCount = p.zombieCount + 1
             zombies.append(z)
Ejemplo n.º 16
0
def create_new_world():
    global boy
    boy = Boy()
    game_world.add_object(boy, 1)

    with open('zombie_data.json', 'r') as f:
        zombie_data_list = json.load(f)
    for data in zombie_data_list:
        zombie = Zombie(data['name'], data['x'], data['y'], data['size'])
        game_world.add_object(zombie, 1)
Ejemplo n.º 17
0
def enter():
    global boy
    boy = Boy()
    game_world.add_object(boy, 1)

    global zombie
    zombie = Zombie()
    game_world.add_object(zombie, 1)

    ground = Ground()
    game_world.add_object(ground, 0)
Ejemplo n.º 18
0
 def _create_zombie(self):
     #Create a zombie and place it on the right hand side of screen
     zombie = Zombie(self)
     zombie_width, zombie_height = zombie.rect.size
     max_y = self.settings.screen_height - zombie_height
     random_entry = randint(0, max_y)
     zombie.y = random_entry
     zombie.x = (self.settings.screen_width + randint(50, 200))
     zombie.rect.x = zombie.x
     zombie.rect.y = zombie.y
     self.zombies.add(zombie)
Ejemplo n.º 19
0
def create_new_world():
    global boy, zombie
    boy = Boy()
    game_world.add_object(boy, 1)

    with open('zombie_data.json', 'r') as f:
        zombie_data_list = json.load(f)  # f라는 파일을 역직렬화 해서 리스트로

    for data in zombie_data_list:  # json 파일을 바꿈으로 내가 원하는 레벨을 설계할 수 있다.
        zombie = Zombie(data['name'], data['x'], data['y'], data['size'])
        game_world.add_object(zombie, 1)
Ejemplo n.º 20
0
    def update(self):
        # 更新对象
        # 补足僵尸
        if len(self.zombies) < self.settings.zombie_number:
            new_zombie = Zombie(self, (random() * 200, random() * 200))
            if pygame.sprite.spritecollideany(new_zombie,
                                              self.zombies) == None:
                self.zombies.add(new_zombie)

        # 更新各对象状态
        self.player.update()
        self.bullets.update()
        self.zombies.update()

        # 计算子弹击中僵尸
        bullets_zombies_collisions = pygame.sprite.groupcollide(
            self.bullets, self.zombies, True, False)

        for bullet, zombies in bullets_zombies_collisions.items():
            for zombie in zombies:
                zombie.hit_bullet(bullet)

        # 去除死亡僵尸
        for zombie in self.zombies.copy():
            if not zombie.alive:
                self.zombies.remove(zombie)
                self.stats.score += self.settings.zombie_kill_score

                # 奖励
                if random() < self.settings.zombie_kill_bonus_change:
                    self.player.change_hp(int(self.player.hp_limit * 0.1))

        # 更新最高分
        self.stats.update()

        if not self.player.blink:
            # 计算僵尸碰撞玩家,闪烁时玩家无敌,不计算
            player_zombies_collisions = pygame.sprite.spritecollideany(
                self.player, self.zombies)

            if player_zombies_collisions:
                self.player.hit_zombie()

        # 判断游戏结束
        if self.player.alive == False:
            self.stats.game_over = True
            return

        # 去除出界子弹
        for bullet in self.bullets.copy():
            if not bullet.alive:
                self.bullets.remove(bullet)

        self.ui.update()
Ejemplo n.º 21
0
    def addZombie(self, c, address):

        for z in self.zombies:
            if z.address == address and not z.active():
                z.openedSocket.close()
                z.openedSocket = c
                return True

        zombie = Zombie(c, len(self.zombies), address)
        self.zombies.append(zombie)
        return True
Ejemplo n.º 22
0
	def update_tickspeed(self):
		self.ticks += 1
		if (self.ticks % 120) == 0:
			self.zombies.add(Zombie(self))
		if (self.ticks % 120) == 0:
			for zombie in self.zombies.copy():
				zombie.seconds -= 1
				if zombie.seconds == 0:
					self.zombies.remove(zombie)
			
		if self.ticks > 10000000:
			self.ticks = 1
Ejemplo n.º 23
0
    def createZombie(self):

        height = random.randrange(3)
        horizontal_position = random.randrange(2)
        new_zombie = Zombie()

        success = False

        while not success:
            ## position the zombies between invisible wall tiles and at proper heights
            if height == 0:
                new_zombie.bottom = 220

                if horizontal_position == 0:
                    new_zombie.center_x = random.randrange(30, 180)
                else:
                    new_zombie.center_x = random.randrange(760, 920)
            elif height == 1:
                new_zombie.bottom = 375
                if horizontal_position == 0:
                    new_zombie.center_x = random.randrange(130, 300)
                else:
                    new_zombie.center_x = random.randrange(640, 830)
            else:
                new_zombie.bottom = 527
                if horizontal_position == 0:
                    new_zombie.center_x = random.randrange(30, 240)
                else:
                    new_zombie.center_x = random.randrange(720, 920)

            hit_list = arcade.check_for_collision_with_list(
                new_zombie, self.enemy_list)

            if len(hit_list) == 0:
                success = True
            else:
                print('collision')

        # new_zombie.rect_outline = arcade.create_rectangle_outline(new_zombie.center_x, new_zombie.top + new_zombie.height * 0.1,
        #                                                new_zombie.hp_bar_width,
        #                                                new_zombie.hp_bar_height, new_zombie.hp_bar_outline_color, 2, 0)
        #
        # new_zombie.rect = arcade.create_rectangle_filled(new_zombie.center_pos, new_zombie.top + new_zombie.height * 0.1,
        #                                             (new_zombie.remaining_hp / new_zombie.total_hp) * new_zombie.hp_bar_width,
        #                                             new_zombie.hp_bar_height,
        #                                             new_zombie.hp_bar_color, 0)
        #
        # # self.hp_bar_list.append(rect_outline)
        # self.hp_bar_list.append(new_zombie.rect)
        # self.hp_bar_list.append(new_zombie.rect_outline)
        self.enemy_list.append(new_zombie)
        self.animated_list.append(new_zombie)
Ejemplo n.º 24
0
def enter():
    global boy
    boy = Boy()
    game_world.add_object(boy, 1)

    global zombie
    zombie = Zombie()
    game_world.add_object(zombie, 1)

    global balls
    balls = [Ball() for i in range(20)]
    game_world.add_objects(balls, 1)

    ground = Ground()
    game_world.add_object(ground, 0)
Ejemplo n.º 25
0
def main():
    my_hero = Hero()
    goblin = Goblin()
    zombie = Zombie()
    medic = Medic()
    shadow = Shadow()

    while (goblin.alive() or zombie.alive()) and my_hero.alive():
        my_hero.print_status()
        print()
        print("What do you want to do?")
        print("1. fight goblin")
        print("2. fight zombie")
        print("3. fight medic")
        print("4. fight shadow")
        print("5. do nothing")
        print("6. flee")
        print("> ",)
        user_input = input()
        if user_input == "1":
            goblin.print_status()
            # my_hero attacks goblin
            my_hero.attack(goblin)
            if goblin.health > 0:
            # Goblin attacks my_hero
                goblin.attack(my_hero)
        elif user_input == "2":
            zombie.print_status()
            my_hero.attack(zombie)
            zombie.attack(my_hero)
            zombie.alive()   
        elif user_input == "3":
            medic.print_status()
            my_hero.attack(medic)
            medic.attack(my_hero)
            medic.alive()
        elif user_input == "4":
            shadow.print_status()
            shadow.attack(my_hero)
            my_hero.attack(shadow)
            shadow.alive()
        elif user_input == "5":
            pass
        elif user_input == "6":
            print("Goodbye.")
            break
        else:
            print("Invalid input %r" % user_input)
Ejemplo n.º 26
0
def create_new_world():

    global playTime
    playTime = get_time()
    print(playTime)

    global boy
    boy = Boy()
    game_world.add_object(boy, 1)

    # fill here
    with open('zombie_data.json', 'r') as f:
        zombie_data_list = json.load(f)

    for data in zombie_data_list:
        zombie = Zombie(data['name'], data['x'], data['y'], data['size'])
        zombies.append(zombie)
        game_world.add_object(zombie, 6)

    global time_CreateMonster
    global time_UpdateCreateMonster

    global posX
    global posY
    global posOffsetX

    global Monster_Hp
    global Monster_Speed
    global Monster_Exp

    time_CreateMonster += 0.1

    if playTime >= 5:
        print('make_monster')
        for n in range(random.randint(0, 2 + 1), random.randint(3, 5 + 1)):
            PosX = posX + posOffsetX * n
            Monster_Hp = 100
            Monster_Speed = 400
            Monster_Exp = 50
            # x, y, scaleX, scaleY, hp, speed, radius, exp, filename
            GameObject = moster.CMonster(PosX, posY, 114, 76, Monster_Hp,
                                         Monster_Speed, 25, Monster_Exp,
                                         "Enemy01.png")

            game_world.add_object(GameObject, 8)
            # game_world.remove_object(GameObject)
            pass
Ejemplo n.º 27
0
    def setup(self):
        self.game_status = "Game is on"

        # Sprite lists
        self.player_list = arcade.SpriteList()
        self.zombie_list = arcade.SpriteList()
        self.bullet_list = arcade.SpriteList()

        self.player = Player()
        self.player.center_x = 50
        self.player.center_y = 50
        self.player_list.append(self.player)

        self.zombie = Zombie("images/zombie/zombie_stand.png", SPRITE_SCALING_PLAYER)
        self.zombie.center_x = 500
        self.zombie.center_y = 200
        self.zombie_list.append(self.zombie)
Ejemplo n.º 28
0
    def __init__(self, windowProps, evtSrc):
        #super(GamePhase, self).__init__()
        self.windowProps = windowProps
        self.evtSrc = evtSrc
        self.wallPolygons = xsect.PolygonList()

        #print vars(windowProps)

        self.gameElements = gameelements.GameElements(windowProps)
        self.gameElements.populateGame(GameAssets.Instance())

        ga = GameAssets.Instance()

        #Make tiled background
        self.grassBatch = pyglet.graphics.Batch()
        #spritelist is to prevent garbage collection
        self.spritelist = []

        graphics.tileRegion(self.grassBatch, self.spritelist,
                            ga.getImage('background'),
                            (0, windowProps.windowWidth),
                            (0, windowProps.windowHeight))

        #create walls
        self.wallImgBatch = pyglet.graphics.Batch()

        self.addWall((200, 250), (100, 400))
        self.addWall((600, 650), (100, 350))

        self.zombies = [
            Zombie(random.randint(500, 850), random.randint(100, 300))
            for i in range(0, 4)
        ]
        self.holes = [
            Hole(random.randint(250, 1800), random.randint(250, 850))
            for i in range(0, 3)
        ]
        self.fam = Fam(100, 100)

        w, h = windowProps.windowWidth, windowProps.windowHeight
        self.wallPolygons.add(xsect.Polygon((0, 0), (w, 0)))
        self.wallPolygons.add(xsect.Polygon((w, 0), (w, h)))
        self.wallPolygons.add(xsect.Polygon((w, h), (0, h)))
        self.wallPolygons.add(xsect.Polygon((0, h), (0, 0)))

        self.healthBar = healthbar.HealthBar(100, 100)
Ejemplo n.º 29
0
def enter():
    global boy
    boy = Boy()
    game_world.add_object(boy, 1)

    global zombie
    zombie = Zombie()
    game_world.add_object(zombie, 1)

    global balls
    global ball
    global num
    ball = Ball()
    balls = [Ball() for i in range(30)]
    for i in range(30):
        game_world.add_object(balls[i], 1)

    ground = Ground()
    game_world.add_object(ground, 0)
Ejemplo n.º 30
0
def enter():
    global boy
    boy = Boy()
    game_world.add_object(boy, 1)

    global zombie
    zombie = Zombie()
    game_world.add_object(zombie, 1)

    global ball
    for i in range(5):
        ball.append(BigBall())
    for i in range(5):
        ball.append(SmallBall())

    game_world.add_objects(ball, 1)

    ground = Ground()
    game_world.add_object(ground, 0)