コード例 #1
0
    def update(self, items_dict):
        self.tiles = []

        yn = 0

        n = 1

        for item, number in items_dict.items():
            point = Point(self.x, self.y - yn * self.dy)
            tilename = self.tilenames[item]

            width = self.surface.tiledict[tilename].width
            height = self.surface.tiledict[tilename].height

            shift = Point(width, height / 2)

            sprite = create_tile(point - shift, tilename)
            label = create_label("F-%s [%s]" % (n, number), point)

            self.tiles.append(label)
            self.tiles.append(sprite)

            self.slots[n] = item

            yn += 1
            n += 1
コード例 #2
0
 def choice_position(self, player, radius=7, start=False, ask_player=False):
     "выбирает случайную позицию, доступную для объекта"
     if not start:
         start = Point(self.size / 2, self.size / 2)
     else:
         start = start / TILESIZE
     lim = 1000
     counter = 0
     cords = set()
     timeout = self.size ** 2
     
     while len(cords) < timeout:
         
         position = start + Point(randrange(-radius, radius), randrange(-radius, radius))
         cord = position
         if cord not in cords:
             cords.add(cord)
             i, j =  cord.get()
             if 1 < i < self.size - 1 and 1 < j < self.size - 1:
                 
                 if not self.map[i][j] in player.BLOCKTILES:
                     #проверяем, подходит ли клетка объекту
                     position = position * TILESIZE
                     location = self.get_location(position)
                     exp = ask_player and player.choice_position(self, location, i ,j)
                     if counter > 1000 or exp:
                         shift = Point(randrange(TILESIZE-1), randrange(TILESIZE-1))
                         return position + shift
         counter += 1
         if counter > lim:
             lim *= 2
             if radius < self.size / 2:
                 radius = int(radius * 1.5)
     raise BaseException('world[%s].choice_position: no place for %s' % (self.name, player))
コード例 #3
0
ファイル: location.py プロジェクト: free-gate/pyglet_rpg
    def __init__(self, world, i, j):
        self.world = world
        self.i, self.j = i, j
        self.cord = Point(i, j)

        self.nears = []

        ActivityContainer.__init__(self)
        LocationObjects.__init__(self)
        LocationEvents.__init__(self)
コード例 #4
0
    def choice_position(cls, world, location, i, j):
        if len(world.tiles[Point(i, j)]):
            return False

        for ij in world.get_near_cords(i, j):
            for player in world.tiles[Point(*ij)]:
                if isinstance(player, AloneTree):
                    return True
        if chance(98):
            return False
        else:
            return True
コード例 #5
0
    def __init__(self, world, i, j):
        self.world = world
        self.i, self.j = i, j
        self.cord = Point(i, j)

        self.nears = []

        ActivityContainer.__init__(self)
        LocationObjects.__init__(self)
        LocationEvents.__init__(self)
コード例 #6
0
class Location(ActivityContainer, LocationEvents, LocationObjects):
    "небольшие локаци на карте, содержат ссылки на соседние локации и хранят ссылки на объекты и события"

    def __init__(self, world, i, j):
        self.world = world
        self.i, self.j = i, j
        self.cord = Point(i, j)

        self.nears = []

        ActivityContainer.__init__(self)
        LocationObjects.__init__(self)
        LocationEvents.__init__(self)

    def create_links(self):
        "создает сслыки на соседние локации"
        for i, j in near_cords:
            try:
                near_location = self.world.locations[self.i + i][self.j + j]
            except IndexError:
                pass
            else:
                self.nears.append(near_location)

    def update(self):
        LocationObjects.update(self)

    def complete_round(self):
        LocationObjects.complete_round(self)
        LocationEvents.complete_round(self)

    def set_activity(self):
        self.world.active_locations[self.cord.get()] = self

    def unset_activity(self):
        key = self.cord.get()
        if key in self.world.active_locations:
            del self.world.active_locations[key]
        else:
            print_log("key error", key)
コード例 #7
0
ファイル: location.py プロジェクト: free-gate/pyglet_rpg
class Location(ActivityContainer, LocationEvents, LocationObjects):
    "небольшие локаци на карте, содержат ссылки на соседние локации и хранят ссылки на объекты и события"

    def __init__(self, world, i, j):
        self.world = world
        self.i, self.j = i, j
        self.cord = Point(i, j)

        self.nears = []

        ActivityContainer.__init__(self)
        LocationObjects.__init__(self)
        LocationEvents.__init__(self)

    def create_links(self):
        "создает сслыки на соседние локации"
        for i, j in near_cords:
            try:
                near_location = self.world.locations[self.i + i][self.j + j]
            except IndexError:
                pass
            else:
                self.nears.append(near_location)

    def update(self):
        LocationObjects.update(self)

    def complete_round(self):
        LocationObjects.complete_round(self)
        LocationEvents.complete_round(self)

    def set_activity(self):
        self.world.active_locations[self.cord.get()] = self

    def unset_activity(self):
        key = self.cord.get()
        if key in self.world.active_locations:
            del self.world.active_locations[key]
        else:
            print_log('key error', key)
コード例 #8
0
    def __init__(self, game, name):
        PersistentWorld.__init__(self, name)
        self.game = game
        self.name = name
        
        self.teleports = [Point(self.size / 2, self.size / 2)]
        
        self.location_size = self.size / LOCATIONSIZE + 1
        
        self.tiles = defaultdict(lambda: set())
        
        self.players = {}
        self.static_objects = {}
        
        self.locations = []
        self.active_locations = {}
        
        self.create_locations()
        self.create_links()

        init = imp.load_source('init', WORLD_PATH % name + 'init.py')
        self.generate_func = init.generate
        self.init_func =  init.init
コード例 #9
0
    def unpack(cls,land,observed):
        land =  [(Point(x,y), str(tilename)) for x,y, tilename in land]
        observed =  [(i,j) for (i,j) in observed]

        return land, observed
コード例 #10
0
ファイル: gui_lib.py プロジェクト: free-gate/pyglet_rpg
 def __init__(self):
     self.shift = Point(0, 0)
     self.tiles = []
コード例 #11
0
 def unpack(cls, wold_name, world_size, xy, background):
     position = Point(*xy)
     return wold_name, world_size, position, background
コード例 #12
0
 def unpack(cls, x,y):
     move_vector = Point(x,y)
     return move_vector
コード例 #13
0
 def unpack(cls, x_y, destination):
     x,y = x_y
     return (Point(x,y), destination)
コード例 #14
0
 def unpack(cls, x,y):
     return Point(x,y)
コード例 #15
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from config import *

from weakref import proxy, ProxyType

from engine.enginelib.meta import ActiveState
from share.mathlib import Point

#список инкременаторов к индексу на соседние локации
nears = ((-1, 1), (0, 1), (1, 1), (-1, 0), (1, 0), (-1, -1), (0, -1), (1, -1))

near_cords = [Point(i, j) for i, j in nears]


class ObjectContainer:
    proxy_list = ()

    def __init__(self):
        for p_type in self.proxy_list:
            assert isinstance(p_type, type)
        self.__forproxy__ = {
            p_type: p_type.__name__
            for p_type in self.proxy_list
        }
        self.proxy_dicts = {
            type_name: {}
            for type_name in self.__forproxy__.values()
        }
        self.new_players = False
コード例 #16
0
 def on_mouse_release(self, x, y, button, modifiers):
     for surface in self.surfaces:
         if Point(x, y) in surface:
             surface.on_mouse_release(x, y, button, modifiers)
コード例 #17
0
 def __init__(self, height, width):
     Window.__init__(self, height, width)
     self.clock_setted = False
     self.complete = 0
     self.center = Point(height / 2, width / 2)
コード例 #18
0
 def on_mouse_press(self, x, y, button, modifiers):
     "перехватывавем нажатие левой кнопки мышки"
     for surface in self.surfaces:
         if Point(x, y) in surface:
             surface.on_mouse_press(x, y, button, modifiers)
コード例 #19
0
ファイル: objects_lib.py プロジェクト: free-gate/pyglet_rpg
 def force_complete(self):
     if self.vector:
         self.position += self.vector
         self.vector = Point(0, 0)
コード例 #20
0
ファイル: objects_lib.py プロジェクト: free-gate/pyglet_rpg
 def move(self, xy):
     vector = Point(*xy)
     self.vector += vector
     if self.vector:
         self.moving = True
コード例 #21
0
ファイル: objects_lib.py プロジェクト: free-gate/pyglet_rpg
 def __init__(self, frames=1):
     Animated.__init__(self)
     self.moving = False
     self.vector = Point(0, 0)
     self.create_animation('moving', 'move', frames, 2)
コード例 #22
0
 def choice_position(cls, world, location, i, j):
     if len(world.tiles[Point(i, j)]):
         return False
     else:
         return True
コード例 #23
0
 def unpack(cls, players):
     players = dict([(gid, (name, o_type, Point(x,y), args))
         for gid, (name, o_type, (x,y), args) in players.items()])
     return players
コード例 #24
0
 def on_mouse_drag(self, x, y, dx, dy, button, modifiers):
     for surface in self.surfaces:
         if Point(x, y) in surface:
             surface.on_mouse_drag(x, y, dx, dy, button, modifiers)
コード例 #25
0
 def unpack_events(cls, events):
     return [(name, object_type,  Point(x,y), timeout, action, args)
         for (name, object_type, (x,y), timeout, action, args) in events]
コード例 #26
0
ファイル: location.py プロジェクト: free-gate/pyglet_rpg
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from config import *

from weakref import proxy, ProxyType

from share.mathlib import Point
from engine.enginelib.meta import DynamicObject, StaticObject, ActiveState, Solid
from engine.world.objects_containers import ActivityContainer

from share.logger import print_log

#список инкременаторов к индексу на соседние локации
near_cords = [
    cord.get()
    for cord in (Point(-1, 1), Point(0, 1), Point(1, 1), Point(-1, 0),
                 Point(1, 0), Point(-1, -1), Point(0, -1), Point(1, -1))
]


class LocationEvents:
    "функционал локации для работы с событиями"

    def __init__(self):
        self.events = []
        self.static_events = []

        self.new_events = False
        self.new_static_events = False

        self.timeouted_events = []
コード例 #27
0
 def draw_label(self):
     label = create_label('%d/%d' % (self.hp, self.hp_value), self.position+Point(0, self.sprite.height))
     return [label]
コード例 #28
0
 def __init__(self, x, y, width, height):
     self.x, self.y = x, y
     self.width = width
     self.height = height
     self.center = Point(width / 2, height / 2)
     self.elements = []
コード例 #29
0
 def on_mouse_motion(self, x, y, dx, dy):
     for surface in self.surfaces:
         if Point(x, y) in surface:
             surface.on_mouse_motion(x, y, dx, dy)