Esempio n. 1
0
    def __init__(self, *arg, **kw):
        # +2 to allow server->master and master->server connection since enet
        # allocates peers for both clients and hosts. this is done at
        # enet-level, not application-level, so even for masterless-servers,
        # this should not allow additional players.
        self.max_connections = self.max_players + 2
        BaseProtocol.__init__(self, *arg, **kw)
        self.entities = []
        self.players = {}
        self.player_ids = IDPool()

        self._create_teams()

        self.world = world.World()
        self.set_master()

        # safe position LUT
        #
        # Generates a LUT to check for safe positions. The slighly weird
        # sorting is used to sort by increasing distance so the nearest spots
        # get chosen first
        # product(repeat=3) is the equivalent of 3 nested for loops
        self.pos_table = list(product(range(-5, 6), repeat=3))

        self.pos_table.sort(key=lambda vec: abs(vec[0] * 1.03) +
                            abs(vec[1] * 1.02) +
                            abs(vec[2] * 1.01))
Esempio n. 2
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with pyspades.  If not, see <http://www.gnu.org/licenses/>.

import sys
sys.path.append('..')

from pyspades.common import *
from pyspades.load import VXLData
from pyspades import world
from twisted.internet import reactor
from twisted.internet.task import LoopingCall

new_world = world.World(VXLData(open('../data/sinc0.vxl')))
nade = new_world.create_object(world.Character, Vertex3(20.0, 20.0, 5.0),
                               Vertex3())


def update():
    dt = 1 / 60.0
    new_world.update(dt)
    for instance in new_world.objects:
        position = instance.position
        print position.x, position.y, position.z


caller = LoopingCall(update)
caller.start(1 / 60.0, now=False)
reactor.run()
Esempio n. 3
0
             './feature_server/maps/pyspades.vxl'):
    try:
        fp = open(name, 'rb')
    except IOError:
        pass

if fp is None:
    raise SystemExit('no map file found')

map = VXLData(fp)
fp.close()

def on_fall(damage):
    print 'on fall:', damage

new_world = world.World()
new_world.map = map
character = new_world.create_object(world.Character,
    Vertex3(20.0, 20.0, 5.0), Vertex3(0.999992012978, 0.0, -0.00399998947978),
    on_fall)

window = pyglet.window.Window(width = 600, height = 600,
    resizable=True)

keyboard = key.KeyStateHandler()
window.set_handlers(keyboard)

def draw_quad(x1, y1, x2, y2, color = (255, 255, 255)):
    r, g, b = color
    glColor4ub(r, g, b, 255)
    glBegin(GL_QUADS)