本文整理汇总了Python中pyglet.sprite.Sprite.set_position方法的典型用法代码示例。如果您正苦于以下问题:Python Sprite.set_position方法的具体用法?Python Sprite.set_position怎么用?Python Sprite.set_position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyglet.sprite.Sprite
的用法示例。
在下文中一共展示了Sprite.set_position方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Inhabitant
# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import set_position [as 别名]
class Inhabitant(object):
def __init__(self, img, x, y):
super(Inhabitant, self).__init__()
register(self)
self.x, self.y = x, y
self.pathfinder = None
self.path = [] # extra copy for custom tumbling or alternative path factories
self.speed = 0.05
self.image = img
self.sprite = Sprite(img, batch=batch)
self.update()
def update(self):
grpos = topo.ground_position(self.x, self.y)
if grpos:
x, y = grpos
self.sprite.set_position(x - 10, y)
def move(self):
dx = self.path[0].x - self.x
dy = self.path[0].y - self.y
if dx ** 2 + dy ** 2 < 0.01:
self.path.pop(0)
if len(self.path) < 1:
self.pathfinder = None
else:
r = math.sqrt(dx ** 2 + dy ** 2)
dx *= self.speed / r
dy *= self.speed / r
self.x += dx
self.y += dy
self.update()
示例2: Goal
# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import set_position [as 别名]
class Goal(object):
def __init__(self, pos):
self._sprite = Sprite(FLOORTARGET_IMAGE)
self._pos = pos
self._sprite.opacity = FLOORTARGET_OPACITY
@property
def pos(self):
return self._pos
@pos.setter
def pos(self, value):
self._pos = value
offset = Vector(self._sprite.width / 2, self._sprite.height / 2)
pos = value * STREET_GRID_SIZE - offset
self._sprite.set_position(pos.x, pos.y)
def render(self):
self._sprite.draw()
def on_goal(self, position):
distance = position - self._pos
return distance.length2 < FLOORTARGET_RANGE ** 2
示例3: __init__
# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import set_position [as 别名]
class GarbageCan:
def __init__(self):
self.image_opened = image.load(data_file('garbagecan-open.png'))
self.image_closed = image.load(data_file('garbagecan-closed.png'))
self.image_lid = image.load(data_file('garbagecan-lid.png'))
self.image_opened.anchor_x = self.image_opened.width/2
self.image_opened.anchor_y = self.image_opened.height/2
self.image_closed.anchor_x = self.image_opened.width/2
self.image_closed.anchor_y = self.image_opened.height/2
self.candidateLeaves = {}
self.opened = True
self.lid_active = False
self.can_active = False
self.fallen = False
self.can_highlighted = False
self.lid_highlighted = True
self.can_rect = Rect(0, 0, self.image_closed)
self.can_rect.center = (80, 90)
self.can_sprite = Sprite(self.image_opened)
self.can_sprite.set_position(self.can_rect.x, self.can_rect.y)
self.lid_rect = Rect(20, 40, self.image_lid)
window.game_window.push_handlers(self.on_mouse_release)
window.game_window.push_handlers(self.on_mouse_press)
window.game_window.push_handlers(self.on_mouse_drag)
window.game_window.push_handlers(self.on_mouse_motion)
events.AddListener(self)
def update(self, timechange):
pass
def draw(self):
if not self.can_active:
if self.can_highlighted:
self.can_sprite.color = (255, 20, 25)
else:
self.can_sprite.color = (255, 255, 255)
else:
self.can_sprite.color = (255, 255, 255)
self.can_sprite.draw()
glColor4f(1, 1, 1, 1)
if not self.lid_active:
if self.lid_highlighted:
glColor4f(1, 0.1, 0.1, 1)
else:
glColor4f(1, 1, 1, 1)
if self.opened:
self.image_lid.blit(*self.lid_rect.bottomleft)
glColor4f(1, 1, 1, 1)
def on_mouse_press(self, x, y, button, modifiers):
if self.opened and self.lid_rect.collide_point(x, y):
self.set_lid_active()
elif self.collides(x, y):
self.fallen = False
self.set_can_active()
self.can_sprite.rotation = 0
if self.opened:
self.can_sprite.image = self.image_opened
else:
self.can_sprite.image = self.image_closed
def set_can_active(self):
window.game_window.set_mouse_visible(False)
self.can_active = True
events.Fire('CanTaken')
def set_lid_active(self):
window.game_window.set_mouse_visible(False)
self.lid_active = True
events.Fire('LidTaken')
def collides(self, x,y):
cs = self.can_sprite
return (x > cs.x - cs.image.width/2
and x < cs.x + cs.image.width/2
and y > cs.y - cs.image.height/2
and y < cs.y + cs.image.height/2 )
def on_mouse_release(self, x, y, button, modifiers):
window.game_window.set_mouse_visible(True)
#print "x=%d y=%d" % (x, y)
if self.lid_active:
if self.collides(x, y):
self.can_sprite.image = self.image_closed
self.opened = False
events.Fire('LidClosed')
#.........这里部分代码省略.........