Esempio n. 1
0
    def __init__(self, width, height):
        #
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        # create pyglet window
        self.window = pyglet.window.Window()
        self.window.on_draw = self.on_draw
        self.window.on_key_press = self.on_key_press
        self.window.on_key_release = self.on_key_release
        self.window.width = width
        self.window.height = height
        self.key_pressed = []

        # create fps display 
        self.fps_display = pyglet.clock.ClockDisplay()

        # sync clock
        pyglet.clock.schedule_interval(self.tick, 1.0/60.0)   
        pyglet.clock.set_fps_limit(60)

        # create world
        world_width = 5000
        world_height = 5000
        self.world = world.world(world_width, world_height)

        # set background
        # self.background = pyglet.graphics.OrderedGroup(0)
        # self.background_image = pyglet.image.load('assets/space.png')
        # self.background_image.x_anchor = world_width / 2
        # self.background_image.y_anchor = world_height / 2
        #self.background_image.blit_into(img1,0,0,0)

        # create scene- match dimensions of the app window
        self.scene = scene.scene(self.world, offset_x=0, offset_y=0,width=width, height=height)

        # create physics engine
        self.engine = engine.engine()

        # throw some objects in there for now
        for _ in xrange(0, 100):
            theta = random() * 2 * math.pi
            pos = dict(x=random() * world_width, y=random() * world_height)
            s = square.square(position=pos, size=50)
            s.rotate(theta)
            self.world.add_entity(s)
Esempio n. 2
0
    def __init__(self, width, height):
        # create pyglet window
        self.window = pyglet.window.Window()
        self.window.on_draw = self.on_draw
        self.window.on_key_press = self.on_key_press
        self.window.on_key_release = self.on_key_release
        self.window.width = width
        self.window.height = height
        self.key_pressed = []

        # create fps display 
        self.fps_display = pyglet.clock.ClockDisplay()
        self.clock = 0

        # sync clock
        pyglet.clock.schedule_interval(self.tick, 1.0/60.0)   
        pyglet.clock.set_fps_limit(60)

        # create world
        world_width = 3000
        world_height = 3000
        self.world = world.world(world_width, world_height)

        # create scene- match dimensions of the app window
        self.scene = scene.scene(self.world, offset_x=0, offset_y=0,width=width, height=height)

        # create physics engine
        self.engine = engine.engine()

        self.sun = []
        self.moon = []
        self.earth = []

        # throw some objects in there for now
        moon_pos = dict(x=world_width/2, y=world_height/2)
        moon = circle(position=moon_pos, color=(100, 100, 100, 255), radius=400, num_vertices=50, z_index=100)
        self.world.add_entity(moon)
        self.moon.append(moon)

        moon_pos = dict(x=world_width/2, y=world_height/2)
        moon = circle(position=moon_pos, color=(200, 200, 200, 255), radius=380, num_vertices=50, z_index=101)
        self.world.add_entity(moon)
        self.moon.append(moon)

        sun_pos = dict(x=world_width/4, y=world_height/4)
        sun = circle(position=sun_pos, color=(255, 255, 0, 200), radius=100, num_vertices=50, z_index=3)
        self.world.add_entity(sun)
        self.sun.append(sun)

        sun_pos = dict(x=world_width/4, y=world_height/4)
        sun = circle(position=sun_pos, color=(255, 215, 0, 200), radius=110, num_vertices=50, z_index=2)
        self.world.add_entity(sun)
        self.sun.append(sun)

        sun_pos = dict(x=world_width/4, y=world_height/4)
        sun = circle(position=sun_pos, color=(255, 150, 0, 200), radius=120, num_vertices=50, z_index=1)
        self.world.add_entity(sun)
        self.sun.append(sun)

        earth_pos = dict(x=world_width/8, y=world_height/8)
        earth = circle(position=earth_pos, color=(255, 255, 255, 100), radius=42, num_vertices=50, z_index=100)
        self.world.add_entity(earth)
        self.earth.append(earth)

        earth_pos = dict(x=world_width/8, y=world_height/8)
        earth = circle(position=earth_pos, color=(27, 92, 174, 255), radius=38, num_vertices=50, z_index=101)
        self.world.add_entity(earth)
        self.earth.append(earth)

        earth_pos = dict(x=world_width/8 + 5, y=world_height/8 + 5)

        land = [dict(x=-10, y=30), dict(x=0,y=0), dict(x=15, y=7.5), dict(x=20, y=15), dict(x=22, y=10), dict(x=20,y=-15)]
        earth = entity(position=earth_pos, color=(27, 98, 22, 225), z_index=102, vertices=land)
        self.world.add_entity(earth)
        self.earth.append(earth)