def __init__(self, queue_dict):
        super().__init__(width=1280, height=720, caption='PACHINKO')
        # self.minimize()
        # self.config = gl.Config(double_buffer=True)
        # self.window = window.Window(1280, 720,config=self.config,caption='PACHINKO')
        self.queue_dict = queue_dict

        self.game_objects = {}
        self.object_batch = graphics.Batch()
        self.text_batch = graphics.Batch()
        self.spawn_circles()
Beispiel #2
0
    def setBattleField(self, playerArchive, playerInd, header):
        self._status = PLAYING
        self.batch = pyGra.Batch()
        self.ocean = mdl.gif(oceanBG, [0, 0], glb.wh, self.batch, gOcean)

        # Top Panel
        topPanelXY = [0, reduceTo(glb.wh[1], 90)]
        topPanelWH = [glb.wh[0], glb.wh[1] - topPanelXY[1]]
        mdl.quad(topPanelXY,
                 topPanelWH, [0, 0, 0, 120],
                 self.batch,
                 group=gTopPanel,
                 blend=True)
        self.topPanelXY = topPanelXY

        # Divider
        dividerWH = [15, topPanelXY[1]]
        dividerXY = [int(topPanelWH[0] / 2 - dividerWH[0] / 2), 0]
        mdl.quad(dividerXY,
                 dividerWH, [0, 0, 0, 120],
                 self.batch,
                 group=gTopPanel,
                 blend=True)

        self.setPlayerLayout(0, header[0], topPanelXY, topPanelWH)
        self.setPlayerLayout(1, header[1], topPanelXY, topPanelWH)

        self.extractPlayer1(playerArchive[0])
        self.extractPlayer2(playerArchive[1])

        self.setPlayerTurn(playerInd)
        glb.Aud.gameplay()
Beispiel #3
0
    def __init__(self, doctype, *args, **kwargs):
        super(TestWindow, self).__init__(*args, **kwargs)

        self.batch = graphics.Batch()
        self.document = doctype()
        self.layout = layout.IncrementalTextLayout(self.document,
            self.width, self.height, batch=self.batch)
Beispiel #4
0
    def __init__(self, game: 'Game', x: int, y: int):

        self.pos: vec2 = vec2(x, y)

        self.game = game

        self.batch = graphics.Batch()

        self.e_boxes = []

        for pos in self.game.world.room_map.keys():

            box = shapes.Rectangle(x + (pos.x * Map.size),
                                   y + ((Map.rows - pos.y) * Map.size),
                                   Map.size,
                                   Map.size,
                                   color=(50, 50, 50),
                                   batch=self.batch)
            self.e_boxes.append(box)

        self.e_player = shapes.Rectangle(x,
                                         y,
                                         Map.size,
                                         Map.size,
                                         color=(255, 255, 255),
                                         batch=self.batch)
    def on_enter(self):
        super(PythonInterpreterLayer, self).on_enter()

        vw, vh = cocos.director.director.get_window_size()

        # format the code
        self.document = document.FormattedDocument(self.content)
        self.document.set_style(
            0, len(self.document.text), {
                'font_name': self.cfg['code.font_name'],
                'font_size': self.cfg['code.font_size'],
                'color': self.cfg['code.color'],
            })

        self.batch = graphics.Batch()

        # generate the document
        self.layout = layout.IncrementalTextLayout(self.document,
                                                   vw,
                                                   vh,
                                                   multiline=True,
                                                   batch=self.batch)
        self.layout.anchor_y = 'top'

        self.caret = caret.Caret(self.layout, color=self.cfg['caret.color'])
        self.caret.on_activate()

        self.on_cocos_resize(vw, vh)

        self.start_of_line = len(self.document.text)
Beispiel #6
0
    def __init__(self, number):
        self.keysdown = []
        self.controllable = False
        self.entities = []
        self.level = number
        self.musicres = [[
            resource.media('epikboss_INTRO.ogg'),
            resource.media('epikboss_loop.wav')
        ]]
        self.musicplayer = media.Player()

        self.batch = graphics.Batch()
        self.expsfx = media.Player()
        self.expsfx.queue(World.explo)
        self.expsfx.eos_action = "pause"

        self.s1sfx = media.Player()
        self.s1sfx.queue(World.s1)
        self.s1sfx.eos_action = "pause"

        self.s2sfx = media.Player()
        self.s2sfx.queue(World.s2)
        self.s2sfx.eos_action = "pause"

        self.s3sfx = media.Player()
        self.s3sfx.queue(World.s3)
        self.s3sfx.eos_action = "pause"

        self.layers = (pyglet.graphics.OrderedGroup(0),
                       pyglet.graphics.OrderedGroup(1),
                       pyglet.graphics.OrderedGroup(2),
                       pyglet.graphics.OrderedGroup(3),
                       pyglet.graphics.OrderedGroup(4))

        self.ui = UI(self)
Beispiel #7
0
    def __init__(self,
                 width=1280,
                 height=720,
                 pathfinder=None,
                 queue=None,
                 semaphore=None):
        if pathfinder:
            self.win_size = {'width': width, 'height': height}
            self.pathfinder = pathfinder
            self.queue = queue
            self.semaphore = semaphore
        else:
            self.win_size = {'width': width, 'height': height}

        # create window
        super(PygletRenderer, self).__init__(width=self.win_size['width'],
                                             height=self.win_size['height'],
                                             resizable=True,
                                             fullscreen=False,
                                             caption="hiddenpath")
        self.set_minimum_size(32, 32)

        self.decorate_events()

        # setup the tick counter and Frames Per Second counter
        self.dt_count = clock.tick()
        self.fps_display = pyglet.clock.ClockDisplay()

        # rendering variables
        pyglet.options['debug_gl'] = False
        self.primitives = {
            'points': GL_POINTS,
            'square_points': GL_QUADS,
            'stripe': GL_LINE_STRIP,
            'line_loop': GL_LINE_LOOP,
            'quads': GL_QUADS
        }
        self.points_mode = {
            'mode': 'square_points',
            'points': 1,
            'square_points': 2
        }
        self.fov_y = 60.0
        self.camera = {
            'x_pan': 0.0,
            'y_pan': 0.0,
            'z_zoom': 1.0,
            'z_offset': 0,  # z coordinate at which primitives are drawn
            'zoom_factor': 1.1,
            'scene_scale': 0
        }
        self.set_camera_scale(self.points_mode[self.points_mode['mode']])

        # objects to draw
        self.const_drawings = []
        self.batches = {'const': pg.Batch()}

        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glEnable(GL_LINE_SMOOTH)
Beispiel #8
0
    def __init__(self):
        self.fps_display = clock.ClockDisplay()
        self.init_frame()
        self.frame = graphics.Batch()

        # -*- WARNING -*-
        # -*- Python magic -*-
        # Luckily this only has to be called once per renderer
        # and per program there is on average 1.0 renderer
        # (Actually it might be useful to have two of these...)
        # Finds all classes in Renderer that inherit Primitive
        # at some point, and for each, creates a copy for this
        # instance and sets the renderer attribute for each
        # to this instance.

        # This is just so we can do stuff like renderer.Rectangle()
        # without having to pass in the renderer because that doesn't
        # make any sense.
        # -*- Python magic -*-
        # -*- WARNING -*-

        for name in dir(self):
            cls = getattr(self, name)
            if hasattr(cls, '__mro__') and Primitive in cls.__mro__:
                setattr(self, name, type(name, (cls, ), dict(renderer=self)))
Beispiel #9
0
def resize(width, height):
    global imageWall
    global imageWallSprites
    imageWall = graphics.Batch()
    imageWallSprites = []
    for y in range(ceil(height / hexImg.height)):
        for x in range(ceil(width / hexImg.width)):
            imageWallSprites.append(sprite.Sprite(hexImg, hexImg.width*x, hexImg.height*y, batch=imageWall))
Beispiel #10
0
    def set_particles(self, points, colors):
        self.particles = []
        self.particle_batch = graphics.Batch()

        for point, color in zip(points, colors):
            new_p = self.particle_batch.add(1, gl.GL_POINTS, None,
                                            ('v2f/stream', point),
                                            ('c3B', color))
            self.particles += [new_p]
Beispiel #11
0
    def set_particles(self, particles):
        self.particles = []
        self.particle_batch = graphics.Batch()

        for p in particles:
            c = np.random.randint(126, 256)
            new_p = self.particle_batch.add(1, gl.GL_POINTS, None, 
                ('v2f/stream', p), ('c3B', (c, c, c)))
            self.particles += [new_p]
Beispiel #12
0
    def __init__(self, doctype, *args, **kwargs):
        super(TestWindow, self).__init__(*args, **kwargs)

        self.batch = graphics.Batch()
        self.document = doctype()
        self.layout = layout.IncrementalTextLayout(self.document,
                                                   self.width,
                                                   self.height,
                                                   batch=self.batch)
        self.document.set_style(0, len(self.document.text), {"bold": True})
Beispiel #13
0
 def __init__( self ) :
     global menu     ; menu = self
     self.initInfo() ; self.socket = CustomSocket.CustomSocket()
     super().__init__(
         self.mainMenuInfo [ 0 ], self.mainMenuInfo [ 1 ],
         batch   = pyGra.Batch(),
         group   = 0            ,
         bg  = 'bg' 
     )
     self.mainMenu() 
Beispiel #14
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # batch for efficient drawing
        self.batch = graphics.Batch()
        background = graphics.OrderedGroup(0)
        foreground = graphics.OrderedGroup(1)

        self.gamelayer = graphics.OrderedGroup(2)

        toplayer = graphics.OrderedGroup(3)

        # window size
        self.size = self.get_size()

        # start with empty asteroid set
        self.asteroids = set()

        # empty explosions set
        self.explosions = set()

        # background and moving foreground sprites
        self.background = physicalobject.ScaledMovingSprite(img=resources.background_image,
                screensize=self.size, batch=self.batch, group=background)
        self.debris = load.debris(screensize=self.size, batch=self.batch, group=foreground)
        self.splashscreen = load.ClickableSprite(hook_function=self.start,
                img=resources.splashscreen,
                x = self.size[0] / 2.0, y=self.size[1] / 2.0,
                batch=self.batch, group=toplayer)


        # player ship
        self.player = load.ship(screensize=self.size, batch=self.batch, group=self.gamelayer)

        self.score = 0
        self.lives = LIVES
        self.started = False

        self.fps_display = clock.ClockDisplay()

        # Lives and score labels
        self.lives_label = text.Label(font_size=20, text="Lives: %d" % self.lives, x=40, y=self.size[1]-40,
                    batch=self.batch, group=toplayer)
        self.score_label = text.Label(font_size=20, anchor_x='right', text="Score: %d" % self.score, x=self.size[0]-40,
                    y=self.size[1]-40, batch=self.batch, group=toplayer)

        # update frequency
        clock.schedule_interval(self.update, 1 / 120)

        # spawn a new asteroid each second
        clock.schedule_interval(self.spawn_asteroid, 1)

        # add event handlers to the ship and splashscreen
        self.push_handlers(self.player)
        self.push_handlers(self.splashscreen)
Beispiel #15
0
    def batch(self, batch):
        if self._batch == batch:
            return

        if batch is None:
            batch = graphics.Batch()

        for group, vlist in zip(self.groups, self.vertex_lists):
            self._batch.migrate(vlist, gl.GL_TRIANGLES, group, batch)

        self._batch = batch
Beispiel #16
0
    def image(self):
        """
		dummy method that returns the graphical representation
		of a random map tile as a vertex_list, just for debugging"""
        # http://packages.python.org/pyglet/api/pyglet.image.AbstractImage-class.html#blit_into
        global tex
        if not tex:
            tex = load_tex()
        if tex:
            #glEnable(tex.target)
            if self.batch is None:
                self.batch = gfx.Batch()
                glActiveTexture(GL_TEXTURE0 + 0)
                glBindTexture(tex.target, tex.id)
                txmx = tex.tex_coords[3] - tex.tex_coords[0]
                txmy = tex.tex_coords[7] - tex.tex_coords[4]
                for x in range(0, self.width):
                    for y in range(0, self.height):
                        tile = self.tiles[(x, y)]
                        val = 200
                        for cx, cy in [(1, 0), (1, 1)]:
                            nn = self.tiles.get((x + cx, y + cy), None)
                            if nn:
                                val += int(nn.elevation - tile.elevation)
                        cols = (max(0, min(255, val)), ) * 12
                        # schoen auch die ecken!
                        nn = [(tile.waterlevel, tile.vegetation)]
                        for d in ['e', 'ne', 'n']:
                            if d in tile.neighbours:
                                nn.append((tile.neighbours.get(d).waterlevel,
                                           tile.neighbours.get(d).vegetation))
                            else:
                                nn.append((None, 0))
                        # elevation?
                        cns = [(e > 1, w > 0) for (w, e) in nn]
                        # gras, wasser tex ids
                        gx = 15 - sum(
                            [int(v[0]) * 2**i for i, v in enumerate(cns)])
                        wx = sum([int(v[1]) * 2**i for i, v in enumerate(cns)])
                        coor = (wx * txmx / 16, gx * txmy / 16,
                                (wx + 1) * txmx / 16, gx * txmy / 16,
                                (wx + 1) * txmx / 16, (gx + 1) * txmy / 16,
                                wx * txmx / 16, (gx + 1) * txmy / 16)
                        self.batch.add_indexed(
                            4,
                            pyglet.gl.GL_TRIANGLES,
                            None,
                            [0, 1, 2, 0, 2, 3],
                            ('v2i', tile.get_bounds()),
                            ('t2f',
                             coor),  #(0., 0., .12, 0., .12, .12, 0., .12)),
                            ('c3B', cols))
        return self.batch
Beispiel #17
0
 def __init__(self):
     self.player, self.turnLbl = [None] * 2, [None] * 2
     self.batch = self.fadeQuad = None
     self._status = SETUP
     glb.Aud.baseSetup()
     self.pausePanel = sp.SidePanel(
         'Paused', [['Resume', self.unPause], ['Main Menu', Menu.display],
                    [], [], [], [], ['Cancel', self.unPause]],
         batch=pyGra.Batch(),
         group=Player.gCrosshair + 1,
         fullScreenBlend=True,
         bgObj=self)
Beispiel #18
0
    def __init__(self,
                 width,
                 height,
                 caption='Window Caption',
                 bg=(0, 0, 0),
                 ticktime=0,
                 *args,
                 **kwargs):
        """
        Window constructor.

        :type width: int
        :param width: width
        :type height: int
        :param height: height
        :type caption: str
        :param caption: caption
        :type bg: list(int * 3)
        :param bg: background color
        :type ticktime: float
        :param ticktime: interval between ticks in seconds, zero to disable ticking
        """
        super().__init__(width=width,
                         height=height,
                         caption=caption,
                         *args,
                         **kwargs)
        self.set_minimum_size(width, height)
        self.real_width, self.real_height = width, height

        self.set_bg(bg)

        self._batch = _graphics.Batch()
        self.screens = {}
        self.buttons = {}
        self.labels = {}
        self.fields = {}
        self.sliders = {}
        self.labelrows = {}
        self.boxes = {}
        self.valset = ValSet()

        self.focus = None
        self.hover = None
        self.mousedown = False

        self.set_vars()
        self.update_labels()

        self.ticktime = ticktime
        if ticktime > 0:
            _clock.schedule_interval(self.tick, ticktime)
        '''
Beispiel #19
0
 def __init__(
     self,
     turn: Turn,
     board: TicTacToeBoard,
     width=None,
     height=None,
     caption=None,
     resizable=False,
     style=None,
     fullscreen=False,
     visible=True,
     vsync=True,
     file_drops=False,
     display=None,
     screen=None,
     config=None,
     context=None,
     mode=None,
 ):
     super().__init__(turn, board)
     super(pyglet.window.Window, self).__init__(
         width=width,
         height=height,
         caption=caption,
         resizable=resizable,
         style=style,
         fullscreen=fullscreen,
         visible=visible,
         vsync=vsync,
         file_drops=file_drops,
         display=display,
         screen=screen,
         config=config,
         context=context,
         mode=mode,
     )
     self.square_batch: graphics.Batch = graphics.Batch()
     self.square_buttons: graphics.Batch = graphics.Batch()
     self.inp = ()
Beispiel #20
0
    def __init__(self, *args, **kwargs):
        super(TestWindow, self).__init__(*args, **kwargs)

        self.batch = graphics.Batch()
        self.document = text.decode_attributed(doctext)
        self.margin = 2
        self.layout = layout.IncrementalTextLayout(self.document,
            self.width - self.margin * 2, self.height - self.margin * 2,
            multiline=True,
            batch=self.batch)
        self.caret = caret.Caret(self.layout)
        self.push_handlers(self.caret)

        self.set_mouse_cursor(self.get_system_mouse_cursor('text'))
Beispiel #21
0
    def __init__(self,
                 document,
                 col_width,
                 width=None,
                 height=None,
                 dpi=None,
                 batch=None,
                 group=None):
        '''Create a text layout.

        :Parameters:
            `document` : `AbstractDocument`
                Document to display.
            `col_width` : int
                Fixed column width for glyphs
            `width` : int
                Width of the layout in pixels, or None
            `height` : int
                Height of the layout in pixels, or None
            `dpi` : float
                Font resolution; defaults to 96.
            `batch` : `Batch`
                Optional graphics batch to add this layout to.
            `group` : `Group`
                Optional rendering group to parent all groups this text layout
                uses.  Note that layouts with different
                rendered simultaneously in a batch.

        '''
        self.content_width = 0
        self.content_height = 0

        self.groups = {}
        self._init_groups(group)

        self._col_width = col_width
        if batch is None:
            batch = graphics.Batch()
            self._own_batch = True
        self.batch = batch

        self._width = width
        if height is not None:
            self._height = height

        if dpi is None:
            dpi = 96
        self._dpi = dpi
        self.document = document
Beispiel #22
0
 def draw(self):
     if self.path:
         if not self.batch:
             self.batch = gfx.Batch()
             coords = []
             for n in self.path:
                 coords += n.coord
             self.batch.add_indexed(len(self.path), pyglet.gl.GL_LINES,
                                    None, [
                                        j
                                        for i in range(len(self.path) - 1)
                                        for j in range(i, i + 2)
                                    ], ('v2i', tuple(coords)),
                                    ('c3B', (255, 0, 0) * len(self.path)))
         self.batch.draw()
Beispiel #23
0
    def __init__(self, menuWidth, menuHeight, x=0, y=0):
        '''Menu Width: width of menu
		   Menu Height: height of menu
		   #used as relative positioning for buttons
		   x: Position of menu Horizontally inside of the window
		   y: Position of menu Vertically inside of the window

		   buttonShift: the shift of buttons from mid height'''
        self.batch = graphics.Batch()
        self.title = None
        self.buttons = []
        self.width = menuWidth
        self.height = menuHeight
        self.x = x
        self.y = y
        self.buttonShift = 0
Beispiel #24
0
    def __init__(self, multiline, wrap_lines, msg, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.batch = graphics.Batch()
        self.document = text.decode_attributed(msg)
        self.margin = 2
        self.layout = layout.IncrementalTextLayout(
            self.document, (self.width - self.margin * 2),
            self.height - self.margin * 2,
            multiline=multiline,
            wrap_lines=wrap_lines,
            batch=self.batch)
        self.caret = caret.Caret(self.layout)
        self.push_handlers(self.caret)

        self.wrap_lines = wrap_lines

        self.set_mouse_cursor(self.get_system_mouse_cursor('text'))
Beispiel #25
0
    def __init__(self, parent, x, y, width, height, bg=(255, 255, 255), visible=True, active=True):
        """
        Screen constructor.

        :type x: int
        :param x: x coord
        :type y: int
        :param y: y coord
        :type width: int
        :param width: width
        :type height: int
        :param height: height
        :type valset: ValSet
        :param valset: the window's value set
        :type bg: list(int * 3)
        :param bg: background color
        :type visible: bool
        :param visible: determines if the screen is drawn
        :type active: bool
        :param active: determines if the screen is updated
        """

        self.parent = parent
        self.valset = parent.valset
        self.x = x
        self.y = y
        self.w = width
        self.h = height
        self.visible = visible
        self.active = active

        self._batch = _graphics.Batch()
        self._vertex_lists = {}
        self._vertices = {}
        self._colors = {}
        self._vertex_lists['bg'] = None
        for vtype in self._vertex_types:
            self._vertex_lists[vtype] = None
            self._vertices[vtype] = []
            self._colors[vtype] = []

        self.bg = bg
        self.set_bg(bg)
Beispiel #26
0
 def setPlayer(self, playerName, onConfirm):
     self.onConfirm = onConfirm
     self.batch = pyGra.Batch()
     self.ocean = mdl.gif(oceanBG, [0, 0], glb.wh, self.batch, gOcean)
     topPanelWHPerc = [30, 100]
     self.sidePanel = sp.SidePanel(
         playerName,
         whPercent=topPanelWHPerc,
         optionList=[['Place your ships'], ['Drag : To move'],
                     ['Right click : '], ['           To Rotate'], [],
                     ['Confirm', self.setupConfirmSeq],
                     ['Cancel', Menu.display]],
         batch=self.batch,
         group=gSidePanel)
     remainingWH = [reduceTo(glb.wh[0], 100 - topPanelWHPerc[0]), glb.wh[1]]
     wh = [600, 600]
     x = glb.wh[0] - remainingWH[0] + (remainingWH[0] - wh[0]) // 2
     y = (glb.wh[1] - wh[1]) // 2
     return Player.Player([x, y], wh, batch=self.batch, group=gPlayer)
Beispiel #27
0
    global particles
    for particle in particles:
        particle.dy += GRAVITY * dt
        vertices = particle.vertices
        vertices[0] += particle.dx * dt
        vertices[1] += particle.dy * dt
        if vertices[1] <= 0:
            particle.delete()
            particle.dead = True
    particles = [p for p in particles if not p.dead]


def loop(dt):
    update_particles(dt)
    for i in range(min(MAX_ADD_PARTICLES, MAX_PARTICLES - len(particles))):
        add_particles()

win = window.Window(vsync=False)
batch = graphics.Batch()
particles = list()


@win.event
def on_draw():
    win.clear()
    batch.draw()

clock = pyglet.app.event_loop.clock
clock.schedule(loop)
pyglet.app.run()
Beispiel #28
0
    def batch(self, batch=None, show_basis_vectors=True, show_endpoint_coordinates=True):
        ''' Returns a pyglet.graphics.Batch containing vertex lists for
            all vectors in self.vectors, the basis vectors, and gridlines. '''
        if batch is None:
            batch = graphics.Batch()

        if self.gridlines > 1:
            i_hat = self.basis[0]
            j_hat = self.basis[1]
            for i in range(0, self.gridlines):
                y = -j_hat + i * (j_hat*2/self.gridlines)
                v0 = self._transform_to_window_coordinates([-i_hat, y])
                v1 = self._transform_to_window_coordinates([i_hat, y])
                batch.add(2, gl.GL_LINES, None,
                    ('v2f', [v0[0], v0[1], v1[0], v1[1]]),
                    ('c4B', [64, 64, 64, 1]*2)
                )

            for j in range(0, self.gridlines):
                x = -i_hat + j * (i_hat*2/self.gridlines)
                v0 = self._transform_to_window_coordinates([x, -j_hat])
                v1 = self._transform_to_window_coordinates([x, j_hat])
                batch.add(2, gl.GL_LINES, None,
                    ('v2f', [v0[0], v0[1], v1[0], v1[1]]),
                    ('c4B', [64, 64, 64, 1]*2)
                )

        if show_basis_vectors is True:
            # Add basis vector lines to batch
            # i^
            v0 = self._transform_to_window_coordinates([0, 0])
            v1 = self._transform_to_window_coordinates([self.basis[0], 0])
            color = [1.0, 0.0, 0.0]
            batch.add(2, gl.GL_LINES, None,
                ('v2f', [v0[0], v0[1], v1[0], v1[1]]),
                ('c3f', color*2)
            )

            # j^
            v0 = self._transform_to_window_coordinates([0, 0])
            v1 = self._transform_to_window_coordinates([0, self.basis[1]])
            color = [0.0, 1.0, 0.0]
            batch.add(2, gl.GL_LINES, None,
                ('v2f', [v0[0], v0[1], v1[0], v1[1]]),
                ('c3f', color*2)
            )

        for vector in self.vectors:
            # Add vector lines to batch
            v0 = self._transform_to_window_coordinates(vector.origin)
            v1 = self._transform_to_window_coordinates(vector.endpoint)
            batch.add(2, gl.GL_LINES, None,
                ('v2f', [v0[0], v0[1], v1[0], v1[1]]),
                ('c3f', vector.color*2)
            )
            if show_endpoint_coordinates is True:
                # Display planespace coordinates
                x = round(vector.endpoint[0], 3)
                y = round(vector.endpoint[1], 3)
                text.Label(str(x) + ", " + str(y),
                            font_name='Consolas',
                            font_size=12,
                            x=v1[0]+10, y=v1[1]+10).draw()


        return batch
Beispiel #29
0
    def __init__(self,
                 width,
                 height,
                 interface_width,
                 window,
                 smell_score=100,
                 position=[0, 0],
                 title="abcdefghijklmno"):

        self.width = width
        self.height = height

        #iw = self.cnvCoor((interface_width,0))[0]
        iw = interface_width
        self.interface_width = iw
        ih = self.height
        self.position = position
        self.fore_batch = graphics.Batch()
        self.back_batch = graphics.Batch()
        background = pyglet.graphics.OrderedGroup(0)
        foreground = pyglet.graphics.OrderedGroup(1)
        self.objectlist = []
        self.strategy_activity = []
        self.detected_shroom = {}
        self.detected_square = {}
        self.detected_garden = {}

        self.interface_box = self.back_batch.add(
            4, GL_QUADS, background,
            ('v2f', (position[0], position[1], position[0] + iw, position[1],
                     position[0] + iw, position[1] + ih, position[0],
                     position[1] + ih)),
            ('c4B', (255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
                     255, 255, 255, 255, 255)))
        db = DBConnector()
        gui_textures = db.execute(
            "SELECT * FROM visualpropertypath WHERE type = 'gui texture'")
        self.texture_paths = {}
        for texture in gui_textures:
            self.texture_paths[texture[1]] = texture[3]
        del db

        # project title
        self.title = pyglet.text.Label(title,
                                       font_size=17,
                                       x=position[0] + 10,
                                       y=position[1] + ih - 10,
                                       width=iw - 20,
                                       anchor_x="left",
                                       anchor_y="top",
                                       color=(0, 0, 0, 255),
                                       align="center",
                                       multiline=True,
                                       batch=self.fore_batch)

        #code score
        self.scoreboard = pyglet.image.load(self.texture_paths['score'])
        self.scoreboard.anchor_y = self.scoreboard.height // 2
        self.scoreboard.anchor_x = self.scoreboard.width // 2
        self.score_pos = (position[0] + iw // 2,
                          position[1] + ih - self.scoreboard.height // 2 - 30 -
                          self.title.content_height)
        self.score = pyglet.text.Label("",
                                       font_size=42,
                                       x=self.score_pos[0] - 5,
                                       y=self.score_pos[1] + 17,
                                       anchor_x='center',
                                       anchor_y='center',
                                       color=(255, 255, 255, 255),
                                       batch=self.fore_batch)
        self.set_score(smell_score)

        # making detection strategies box
        self.strategies_box = GUIBox(
            8, ih // 2 - 12 - iw // 2 - self.title.content_height, iw - 16,
            iw + 14, self.back_batch, foreground)
        strategieslabel = pyglet.text.Label("Code Smell",
                                            font_name='Calibri',
                                            font_size=18,
                                            x=10,
                                            y=ih // 2 + iw // 2 + 8 -
                                            self.title.content_height,
                                            color=(0, 0, 0, 255),
                                            batch=self.fore_batch,
                                            group=foreground)
        self.checkbox = pyglet.image.load(self.texture_paths['checkbox empty'])
        self.checkedbox = pyglet.image.load(
            self.texture_paths['checkbox checked'])
#transform player's options
o_rock_pos = (950, 350)
o_paper_pos = (950, 250)
o_scissors_pos = (950, 150)
#transform big choice
players_choice_pos = (650, 200)
comps_choice_pos = (150, 200)
questionmark_pos = (50, 250)

its_a_tie = 0 # if the game is evaluated as "its a tie", the value turns 1
#image properties
play_image_size = (265, 215)
choice_image_size = (94, 76)

#players options
options_all = graphics.Batch()
image_dir = Path(__file__).parent / "images"
image_option_player_rock = image.load(image_dir / "small_choice_player-01.png")
image_option_player_paper = image.load(image_dir / "small_choice_player-02.png")
image_option_player_scissors = image.load(image_dir / "small_choice_player-03.png")
option_player_rock = sprite.Sprite(image_option_player_rock, o_rock_pos[0], o_rock_pos[1], batch = options_all)
option_player_paper = sprite.Sprite(image_option_player_paper, o_paper_pos[0], o_paper_pos[1], batch = options_all)
option_player_scissors = sprite.Sprite(image_option_player_scissors, o_scissors_pos[0], o_scissors_pos[1], batch = options_all)

# player choice
image_player_rock = image.load(image_dir / "choice_player-01.png")
image_player_paper = image.load(image_dir / "choice_player-02.png")
image_player_scissors = image.load(image_dir / "choice_player-03.png")
chosen_image = image_player_rock
player_start = sprite.Sprite(chosen_image, players_choice_pos[0], players_choice_pos[1], batch = options_all)