Exemple #1
0
def setup_physics():
    """Setup physics engine and initialise the world space."""
    SPACE.gravity = SETTINGS.physics.gravity
    objects = []
    for properties in yaml.load(open(SETTINGS.paths.objects, 'r'))['objects']:
        objects.append(helpers.rebunch(properties))
    for properties in objects:
        if properties.id == -1:
            logging.warning('attempt to create object with no id set')
        else:
            shape = helpers.create_shape(properties.physics)
            helpers.add_shape(SPACE, shape.body, shape)
            SHAPES[properties.id] = helpers.rebunch({
                'shape': shape,
                'properties': properties,
                'collisions': 0
            })
    SPACE.add_collision_handler(0, 1, 
            begin=lambda *x: helpers.add_collision(SHAPES[0], 1),
            separate=lambda *x: helpers.add_collision(SHAPES[0], -1))
Exemple #2
0
def setup_physics():
    """Setup physics engine and initialise the world space."""
    SPACE.gravity = SETTINGS.physics.gravity
    objects = []
    for properties in yaml.load(open(SETTINGS.paths.objects, 'r'))['objects']:
        objects.append(helpers.rebunch(properties))
    for properties in objects:
        if properties.id == -1:
            logging.warning('attempt to create object with no id set')
        else:
            shape = helpers.create_shape(properties.physics)
            helpers.add_shape(SPACE, shape.body, shape)
            SHAPES[properties.id] = helpers.rebunch({
                'shape': shape,
                'properties': properties,
                'collisions': 0
            })
    SPACE.add_collision_handler(
        0,
        1,
        begin=lambda *x: helpers.add_collision(SHAPES[0], 1),
        separate=lambda *x: helpers.add_collision(SHAPES[0], -1))
Exemple #3
0
def setup_bindings():
    """Load the key bindings from the configuration file."""
    for state in yaml.load(open(SETTINGS.paths.bindings, 'r'))['states']:
        state = helpers.rebunch(state)
        BINDINGS[state.name] = state
Exemple #4
0
#!/usr/bin/env python3

import helpers
import logging
import pyglet
import pyglet.gl as gl
import pymunk
import time
import yaml

SETTINGS = helpers.rebunch(yaml.load(open('config/settings.yaml', 'r')))
CONFIG = pyglet.gl.Config(
    sample_buffers=SETTINGS.graphics.opengl.sample_buffers,
    samples=SETTINGS.graphics.opengl.samples)
WINDOW = pyglet.window.Window(width=SETTINGS.graphics.window.width,
                              height=SETTINGS.graphics.window.height,
                              config=CONFIG)
FPS = pyglet.clock.ClockDisplay(color=(0.2, 0.2, 0.2, 1))
SPACE = pymunk.Space()
BINDINGS = helpers.rebunch({})
KEYS_PRESSED = helpers.rebunch({})
SHAPES = helpers.rebunch({})
POINTS = []


def main():
    """Setup and initialise the application."""
    setup_bindings()
    setup_graphics()
    setup_physics()
    pyglet.clock.schedule_interval(update, 1 / SETTINGS.graphics.fps)
Exemple #5
0
def setup_bindings():
    """Load the key bindings from the configuration file."""
    for state in yaml.load(open(SETTINGS.paths.bindings, 'r'))['states']:
        state = helpers.rebunch(state)
        BINDINGS[state.name] = state
Exemple #6
0
#!/usr/bin/env python3

import helpers
import logging
import pyglet
import pyglet.gl as gl
import pymunk
import time
import yaml


SETTINGS = helpers.rebunch(yaml.load(open('config/settings.yaml', 'r')))
CONFIG = pyglet.gl.Config(
    sample_buffers=SETTINGS.graphics.opengl.sample_buffers,
    samples=SETTINGS.graphics.opengl.samples)
WINDOW = pyglet.window.Window(width=SETTINGS.graphics.window.width,
                              height=SETTINGS.graphics.window.height,
                              config=CONFIG)
FPS = pyglet.clock.ClockDisplay(color=(0.2, 0.2, 0.2, 1))
SPACE = pymunk.Space()
BINDINGS = helpers.rebunch({})
KEYS_PRESSED = helpers.rebunch({})
SHAPES = helpers.rebunch({})
POINTS = []


def main():
    """Setup and initialise the application."""
    setup_bindings()
    setup_graphics()
    setup_physics()