当前位置: 首页>>代码示例>>Python>>正文


Python Sprite.bind方法代码示例

本文整理汇总了Python中sprite.Sprite.bind方法的典型用法代码示例。如果您正苦于以下问题:Python Sprite.bind方法的具体用法?Python Sprite.bind怎么用?Python Sprite.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sprite.Sprite的用法示例。


在下文中一共展示了Sprite.bind方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Player

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import bind [as 别名]
class Player(object):
    max_speed = 1.8

    def __init__(self):
        self.x = 0
        self.y = 1 # starts a bit in the air
        self.z = 0

        # speed
        self.vel = 0.0
        self.acc = 0.0
        
        # for jumps
        self.in_air = True
        self.jump_pow = 0.0
        self.jumping = False

        try:
            self.sprite = Sprite('player.png', 10)
        except:
            print >> sys.stderr, "Failed to load hires player texture, trying lowres."
            self.sprite = Sprite('player_lo.png', 10)
		
        self.shadow = Sprite('shadow.png', 1)
        self.frame = 0

    def render(self):
        h,_ = self.calc_height()
        
        if h > -0.1:
            glPushMatrix()
            glTranslatef(player.x, h + 0.01, player.z)
            
            self.shadow.bind()
            glBegin(GL_QUADS)
            glTexCoord2f(0,0)
            glVertex3f(-0.4, 0, -0.4)
            glTexCoord2f(1,0)
            glVertex3f( 0.4, 0, -0.4)
            glTexCoord2f(1,1)
            glVertex3f( 0.4, 0,  0.4)
            glTexCoord2f(0,1)
            glVertex3f(-0.4, 0,  0.4)
            glEnd()

            glPopMatrix()

        glPushMatrix()
        glPushAttrib(GL_ENABLE_BIT)
        #glDisable(GL_DEPTH_TEST)
        glTranslatef(player.x, player.y, player.z)
        glColor4f(1,1,1,1)
        self.sprite.bind()
      
        t = self.sprite.index((self.frame / 3) % 10)
        self.frame += 1

        glBegin(GL_QUADS)
        glTexCoord2f(*t[3])
        glVertex3f(-0.4, 1.5, 0)

        glTexCoord2f(*t[0])
        glVertex3f( 0.4, 1.5, 0)

        glTexCoord2f(*t[1])
        glVertex3f( 0.4,   0, 0)

        glTexCoord2f(*t[2])
        glVertex3f(-0.4,   0, 0)
        glEnd()

        glPopAttrib()
        glPopMatrix()

    def inc(self):
        self.acc = 0.01
        if self.vel > 0.0:
            self.acc *= 1.0 - (self.vel/Player.max_speed)

    def dec(self):
        self.acc = -0.03
        if self.vel < 0.0:
            self.acc *= 1.0 - (self.vel/(-Player.max_speed*0.3))
    
    def left(self):
        x = player.x + 0.1
        mx2 = int(math.ceil(x-0.2) + 2)
        my =  int(player.z)
        h1 = player.y
        h2 = -1
        try:
            h2 = map[my][mx2]
        except IndexError:
            pass

        lower = math.floor(h2) 
        upper = (h2 - math.floor(h2)) * 100

        if lower > 9:
            lower = int(lower) % 10 + int(lower)/10
#.........这里部分代码省略.........
开发者ID:ext,项目名称:sphorse,代码行数:103,代码来源:player.py


注:本文中的sprite.Sprite.bind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。