本文整理汇总了Python中Vector.add方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.add方法的具体用法?Python Vector.add怎么用?Python Vector.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector
的用法示例。
在下文中一共展示了Vector.add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Player
# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import add [as 别名]
class Player(pygame.sprite.Sprite):
bottom = 630
left = 0
right = 720
def __init__(self):
self.image = 17
self.framenumber = 0
self.swinging = 4;
self.gunmode = False;
pygame.sprite.Sprite.__init__(self)
self.images = [pygame.image.load(os.path.join(os.curdir, 'spritel1.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spritel2.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spritel3.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spritel4.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spritel5.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spritel6.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spritel7.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spritel8.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spriter1.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spriter2.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spriter3.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spriter4.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spriter5.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spriter6.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spriter7.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spriter8.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'jump.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'start.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'bowl.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'bowr.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'hurt.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'dead.png')).convert_alpha()
]
self.rect = self.images[self.image].get_rect()
self.rect = self.rect.move(300,600)
self.vel = 0
self.x = 300
self.y = 600
self.dir = 1 # 1: Right -1: Left
self.vector = Vector(self.x,self.y)
self.Arrows = 20
self.ArrowsMax = 20
self.ArrowsRepl = 0.0
self.ArrowsReplRate = 0.1
self.Gravity = 100
self.GravityRepl = 0.0
self.RapidFire = False
self.MultiShot = False
self.MultiShot2 = False
self.Lives = 5
self.Repel = 8
self.DecoyNum = 5
self.DecoyCounter = 0
self.DecoyX = 0
self.DecoyY = 0
def updateVector(self,x,y):
diffX = x - self.x
diffY = y - self.y
if diffX != 0 and diffY!= 0:
newX = diffX / (sqrt((diffX*diffX)+(diffY*diffY)))
newY = diffY / (sqrt((diffX*diffX)+(diffY*diffY)))
else:
newX = 0
newY = 0
temp = Vector(newX,newY)
self.vector.add(temp)
if self.vector.x != 0 and self.vector.y != 0:
self.vector.x = self.vector.x / (sqrt((self.vector.x*self.vector.x)+(self.vector.y*self.vector.y)))
self.vector.y = self.vector.y / (sqrt((self.vector.x*self.vector.x)+(self.vector.y*self.vector.y)))
def updatePlayerPos(self,x,y):
#self.image = (self.image + 1) % 8
x = int(x)
y = int(y)
#if(x == 0):
# if(self.image != 19 and self.image != 18):
# self.updatePlayerSprite(17, 1)
if(self.gunmode):
self.images[18] = pygame.image.load(os.path.join(os.curdir, 'gunl.png')).convert_alpha()
self.images[19] = pygame.image.load(os.path.join(os.curdir, 'gunr.png')).convert_alpha()
if self.x + x < 1252 and self.x + x > -5:
self.x += x
self.rect = self.rect.move(x,0)
if self.y + y < 600 and self.y + y > 0:
self.y += y
self.rect = self.rect.move(0,y)
self.updatePlayerSprite(16,1)
if self.y + y > 600:
self.rect = self.rect.move(0,600-self.y)
#self.updatePlayerSprite(17,1)
self.y = 600
if(x < 0):
self.updatePlayerSprite(0, 8)
if(x > 0):
self.updatePlayerSprite(8,8)
#.........这里部分代码省略.........
示例2: construct
# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import add [as 别名]
def construct(self,name=None):
""" builds the trace """
minVel = 99999.0
maxVel = 0.0
pPos = None
if not self.points: # if points is not yet defined, iterate through keys and gather the points
self.points = []
frames = [x*self.timestep+self.timeSpan[0] for x in range(0, int((self.timeSpan[1]-self.timeSpan[0])/self.timestep)+1)]
frames.append(self.timeSpan[1])
for t in frames:
mc.currentTime(t)
pos = mc.xform( self.object, q=True, ws=True, translation=True )
if not pPos == None:
vel = Vector(pos) - Vector(pPos)
if( vel.mag() > maxVel ):
maxVel = vel.mag()
if( vel.mag() < minVel ):
minVel = vel.mag()
if( len(self.points) == 0 or
(Vector(pos) - Vector(self.points[-1])).mag() > 0.001 ):
self.points.append(pos)
pPos = pos
self.origCurve = mc.curve(d=1, ep=self.points, n="nurbsCurveTrace")
self.origCurve = mc.rebuildCurve(self.origCurve,
constructionHistory=0,
replaceOriginal=1,
rebuildType=0,
endKnots=1,
keepRange=1,
keepControlPoints=0,
keepEndPoints=1,
keepTangents=0,
spans=len(self.points)*self.timestep*self.smooth,
degree=3,
tolerance=0.01)[0]
if name:
self.origCurve = mc.rename(self.origCurve,name)
if( self.tube == True ):
self.extrusion = self.extrude()
frames = [x*self.timestep+self.timeSpan[0] for x in range(0, int((self.timeSpan[1]-self.timeSpan[0])/self.timestep)+1)]
frames.append(self.timeSpan[1])
for t in frames:
mc.currentTime(t)
end = cu.curveArcLen( self.origCurve )
mc.select( self.object )
pt = mc.xform( q=True, ws=True, t=True )
now = cu.findArcLenAtParam( self.origCurve, cu.findParamAtPoint( self.origCurve, pt ) )
# find subCurve2 of the extrusion
shape = mc.listRelatives(self.curve2, fullPath=True, shapes=True)[0]
for sub in mc.listConnections(shape):
if(sub.startswith("subCurve")):
mc.setKeyframe( "%s.maxValue"%sub, t=t, v=max(0.0001,now/end) ) # key the visibility
prev = None
frames = [x*self.timestep+self.timeSpan[0] for x in range(0, int((self.timeSpan[1]-self.timeSpan[0])/self.timestep)+1)]
frames.append(self.timeSpan[1])
for prevT in frames:
mc.currentTime(prevT)
mc.select( self.object )
pt = mc.xform( q=True, ws=True, t=True )
scalePivot = Vector()
for i in range(0,8):
mc.select( "%s.cv[%d][%d]"%( self.extrusion, i, int(t/self.timestep) ) )
scalePivot.add( Vector( mc.xform(q=True, ws=True, t=True) ) )
scalePivot.mult(1.0/8.0)
mc.select( "%s.cv[0:7][%d]"%( self.extrusion,int(t/self.timestep) ) )
if( self.multVel ):
sz = 1.0
if( prev == None ):
sz = 0.0
else:
vel = Vector(pt) - Vector(prev)
if( self.invertVel ):
sz = self.taper(prevT, self.timeSpan[0], self.timeSpan[1], 0.2, 0.8) #remap(vel.mag(), minVel, maxVel, 1, 0)
else:
sz = 1-self.taper(prevT, self.timeSpan[0], self.timeSpan[1], 0.2, 0.8) #remap(vel.mag(), minVel, maxVel, 0, 1)
mc.scale( sz, sz, sz, centerPivot=True, relative=True, p=scalePivot )
prev = pt
groupName = mc.group(self.traceBits,n=self.object+"TubeTraceGroup")
mc.setKeyframe( groupName+".visibility", t=self.timeSpan[0]-1, v=0.0 )
mc.setKeyframe( groupName+".visibility", t=self.timeSpan[0], v=1.0 )
# center the pivot on the newly created trace
mc.select(groupName)
mc.xform(cp=True)
return groupName
else:
# center the pivot on the newly created trace
mc.select(self.origCurve)
mc.xform(cp=True)
return self.origCurve