Ejemplo n.º 1
0
    def render_map_panel(self):
        # calculate offsets on scrolling map
        position = self.engine.positions.find(self.engine.player)
        tilemap = self.engine.tilemaps.find(eid=position.map_id)
        if tilemap.width < self.map_width:
            cam_x = 0
        else:
            cam_x = scroll(position.x, self.map_width, tilemap.width)
        x0, x1 = cam_x, self.map_width + cam_x
        if tilemap.height < self.map_height:
            cam_y = 0
        else:
            cam_y = scroll(position.y, self.map_height, tilemap.height)
        y0, y1 = cam_y, self.map_height + cam_y

        self.render_map(position.map_id, cam_x, cam_y, x0, x1, y0, y1)

        tiles = {
            (position.x, position.y): visibility
            for _, (position, visibility
                    ) in join(self.engine.positions, self.engine.visibilities)
            if visibility.level > 1
        }
        self.render_items(tiles, position.map_id, cam_x, cam_y, x0, x1, y0, y1)
        while True:
            self.render_units(tiles, position.map_id, cam_x, cam_y, x0, x1, y0,
                              y1)
            if not self.engine.effects.components:
                break
            # render effects
            self.render_effects(tiles, position.map_id, cam_x, cam_y, x0, x1,
                                y0, y1)
            self.engine.effects.components.clear()
Ejemplo n.º 2
0
    def process(self):
        # should only process the player entity on its turn
        g = join(self.engine.turns, self.engine.positions)
        for eid, (_, position) in g:
            if eid != self.engine.player:
                break
            tilemap = self.engine.tilemaps.find(position.map_id)
            camera = self.engine.cameras.find(eid)
            
            # map offsets if map is bigger than current camera viewport
            x0 = scroll(player.x, camera.width, tilemap.width)
            x1 = x0 + camera.width
            y0 = scroll(player.y, camera.height, tilemap.height)
            y1 = y0 + camera.height

            # sets tiles in range of unit to lighted
            # i.e. tile(X,Y).level > 0
            # they will be saved by the engine to be used during rendering
            cast_light(self.engine, x0, x1, y0, y1)
Ejemplo n.º 3
0
def main(screen):
    curses.curs_set(0)
    world = create_field_matrix(100, 50, '#')
    w, h = len(world[0]), len(world)
    px, py = 0, 0

    while True:
        camera_x = scroll(px, 80, w)
        camera_y = scroll(py, 25, h)
        for y in range(camera_y, camera_y + 25):
            for x in range(camera_x, camera_x + 80):
                c = world[y][x]
                try:
                    screen.addch(y - camera_y, x - camera_x, c)
                except:
                    screen.insch(y - camera_y, x - camera_x, c)

        try:
            screen.addch(py - camera_y, px - camera_x, '@')
        except:
            screen.insch(px - camera_y, py - camera_x, '@')

        screen.refresh()
        c = screen.getch()
        if c == ord('q') or c == 27:
            break
        elif c == curses.KEY_UP:
            py -= 1
        elif c == curses.KEY_DOWN:
            py += 1
        elif c == curses.KEY_LEFT:
            px -= 1
        elif c == curses.KEY_RIGHT:
            px += 1
        px = min(99, max(0, px))
        py = min(49, max(0, py))
Ejemplo n.º 4
0
clpy = []
# clc = []
cl2py = []
# cl2c = []
iters = 10
n = copy.deepcopy(m)
combinations = (
    (clpy, cast_light, py_raycast), 
    (cl2py, cast_light2, py_raycast2),
    # (clc, cast_light, c_raycast),
    # (clc, cast_light2, c_raycast)
)
while True:

    # get camera offsets
    off_x = scroll(p.x, 57, x)
    off_y = scroll(p.y, 17, y)

    for recorder, caster, raycaster in combinations:
        # do some calculations
        t = time.time()
        caster(
            engine, 
            off_x, 
            57 + off_x, 
            off_y, 
            17 + off_y, 
            raycaster=raycaster
        )
        s = time.time()
Ejemplo n.º 5
0
    def render(self):
        player = self.engine.positions.find(self.engine.player)
        tilemap = self.engine.tilemaps.find(player.map_id)
        # calculate camera bounds on scrolling map
        if tilemap.width < self.width:
            self.cam_x = 0
        else:
            self.cam_x = scroll(player.x, self.width, tilemap.width)
        x0, x1 = self.cam_x, self.width + self.cam_x
        if tilemap.height < self.height:
            self.cam_y = 0
        else:
            self.cam_y = scroll(player.y, self.height, tilemap.height)
        y0, y1 = self.cam_y, self.height + self.cam_y

        # do line of sight calculations
        cast_light(self.engine, x0, x1, y0, y1)

        start = time.time()
        # draw map first, then items, then units
        for visibility, position, render in join_drop_key(
                self.engine.visibilities, self.engine.positions,
                self.engine.renders):
            if (visibility.level > 0 and player.map_id == position.map_id
                    and x0 <= position.x < x1 and y0 <= position.y < y1):
                c = render.color if visibility.level > 1 else "darkest grey"
                self.add_string(position.x - self.cam_x,
                                position.y - self.cam_y, render.char, c)

        self.engine.entities_in_view.clear()
        for eid, (health, position, render,
                  info) in join(self.engine.healths, self.engine.positions,
                                self.engine.renders, self.engine.infos):
            if (position.map_id == self.engine.world.id
                    and (position.x, position.y) in self.engine.tiles_in_view
                    and x0 <= position.x < x1 and y0 <= position.y < y1):
                if self.engine.player != eid:
                    self.engine.entities_in_view.add(eid)
                self.add_string(position.x - self.cam_x,
                                position.y - self.cam_y, render.char,
                                render.color)

        # # draw items
        # self.render_items(visible_tiles, player.map_id, cam_x, cam_y, x0, x1, y0, y1)
        # while True:
        #     # draw units
        #     self.render_units(visible_tiles, player.map_id, cam_x, cam_y, x0, x1, y0, y1)
        #     if not self.engine.effects.components:
        #         break
        #     if time.time() - start > (1 / 23):
        #         self.engine.effects.components.clear()
        #         break
        #     # draw effects
        #     self.render_effects(tiles, player.map_id, cam_x, cam_y, x0, x1, y0, y1)
        #     self.update_effects()

        if self.engine.mode is not GameMode.NORMAL:
            # self.render_cursor(visible_tiles, player.map_id, cam_x, cam_y, x0, x1, y0, y1)
            position = self.engine.positions.find(self.engine.cursor)
            if self.engine.mode in (GameMode.LOOKING, GameMode.DEBUG):
                self.add_string(position.x - self.cam_x,
                                position.y - self.cam_y, 'X')
            elif self.engine.mode == GameMode.MAGIC:
                cursor = self.engine.cursors.find(self.engine.cursor)
                spellname = Spell.identify[cursor.using]
                render = self.engine.renders.shared[spellname][0]
                if spellname == 'fireball':
                    for xx, yy in diamond():
                        x = position.x + xx
                        y = position.y + yy
                        if (x, y) not in self.engine.tiles_in_view:
                            continue
                        self.add_string(x - cam_x, y - cam_y, render.char,
                                        render.color)