Esempio n. 1
0
	def __init__(self, world, **kwargs):
		self.entities = []
		self.world = world

		assert self.world is not None, "Invalid world."

		self.offset_x = kwargs.get('offset_x', 0)
		self.offset_y = kwargs.get('offset_y', 0)
		self.width = kwargs.get('width', 300)
		self.height = kwargs.get('height', 300)

		self.top_left = dict(x = self.offset_x, y = self.offset_y)
		self.top_right = dict(x = self.offset_x + self.width, y = self.offset_y)
		self.bottom_left = dict(x = self.offset_x, y = self.offset_y + self.height)
		self.bottom_right = dict(x = self.offset_x + self.width, y = self.offset_y + self.height)

		self.background = []
		# populate background.. not efficient
		for _ in xrange(0, 100):
			x = random() * world.width
			y = random() * world.height
			color = (255, 255, 255, 255)
			vertices = [dict(x=x, y=y), dict(x=x + 1, y=y), dict(x=x+1, y=y+1),dict(x=x, y=y+1)]
			pos = dict(x=x,y=y)
			e = square(position=pos, color=color, size=1)
			self.background.append(e)
Esempio n. 2
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)