本文整理汇总了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())