本文整理匯總了Python中Vector.getX方法的典型用法代碼示例。如果您正苦於以下問題:Python Vector.getX方法的具體用法?Python Vector.getX怎麽用?Python Vector.getX使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Vector
的用法示例。
在下文中一共展示了Vector.getX方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import Vector [as 別名]
# 或者: from Vector import getX [as 別名]
class Obstacle:
def __init__(self,x,y,vx,vy):
self.pos = Vector(x,y)
self.vel = Vector(vx,vy)
self.acc = Vector(0,1)
self.c = color(random(60),random(80),random(255))
self.radius = 10
self.elasticity = 0.9
self.dead = False
self.life = 0
self.inc = 1
def isDead(self):
return self.dead
def getX(self):
return self.pos.getX()
def getY(self):
return self.pos.getY()
def getR(self):
return self.radius
def render(self):
fill(self.c)
wall = loadImage("Wall.png")
image(wall, self.pos.getX(),self.pos.getY())
def update(self):
#Lifetime
self.life += self.inc
if self.life > 1000:
self.dead = True
示例2: __init__
# 需要導入模塊: import Vector [as 別名]
# 或者: from Vector import getX [as 別名]
class Ball:
def __init__(self,x,y,vx,vy):
self.pos = Vector(x,y)
self.vel = Vector(vx,vy)
self.acc = Vector(0,1)
self.c = color(random(255),random(255),random(255))
self.radius = 10
self.elasticity = 0.8
self.dead = False
self.life = 0
self.inc = 1
def isDead(self):
return self.dead
def render(self):
fill(self.c)
ellipse(self.pos.getX(),self.pos.getY(),2*self.radius,2*self.radius)
def update(self):
#Lifetime
self.life += self.inc
if self.life > 1000:
self.dead = True
# Update velocity
self.vel += self.acc
# Update position
self.pos += self.vel
# top wall collision
if(self.pos.getY() < self.radius):
self.pos.setY(2*self.radius - self.pos.getY())
self.vel.setY(-self.elasticity * self.vel.getY())
# bottom wall collision
if(self.pos.getY() > height - self.radius):
self.pos.setY(2*(height-self.radius) - self.pos.getY())
self.vel.setY(-self.elasticity * self.vel.getY())
# left wall collision
if(self.pos.getX() < self.radius):
self.pos.setX(2*self.radius - self.pos.getX())
self.vel.setX(-self.elasticity*self.vel.getX())
# right wall collision
if(self.pos.getX()>width-self.radius):
self.pos.setX(2*(width-self.radius) - self.pos.getX())
self.vel.setX(-self.elasticity*self.vel.getX())