本文整理汇总了Python中hero.Hero.move方法的典型用法代码示例。如果您正苦于以下问题:Python Hero.move方法的具体用法?Python Hero.move怎么用?Python Hero.move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hero.Hero
的用法示例。
在下文中一共展示了Hero.move方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Level
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import move [as 别名]
class Level(cocos.layer.Layer):
def __init__(self):
super(Level, self).__init__()
self.is_event_handler = True
self.keys = set()
self.keyTracker = KeyTracker()
self.keyTracker.register_double_key_handler(
(key.LEFT, key.RIGHT),
self.on_double_key_pressed
)
self.schedule(self.step)
gravity = getattr(settings, 'GRAVITY', (0, 0))
self.vel_iters = 6
self.pos_iters = 6
self.world = b2d.b2World(
gravity=gravity,
doSleep=True
)
self.hero = Hero(self.world, (5, 5), self)
self.ground = Ground(self.world, self)
self.add(self.hero)
def on_double_key_pressed(self, symbol):
self.hero.run()
def get_direction_method(self):
return (
(key.RIGHT in self.keys) - (key.LEFT in self.keys),
(key.UP in self.keys) - (key.DOWN in self.keys),
)
def on_key_press(self, symbol, modifiers):
self.keyTracker.track(symbol)
self.keys.add(symbol)
vector = self.get_direction_method()
self.hero.move(vector)
def on_key_release(self, symbol, modifiers):
self.keys.discard(symbol)
vector = self.get_direction_method()
self.hero.move(vector)
def step(self, tick):
self.hero.update_position(tick)
self.world.Step(tick, self.vel_iters, self.pos_iters)
self.world.ClearForces()
示例2: TestHero
# 需要导入模块: from hero import Hero [as 别名]
# 或者: from hero.Hero import move [as 别名]
class TestHero(unittest.TestCase):
def setUp(self):
self.hero = Hero()
def test_position(self):
self.assertEqual(self.hero.x, WINDOWWIDTH / 2)
self.assertEqual(self.hero.y, WINDOWHEIGHT)
def test_hero_has_image(self):
self.assertIsNotNone(self.hero.image,
'The hero doesn\'t have an image')
def test_image_rect(self):
self.assertIsInstance(self.hero.rect, pygame.Rect)
def test_is_alive(self):
self.assertTrue(self.hero.is_alive)
self.assertEqual(self.hero.health, HERO_HEALTH)
def test_hero_weapon(self):
self.assertIsInstance(self.hero.weapon, Weapon)
def test_move_attribute(self):
self.assertFalse(self.hero.move_left)
self.assertFalse(self.hero.move_right)
def test_move(self):
self.hero.move_right = True
start_pos = self.hero.x
self.hero.move()
self.assertEqual(self.hero.x, start_pos + PLAYER_SPEED)
self.assertEqual(self.hero.x, self.hero.rect.centerx)
def test_weapon(self):
self.assertFalse(self.hero.weapon.is_active)
self.hero.shoot()
self.assertFalse(self.hero.weapon.is_active)