示例#1
0
    def __init__(self, *args, **kwargs):

        #Let all of the arguments pass through
        self.win = window.Window.__init__(self, *args, **kwargs)

        self.maxaliens = 50  # max num of aliens simultaneously on the screen

        clock.schedule_interval(self.create_alien, 0.5)
        clock.schedule_interval(self.update, 1.0 / 30)  # update at FPS of Hz

        #clock.set_fps_limit(30)

        # setting text objects
        ft = font.load('Tahoma', 20)  #Create a font for our FPS clock
        self.fpstext = font.Text(ft, y=10)  # object to display the FPS
        self.score = font.Text(ft,
                               x=self.width,
                               y=self.height,
                               halign=pyglet.font.Text.RIGHT,
                               valign=pyglet.font.Text.TOP)

        # reading and saving images
        self.spaceship_image = pyglet.image.load(
            'datas/game-resources/ship3.png')
        self.alien_image = pyglet.image.load(
            'datas/game-resources/invader.png')
        self.bullet_image = pyglet.image.load(
            'datas/game-resources/bullet_white_16.png')

        # create one spaceship
        self.spaceship = Spaceship(self.spaceship_image, x=50, y=50)

        self.aliens = []  # list of Alien objects
        self.bullets = []  # list of Bullet objects
示例#2
0
    def render(self):
        fnt = font.load(self.font_name, self.font_size)

        w = self.window.width
        h = self.window.height

        self.labels = [
            font.Text(fnt,
                      'This text is top-left aligned  with several lines.',
                      0,
                      h,
                      width=w,
                      halign='left',
                      valign='top'),
            font.Text(fnt,
                      'This text is centered in the middle.',
                      0,
                      h // 2,
                      width=w,
                      halign='center',
                      valign='center'),
            font.Text(
                fnt,
                'This text is aligned to the bottom-right of the window.',
                0,
                0,
                width=w,
                halign='right',
                valign='bottom'),
        ]
示例#3
0
    def on_enter(self):
        super(ControlLayer, self).on_enter()

        ft_title = font.load("Arial", 32)
        ft_subtitle = font.load("Arial", 18)
        ft_help = font.load("Arial", 16)

        self.text_title = font.Text(ft_title,
                                    "Transition Demos",
                                    x=5,
                                    y=480,
                                    anchor_x=font.Text.LEFT,
                                    anchor_y=font.Text.TOP)

        self.text_subtitle = font.Text(
            ft_subtitle,
            transition_list[current_transition].__name__,
            x=5,
            y=400,
            anchor_x=font.Text.LEFT,
            anchor_y=font.Text.TOP)

        self.text_help = font.Text(ft_help,
                                   "Press LEFT / RIGHT for prev/next example, "
                                   "ENTER to restart example",
                                   x=320,
                                   y=20,
                                   anchor_x=font.Text.CENTER,
                                   anchor_y=font.Text.CENTER)
示例#4
0
    def __init__(self, level):
        super(CutScene3, self).__init__(level)

        self.skybox = level.skybox_space

        self.camera_pos = Vec3(100, 600, 1400)
        self.camera_pitch = -25
        self.camera_heading = 30
        self.camera_heading_speed = -1
        self.station_pos = Vec3()
        self.station_vel = Vec3()
        self.station_accel = Vec3()
        self.station_accel_accel = Vec3()

        self.time = 0

        self.credit_line = -1
        self.subcredit_line = -1
        self.credit_time = 2.
        self.subcredit_time = 2.
        self.max_credit_time = 2.
        self.max_subcredit_time = 2.
        self.subcredits = []

        label1_font = font.load('Arial', 36., bold=True)
        self.label1 = font.Text(label1_font, '', color=(1, 1, 1, 1))
        label2_font = font.load('Arial', 24., bold=True)
        self.label2 = font.Text(label2_font, '', color=(1, 1, 1, 1))
示例#5
0
 def on_draw(self):
     self.window.clear()
     glLoadIdentity()
     glTranslatef(14,0,0)
     if self.inRoom:
         glPushMatrix()
         glTranslatef(self.room.x, self.room.y - self.room.bounce, 0)
         self.room.draw()
         self.player.draw()
         glPopMatrix()
     # player health bar.
     if self.playing:
         x,y=10,self.window.height-10
         if self.player.health > 0:
             fillRect(x+3,y-12,1+self.player.health*2,9,0.25,1,0.25)
         self.hbar.draw()
         # room name.
         self.title.draw()
         self.roomnum.draw()
     else:
         font.Text(self.hfont, "Belle of", x=90, y=320).draw()
         font.Text(self.hfont, "Nine Fables", x=120, y=270).draw()
         x,y = 200,200
         for item in ("Continue","New Game","Instructions","Exit"):
             font.Text(self.font, item, x=x, y=y).draw()
             y -= 24
         font.Text(self.font, ">", x=x-20, y=200+2-self.menuIndex*24).draw()
示例#6
0
    def __init__(self, *args, **kwargs):

        #Let all of the arguments pass through
        self.win = window.Window.__init__(self, *args, **kwargs)
        
        clock.schedule_interval(self.update, 1.0/30) # update at 30 Hz
        clock.schedule_interval(self.create_alien, 1.0/2) # update at 5 Hz
        
        
        # setting text objects
        ft = font.load('Tahoma', 20)         #Create a font for our FPS clock
        self.fpstext = font.Text(ft, y=10)   # object to display the FPS
        
        self.score = font.Text(ft, x=self.width, y=self.height, 
                               halign=pyglet.font.Text.RIGHT, 
                               valign=pyglet.font.Text.TOP)
                               
        # loading image
        self.spaceship_image = pyglet.image.load('images/ship3.png')
        self.spaceship = Spaceship(self.spaceship_image, x=200, y=50)
        
        self.alien_image = pyglet.image.load('images/invader.png')
        self.aliens = []
        
        self.bullet_image = pyglet.image.load('images/bullet_white_16.png')
        self.bullets = []
示例#7
0
    def render(self):
        fnt = font.load('', self.font_size)

        h = fnt.ascent - fnt.descent
        w = self.window.width

        self.labels = [
            font.Text(fnt, 'LEFT', 0, 10 + 3 * h, width=w, halign='left'),
            font.Text(fnt, 'CENTER', 0, 10 + 2 * h, width=w, halign='center'),
            font.Text(fnt, 'RIGHT', 0, 10 + h, width=w, halign='right'),
        ]
示例#8
0
    def __init__(self, model):
        self.model = model
        self.model.push_handlers(self)

        self.window = window.Window(512, 512)
        self.keys = key.KeyStateHandler()
        self.window.push_handlers(self.keys)

        self.fps = clock.ClockDisplay(color=(1, 0, 0, 1))
        self.font = font.load(None, 24, bold=True)
        self.bigfont = font.load(None, 48, bold=True)
        self.score_view = font.Text(self.font,
                                    "Score: 0",
                                    x=16,
                                    y=496,
                                    halign='left',
                                    valign='top',
                                    color=(1, 0, 0, .8))
        self.game_over = font.Text(self.bigfont,
                                   "GAME OVER",
                                   x=256,
                                   y=256,
                                   halign='center',
                                   valign='center',
                                   color=(1, 0, 0, .8))
        # View objects
        self.ship_view = ShipView(self.model.ship)
        self.bullet_views = gfx.ViewObjectBag(self.model.bullets, BulletView)
        self.asteroid_views = gfx.ViewObjectBag(self.model.asteroids,
                                                AsteroidView)
        self.dust = gfx.ParticleSystem(DustParticle)
        self.exhaust = gfx.ParticleSystem(ExhaustParticle)
        self.stars = gfx.SlowParticleSystem(Star)

        # Generate stars
        for i in range(20):
            dist = random.uniform(5, 20)
            x = random.uniform(0, 512)
            y = random.uniform(0, 512)
            angle = random.uniform(0, 72)
            self.stars.new_particle(x=x,
                                    y=y,
                                    vx=-dist * 0.05,
                                    vy=0,
                                    radius=dist,
                                    angle=angle)

        # Setup GL
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glEnable(GL_LINE_SMOOTH)
        glEnable(GL_POINT_SMOOTH)
        glClearColor(0, 0, 0, 0)
示例#9
0
 def loadRoom(self, roomX, roomY):
     roomId = roomY * rooms.width + roomX
     tiles = rooms.rooms[roomId*2]
     codes = rooms.rooms[roomId*2+1]
     self.objs = [self.player]
     self.room.load(tiles, codes, self.objs)
     base = self.window.height - 52
     ix,iy = roomX-8,roomY-8 # relative to start.
     self.title = font.Text(self.font,
         NAMES.get((ix,iy),"Belle of Nine Fables"), x=10, y=base)
     self.roomnum = font.Text(self.font,
         "%d:%d" % (abs(ix),abs(iy)), x=280, y=base)
示例#10
0
    def __init__(self):
        self.window = pyglet.window.Window(width=const.GAME_WIDTH,
                                           height=const.GAME_HEIGHT,
                                           vsync=False,
                                           caption="Porcupyne",
                                           resizable=True)
        self.window.invalid = False

        # resource.path = ['.']

        res = resources.Resource()
        res.load_directory('gamedata')

        self.player1 = Ball(self, res)
        self.bg = BG(res)
        platform_width = 200
        platform_height = 96

        def get_points(x, y):
            x -= platform_width / 2.0
            y -= platform_height / 2.0
            return (((x, y), (x, y + platform_height), (x + platform_width,
                                                        y + platform_height),
                     (x + platform_width, y)))

        self.platforms = [
            Platform(get_points(0, -128), res),
            Platform(get_points(128, 0), res),
            Platform(get_points(-270, -50), res),
            Platform(get_points(-320, 150), res),
            Platform(((225, 48), (400, 160), (400, 48)), res)
        ]
        self.controller = Controller(self.window, self.player1)
        self.fps_display = font.Text(pyglet.font.load('', 18, bold=True),
                                     '',
                                     color=(0.5, 0.5, 0.5, 0.5),
                                     x=-150,
                                     y=-100)

        ft = font.load('Arial', 10)
        color = (0, 0, 0, 1)
        self.debug_text = [
            font.Text(ft, x=-150, y=100, color=color),
            font.Text(ft, x=-150, y=85, color=color),
            font.Text(ft, x=-150, y=70, color=color)
        ]

        # alpha channels¨
        rabbyt.set_default_attribs()
        glEnable(GL_LINE_SMOOTH)
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
示例#11
0
文件: scene.py 项目: toli/yoyobrawlah
    def draw(self):
        if self.selected:
            text = font.Text(self.bigFont,
                             self.text,
                             x=self.x,
                             y=self.y,
                             color=(1, 1, 1, 1))
        else:
            text = font.Text(self.smallFont,
                             self.text,
                             x=self.x,
                             y=self.y,
                             color=(1, 0.5, 0.5, 1))

        text.draw()
示例#12
0
文件: plot_axes.py 项目: msgoff/sympy
    def draw_text(self, text, position, color, scale=1.0):
        if len(color) == 3:
            color = (color[0], color[1], color[2], 1.0)

        if self._p.label_font is None:
            self._p.label_font = font.load(self._p.font_face,
                                           self._p.font_size,
                                           bold=True,
                                           italic=False)

        label = font.Text(
            self._p.label_font,
            text,
            color=color,
            valign=font.Text.BASELINE,
            halign=font.Text.CENTER,
        )

        pgl.glPushMatrix()
        pgl.glTranslatef(*position)
        billboard_matrix()
        scale_factor = 0.005 * scale
        pgl.glScalef(scale_factor, scale_factor, scale_factor)
        pgl.glColor4f(0, 0, 0, 0)
        label.draw()
        pgl.glPopMatrix()
示例#13
0
    def __init__(self):
        self.selected_option = None
        self.selected_hot = False

        self.label_font = font.load('Arial', 24.0, bold=True)
        self.labels = []

        width = height = 0
        for name in self.options[::-1]:
            if name is None:
                height += 30
                continue

            label = font.Text(self.label_font, name, color=self.text_color)
            label.y = height + 5
            width = max(width, label.width)
            height += label.height
            self.labels.append(label)
            height += 10

        self.width = width
        self.height = height
        self.x = 0
        self.y = 0

        self.has_exit = False
示例#14
0
 def fset(self, value):
     self._value = value
     if self.shadow:
         self.shadow = font.Text(self.font,
                                 text=str(value),
                                 color=(0, 0, 0, 1),
                                 width=self._fixed_width,
                                 halign=self.halign,
                                 valign=self.valign)
     self.main_text = font.Text(self.font,
                                text=str(value),
                                color=self.color,
                                width=self._fixed_width,
                                halign=self.halign,
                                valign=self.valign)
     self._width, self._height = self.main_text.width, self.main_text.height
示例#15
0
 def draw(self):
     if self.stop:
         director.scene.end()
         
     if self.state == self.SWITCH:
         text = font.Text(self.font, 'switch to:',color=(0.,0.5,0.5,0.5))
         text.x = 20
         text.y = 300
         text.draw()
         text = font.Text(self.font, self.number ,color=(0.,0.5,0.5,0.5))
         text.x = 20
         text.y = 250
         text.draw()
         
     elif self.state in (self.SHOW, self.DRAG):
         self.path.render()
         if self.near:
             c = Circle(
                 self.near.x,self.near.y,
                 width=15,color=(0.,1.,1.,1.)
                 )
             c.render()
             
     elif self.state == self.ANIMATE:
         dt = time.time() - self.anim_start
         bz = self.path.bezier()
         if dt >= self.duration:
             self.state = self.SHOW
         else:
             x,y = bz.at( (dt/self.duration)**self.time_warp )
             c = Circle(
                     x+self.path.a.x,y+self.path.a.y,
                     width=45,color=(0.,1.,1.,1.)
                     )
             c.render()
                 
             
     text = font.Text(self.font, '[%i,%i] t**%0.2f d=%0.2f n=%d p=%d'%(
                 self.mouse.x, self.mouse.y,
                 self.time_warp,
                 self.duration,
                 len(self.paths), self.pathp
             ),
             color=(0.,0.5,0.5,0.5))
     text.x = 100
     text.y = 20
     text.draw()
 def update_text(self, text=None):
     if not text: text = 'FOV: {:.3}'.format(self.view.fov)
     props = dict(x=self.window.width - 10,
                  y=10,
                  halign=font.Text.RIGHT,
                  valign=font.Text.BOTTOM,
                  color=(0, 0, 0, 0.5))
     self.text = font.Text(self.font, text, **props)
示例#17
0
    def render(self):
        font.add_file(os.path.join(base_path, 'action_man.ttf'))

        # Hard-code 16-pt at 100 DPI, and hard-code the pixel coordinates
        # we see that font at when DPI-specified rendering is correct.
        fnt = font.load('Action Man', 16, dpi=120)

        self.text = font.Text(fnt, 'The DPI is 120', 10, 10)
示例#18
0
 def __init__(self, ft, text="", *args, **kwargs):
     rabbyt.BaseSprite.__init__(self, *args, **kwargs)
     self._text = font.Text(
         ft,
         text,
         halign=font.Text.CENTER,
         valign=font.Text.CENTER,
     )
示例#19
0
	def __init__(self, text_x, text_y, **kwargs):

		self.kills = 0
		Sprite.__init__(self, "ship.png", **kwargs)

		#Create a font for our kill message
		self.font = font.load('Arial', 28)
		#The pyglet.font.Text object to display the FPS
		self.kill_text = font.Text(self.font, y=text_y, x=text_x)
示例#20
0
    def __init__(self, *args, **kwargs):

        #Let all of the arguments pass through
        self.win = window.Window.__init__(self, *args, **kwargs)

        clock.schedule_interval(self.update, 1.0 / 30)  # update at 30 Hz

        # setting text objects
        ft = font.load('Tahoma', 20)  #Create a font for our FPS clock
        self.fpstext = font.Text(ft, y=10)  # object to display the FPS
示例#21
0
文件: style.py 项目: pyzh/pyglet
 def text(self, text, color=(0, 0, 0, 1), font_size=None,
          font_name=None, halign='left', width=None,
          valign=font.Text.BOTTOM):
     if font_size is None:
         font_size = self.font_size
     if font_name is None:
         font_name = self.font_name
     f = self.getFont(name=font_name, size=font_size)
     return font.Text(f, text, color=color, halign=halign, width=width,
                      valign=valign)
示例#22
0
    def render(self):
        font.add_file(os.path.join(base_path, 'action_man.ttf'))
        font.add_file(os.path.join(base_path, 'action_man_bold.ttf'))
        font.add_file(os.path.join(base_path, 'action_man_italic.ttf'))
        font.add_file(os.path.join(base_path, 'action_man_bold_italic.ttf'))

        fnt = font.load('Action Man', self.font_size)
        fnt_b = font.load('Action Man', self.font_size, bold=True)
        fnt_i = font.load('Action Man', self.font_size, italic=True)
        fnt_bi = font.load('Action Man', self.font_size, bold=True, italic=True)

        h = fnt.ascent - fnt.descent

        self.labels = [
            font.Text(fnt, 'Action Man', 10, 10 + 3 * h),
            font.Text(fnt_i, 'Action Man Italic', 10, 10 + 2 * h),
            font.Text(fnt_b, 'Action Man Bold', 10, 10 + h),
            font.Text(fnt_bi, 'Action Man Bold Italic', 10, 10)
        ]
示例#23
0
    def __init__(self, levelNum, sound=True):
        global soundtrack
        events.AddListener(self)
        self.done = False
        self.deathDelay = 0
        self.levelNum = levelNum
        strLevelNum = '%02d' % levelNum
        triggers = data.levelTriggers['leveltriggers' + strLevelNum]
        if not levelNum % 2:
            # even levels are repeats of previous images
            strLevelNum = '%02d' % (levelNum - 1)
        self.walkMask = data.levelMasks[strLevelNum]
        filePath = os.path.join(data.data_dir, 'levelbg%s-?.png' % strLevelNum)
        self.sound = sound

        bgPngs = glob.glob(filePath)
        bgPngs.sort()
        self.bgImages = [data.pngs[png] for png in bgPngs]

        self.avatar = Avatar()
        self.avatar.strings = player.strings[:]
        self.visualEffects = visualeffects.EffectManager()

        self.miscSprites = []
        healthFont = font.load('Oh Crud BB', 28)
        #self.healthText = font.Text(healthFont, x=10, y=25, text='Health:')
        self.healthBar = HeartMeter()
        self.energyBar = EnergyMeter((240, 5))

        self.fpsText = font.Text(healthFont, x=650, y=25)

        self.triggerZones = []
        for rect, clsName in triggers.items():
            cls = globals().get(clsName)
            if not cls:
                if len(rect) == 4:
                    print "ERROR: couldn't find", clsName
                continue
            zone = cls(rect, self)
            self.triggerZones.append(zone)
            if hasattr(zone, 'sprite'):
                self.miscSprites.append(zone.sprite)
            if DEBUG and hasattr(zone, 'debugSprite'):
                self.miscSprites.append(zone.debugSprite)

        self.enemySprites = {}

        self.startLoc = [
            key for key, val in triggers.items() if val == 'start location'
        ][0]

        if levelNum == 1 and self.sound:
            soundtrack = \
                queueSoundtrack('8bp077-01-nullsleep-her_lazer_light_eyes.mp3')
            soundtrack.play()
    def render(self):
        font.add_file(os.path.join(base_path, 'courR12-ISO8859-1.pcf'))

        fnt = font.load('Courier', 16)

        h = fnt.ascent - fnt.descent + 10
        self.texts = [
            font.Text(fnt,
                      'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
                      10, h * 1),
        ]
示例#25
0
    def __init__(self, pos, part):
        myFont = data.fonts['default']
        self.text = font.Text(myFont, part, color=(0, 255, 0, 1))
        #self.text = font.Text(myFont, part)
        pat = pyglet.image.SolidColorImagePattern((255, 255, 255, 128))
        img = pyglet.image.create(self.text.width + self.xPadding * 2,
                                  self.text.height + self.yPadding * 2, pat)
        pyglet.sprite.Sprite.__init__(self, img, 0, 0)

        self.logicalXCenter = pos[0]
        self.logicalY = pos[1] + 40
示例#26
0
 def __init__(self, win):
     helv = font.load('Helvetica', win.width / 15.0)
     self.text = font.Text(
         helv,
         'Hello, World!',
         x=win.width / 2,
         y=win.height / 2,
         halign=font.Text.CENTER,
         valign=font.Text.CENTER,
         color=(1, 1, 1, 0.5),
     )
     self.fps = clock.ClockDisplay()
示例#27
0
 def InitWithPyglet(self, window):
     # stuff that needs to be done *after* the pyglet window is created
     self.set_pen_color(self.pen_color)
     self.set_stroke(self.stroke)
     self.window = window
     # prep the text object
     self.text = font.Text(font.load('',10), '', color=(1,1,1,1),
                           valign='bottom', halign='left')
     # prep the quadric object used by glu* functions (circle)
     # styles GLU_LINE, GLU_FILL, GLU_SILHOUETTE, GLU_POINT
     self.qobj = gluNewQuadric()
     gluQuadricDrawStyle(self.qobj, GLU_SILHOUETTE)
示例#28
0
    def render(self):
        fnt = font.load('', self.font_size)

        h = fnt.ascent - fnt.descent
        w = self.window.width

        self.labels = []
        x = 0
        for align in 'top center baseline bottom'.split():
            label = align.upper() + 'y'
            self.labels.append(font.Text(fnt, label, x, 50, valign=align))
            x += self.labels[-1].width
示例#29
0
 def __init__(self, win, world):
     helv = font.load('Helvetica', 30)
     message = '%d entities' % (world.numEnts)
     self.text = font.Text(
         helv,
         message,
         x=win.width,
         y=0,
         halign=font.Text.RIGHT,
         valign=font.Text.BOTTOM,
         color=(1, 1, 1, 0.5),
     )
     self.fps = clock.ClockDisplay(format="%(fps).1ffps", font=helv)
示例#30
0
    def __init__(self, level):
        self.level = level
        self.restart()

        self.collision = CollisionMesh()

        for mesh in level.collision_meshes:
            self.collision.add_windings(mesh.polygons)

        self.clock_display = None

        game_font = font.load('Arial', 36, bold=True)
        self.game_label = font.Text(game_font, '', color=(.9, .9, 1, .9))