コード例 #1
0
 def activeMovement(self, sprite, action, speed=None):
     """ Here the assumption is that the controls determine the direction of
     acceleration of the sprite. """
     if speed is None:
         speed = sprite.speed
     v1 = action[0] / float(sprite.mass) + sprite.orientation[0] * speed
     v2 = action[1] / float(sprite.mass) + sprite.orientation[1] * speed
     sprite.orientation = unitVector((v1, v2))
     sprite.speed = vectNorm((v1, v2)) / vectNorm(sprite.orientation)
コード例 #2
0
ファイル: ontology.py プロジェクト: sarobe/VGDLEntityCreator
 def activeMovement(self, sprite, action, speed=None):
     """ Here the assumption is that the controls determine the direction of
     acceleration of the sprite. """
     if speed is None:
         speed = sprite.speed
     v1 = action[0] / float(sprite.mass) + sprite.orientation[0] * speed
     v2 = action[1] / float(sprite.mass) + sprite.orientation[1] * speed
     sprite.orientation = unitVector((v1, v2))        
     sprite.speed = vectNorm((v1, v2)) / vectNorm(sprite.orientation)
コード例 #3
0
def killIfSlow(sprite, partner, game, limitspeed=1):
    """ Take a decision based on relative speed. """
    if sprite.is_static:
        relspeed = partner.speed
    elif partner.is_static:
        relspeed = sprite.speed
    else:
        relspeed = vectNorm((sprite._velocity()[0] - partner._velocity()[0],
                             sprite._velocity()[1] - partner._velocity()[1]))
    if relspeed < limitspeed:
        killSprite(sprite, partner, game)
コード例 #4
0
ファイル: ontology.py プロジェクト: sarobe/VGDLEntityCreator
def killIfSlow(sprite, partner, game, limitspeed=1):
    """ Take a decision based on relative speed. """
    if sprite.is_static:
        relspeed = partner.speed
    elif partner.is_static:
        relspeed = sprite.speed
    else:
        relspeed = vectNorm((sprite._velocity()[0] - partner._velocity()[0],
                             sprite._velocity()[1] - partner._velocity()[1]))
    if relspeed < limitspeed:
        killSprite(sprite, partner, game)
コード例 #5
0
ファイル: ontology.py プロジェクト: sarobe/VGDLEntityCreator
def wallStop(sprite, partner, game, friction=0):
    """ Stop just in front of the wall, removing that velocity component,
    but possibly sliding along it. """
    if not oncePerStep(sprite, game, 'laststop'): 
        return
    stepBack(sprite, partner, game)
    if abs(sprite.rect.centerx - partner.rect.centerx) > abs(sprite.rect.centery - partner.rect.centery):
        sprite.orientation = (0, sprite.orientation[1] * (1. - friction))
    else:
        sprite.orientation = (sprite.orientation[0] * (1. - friction), 0)        
    sprite.speed = vectNorm(sprite.orientation) * sprite.speed
    sprite.orientation = unitVector(sprite.orientation)
コード例 #6
0
def wallStop(sprite, partner, game, friction=0):
    """ Stop just in front of the wall, removing that velocity component,
    but possibly sliding along it. """
    if not oncePerStep(sprite, game, 'laststop'):
        return
    stepBack(sprite, partner, game)
    if abs(sprite.rect.centerx -
           partner.rect.centerx) > abs(sprite.rect.centery -
                                       partner.rect.centery):
        sprite.orientation = (0, sprite.orientation[1] * (1. - friction))
    else:
        sprite.orientation = (sprite.orientation[0] * (1. - friction), 0)
    sprite.speed = vectNorm(sprite.orientation) * sprite.speed
    sprite.orientation = unitVector(sprite.orientation)