예제 #1
0
def draw_loop(player, level_map, paper_map, map_console, main_console,
              message_console, status_console, entities, player_state):
    fov = player.fov(level_map, entities)
    re.draw_map(level_map, paper_map, map_console, fov)
    re.draw_all(level_map, map_console, entities, fov)
    re.draw_con(main_console, map_console,
                main_console.width - map_console.width, 0)
    re.draw_con(main_console, status_console, 0, 0)
    re.draw_con(main_console, message_console, status_console.width,
                main_console.height - message_console.height)
    tcod.console_flush()
    re.clear_all(level_map, map_console, entities)
                walls_1.update(walls_2)
                floor_1.update(floor_2)
                walls_1.update(walls_3)
                floor_1.update(floor_3)
                walls_1.update(walls_4)
                floor_1.update(floor_4)

                render.draw_world(walls_1, floor_1)

                npc_1.draw(player.angle, player.player_coords, walls_1, True)
                npc_2.draw(player.angle, player.player_coords, walls_1, True)
                npc_3.draw(player.angle, player.player_coords, walls_1, True)
                npc_4.draw(player.angle, player.player_coords, walls_1, True)
                npc_0.draw(player.angle, player.player_coords, walls_1, False)

                render.draw_map(map.map_of_tiles, player.real_x, player.real_y,
                                player.sin_a, player.cos_a)
                render.display_fps(clock)

                if render.fps > 5:
                    fps.append(render.fps)

                # pygame.display.update()
                pygame.display.flip()
                clock.tick(SETTINGS.FPS)

            min_fps = min(fps)
            fps = sum(fps) / len(fps)

            print(
                f'Time: {time.time() - t}, Avg. FPS: {fps}, min FPS: {min_fps}'
            )
예제 #3
0
    def do_trap(self, map, paper_map, main_console, map_console, fov,
                message_console, messages, entities):
        trap_type = self.traptype
        if trap_type == 0:
            radius = 2
            for z in drawval.CHARS["floor_give"]:
                lc = 0
                for x in range(self.x - radius, self.x + radius + 1):
                    for y in (self.y + lc, self.y - lc):
                        if x > -1 and x < map.width and y > -1 and y < map.height:
                            if map.t_[x][y].type == "floor":
                                map.t_[x][y].char = z
                                map.t_[x][y].fg = drawval.COLORS["floor-bg"]
                                map.t_[x][y].bg = drawval.COLORS["pit-bg"]
                    if x < self.x:
                        lc += 1
                    if x > self.x - 1:
                        lc -= 1

                fov = entities[0].fov(map, entities)
                re.draw_map(map, paper_map, map_console, fov)
                re.draw_all(map, map_console, entities, fov)
                re.draw_con(main_console, map_console,
                            main_console.width - map_console.width, 0)
                re.draw_con(main_console, message_console,
                            main_console.width - map_console.width,
                            main_console.height - message_console.height)
                tcod.console_flush()
                re.clear_all(map, map_console, entities)
                sleep(0.050)

            lc = 0
            for x in range(self.x - radius, self.x + radius + 1):
                for y in (self.y + lc, self.y - lc):
                    if x > -1 and x < map.width and y > -1 and y < map.height:
                        if map.t_[x][y].type == "floor":
                            map.t_[x][y] = mp.newtile(cx.TERRAIN["pit"])
                if x < self.x:
                    lc += 1
                if x > self.x - 1:
                    lc -= 1
            map.walls_and_pits()

        elif trap_type == 1:
            fov = entities[0].fov(map, entities)
            re.draw_map(map, paper_map, map_console, fov)
            re.draw_all(map, map_console, entities, fov)
            re.draw_con(main_console, map_console,
                        main_console.width - map_console.width, 0)
            re.draw_con(main_console, message_console,
                        main_console.width - map_console.width,
                        main_console.height - message_console.height)
            tcod.console_flush()
            re.clear_all(map, map_console, entities)
            sleep(0.080)
            trapeffect_blocked = False
            while trapeffect_blocked == False:
                trapeffect_blocked = entities[0].move(entities[0].lastx,
                                                      entities[0].lasty, map,
                                                      entities, map_console,
                                                      message_console,
                                                      messages, True)
                fov = entities[0].fov(map, entities)
                re.draw_map(map, paper_map, map_console, fov)
                re.draw_all(map, map_console, entities, fov)
                re.draw_con(main_console, map_console,
                            main_console.width - map_console.width, 0)
                re.draw_con(main_console, message_console,
                            main_console.width - map_console.width,
                            main_console.height - message_console.height)
                tcod.console_flush()
                re.clear_all(map, map_console, entities)
                sleep(0.0075)

        elif trap_type == 2:
            fov = entities[0].fov(map, entities)
            re.draw_map(map, paper_map, map_console, fov)
            re.draw_all(map, map_console, entities, fov)
            re.draw_con(main_console, map_console,
                        main_console.width - map_console.width, 0)
            re.draw_con(main_console, message_console,
                        main_console.width - map_console.width,
                        main_console.height - message_console.height)
            tcod.console_flush()
            re.clear_all(map, map_console, entities)
            sleep(0.080)
            entities[0].lastx = entities[0].lastx * -1
            entities[0].lasty = entities[0].lasty * -1
            trapeffect_blocked = False
            while trapeffect_blocked == False:
                trapeffect_blocked = entities[0].move(entities[0].lastx,
                                                      entities[0].lasty, map,
                                                      entities, map_console,
                                                      message_console,
                                                      messages, True)
                fov = entities[0].fov(map, entities)
                re.draw_map(map, paper_map, map_console, fov)
                re.draw_all(map, map_console, entities, fov)
                re.draw_con(main_console, map_console,
                            main_console.width - map_console.width, 0)
                re.draw_con(main_console, message_console,
                            main_console.width - map_console.width,
                            main_console.height - message_console.height)
                tcod.console_flush()
                re.clear_all(map, map_console, entities)
                sleep(0.0075)

        elif trap_type == 3:

            px = self.x * -1
            py = self.y * -1
            while map.t_[self.x + px][self.y + py].type != "floor":
                randz = randint(0, 4)
                if randz == 0:
                    px = 1
                    py = 0
                elif randz == 1:
                    px = -1
                    py = 0
                elif randz == 2:
                    px = 0
                    py = -1
                elif randz == 3:
                    px = 0
                    py = 1

            boulder = Entity(self.x + px,
                             self.y + py,
                             char_input=drawval.CHARS["boulder"],
                             fg="boulder-fg",
                             bg=cx.TERRAIN["floor"]["bg"],
                             hp=100,
                             speed=100,
                             faction=cx.Faction.Enemy,
                             draw_order=cx.DrawOrder.NPC,
                             block_m=True,
                             dispname="Boulder")
            boulder.persistent_x = px * -1
            boulder.persistent_y = py * -1
            entities.append(boulder)
            boulder.block_j = True
            boulder.block_s = True
            boulder.stats.at = 100
            boulder.stats.df = 3
            fov = entities[0].fov(map, entities)
            re.draw_map(map, paper_map, map_console, fov)
            re.draw_all(map, map_console, entities, fov)
            re.draw_con(main_console, map_console,
                        main_console.width - map_console.width, 0)
            re.draw_con(main_console, message_console,
                        main_console.width - map_console.width,
                        main_console.height - message_console.height)
            tcod.console_flush()
            re.clear_all(map, map_console, entities)
            sleep(0.080)

        self.trapstate = -1
        for event in tcod.event.wait(0.5):
            return
예제 #4
0
 def spawn(self):
     return render.draw_map(self.user.map_pos, self.user.sprite)