本文整理汇总了Python中timer.Timer.check方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.check方法的具体用法?Python Timer.check怎么用?Python Timer.check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timer.Timer
的用法示例。
在下文中一共展示了Timer.check方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProjectileCreator
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import check [as 别名]
class ProjectileCreator(Aspect):
"""This aspect allows an entity to create projectiles that are owned by them.
This class also is responsible for updating all projectiles it owns."""
def init(self):
self.projectiles = set()
self.cooled_down = True
self.cooldown_timer = Timer(0) #Timer will always fire
def tick(self, dtime):
"""Update projectile positions and cooldown timer."""
to_remove = []
for projectile in self.projectiles:
# Check if the projectile is floating away forever
if projectile.death_timer.check(dtime, reset=False):
to_remove.append(projectile)
continue
projectile.position = projectile.motion_state.position
# Must be removed separately since items can't be removed from a set during iteration.
for projectile in to_remove:
self.projectiles.remove(projectile)
projectile.destroy()
self.cooled_down = self.cooldown_timer.check(dtime)
def set_projectile(self, projectile_type):
self.projectile_type = projectile_type
self.cooldown_timer = Timer(projectile_type.cooldown, randomize=False, fireFirstCheck=True)
def create(self):
"""Spawn a new projectile."""
if self.cooled_down:
position = self.entity.position
handle = self.engine.entity_manager.create_handle()
projectile = self.engine.entity_manager.create_entity(handle, self.projectile_type, position=position)
body = self.engine.physics_system.register_entity(projectile, 1, PlayerMotionState)
direction = self.entity.motion_state.orientation * (0, 0, -1)
body.setLinearVelocity(vector.ogre2bullet_vector(direction * projectile.speed))
self.projectiles.add(projectile)
projectile.start_death_timer()
self.cooldown_timer.reset()
def attach_controls(self):
self.engine.input_system.register_handler(InputEvent.KEY_DOWN, OIS.KC_X, self.create)
示例2: ManualControl
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import check [as 别名]
class ManualControl(Aspect):
''' Control with right stick of xbox gamepad
'''
turnDelta = 1.0
def init(self):
self.ddContext = self.engine.debugDrawSystem.getContext()
self.timer = Timer(0.01)
self.desiredSpeed = 0.0
self.desiredHeading = 0.0
def crosslink(self):
if self.engine.inputSystem.joystick:
self.gamepad = self.engine.inputSystem.joystick
self.keyboard = self.engine.inputSystem.keyboard
self.engine.inputSystem.registerHandler(inputSystem.InputEvent.KEY_PRESSED, OIS.KC_SPACE, self.spacebar)
self.engine.inputSystem.registerHandler(inputSystem.InputEvent.KEY_PRESSED, OIS.KC_BACK, self.setToNetSlave)
def spacebar(self):
if self.ent.isSelected:
if self.ent.UnitAI.state == self.ent.UnitAI.State.AI:
self.setToManual()
elif self.ent.UnitAI.state == self.ent.UnitAI.State.MANUAL_CONTROL:
if self.engine.localOptions.networkingOptions.enableNetworking:
self.setToNetSlave()
else:
self.setToStop()
elif self.ent.UnitAI.state == self.ent.UnitAI.State.NET_SLAVE:
self.setToManual()
elif self.ent.UnitAI.state == self.ent.UnitAI.State.STOP:
self.setToManual()
else:
print "Unknown state transition"
def setToNetSlave(self):
self.ent.squad.SquadAI.commands = [command.NetSlave(self.engine)]
def setToStop(self):
self.ent.squad.SquadAI.commands = [command.Stop(self.engine, 0)]
def setToManual(self):
self.ent.squad.SquadAI.commands = [command.ManualControl(self.engine)]
self.desiredSpeed = self.ent.desiredSpeed
self.desiredHeading = self.ent.yaw
def turnRight(self, dh, dtime):
dh -= self.turnDelta*dtime
while dh < -mathlib.pi:
dh += mathlib.twopi
return dh
def turnLeft(self, dh, dtime):
dh += self.turnDelta*dtime
while dh > mathlib.pi:
dh -= mathlib.twopi
return dh
def speedUp(self, ds, ms):
return mathlib.clamp(ds + ms/100.0, 0, ms)
def slowDown(self, ds, ms):
return mathlib.clamp(ds - ms/100.0, 0, ms)
def tick(self, dtime):
self.ddContext.clear()
if self.ent.isSelected:
if self.ent.UnitAI.state == self.ent.UnitAI.State.MANUAL_CONTROL:
if self.engine.inputSystem.joystick:
joyState = self.gamepad.getJoyStickState()
if joyState.mAxes[JoyAxes.LEFT_LEFTRIGHT].abs > 10000: #right
self.desiredHeading = self.turnRight(self.desiredHeading, dtime)
if joyState.mAxes[JoyAxes.LEFT_LEFTRIGHT].abs < -10000: #left
self.desiredHeading = self.turnLeft(self.desiredHeading, dtime)
if joyState.mAxes[JoyAxes.LEFT_UPDOWN].abs > 10000: #slower
self.desiredSpeed = self.slowDown(self.desiredSpeed, self.ent.maxSpeed)
if joyState.mAxes[JoyAxes.LEFT_UPDOWN].abs < -10000: #faster
self.desiredSpeed = self.speedUp(self.desiredSpeed, self.ent.maxSpeed)
# in any case you can use keyboard arrow control
if self.keyboard.isKeyDown(OIS.KC_LEFT):
self.desiredHeading = self.turnLeft(self.desiredHeading, dtime)
if self.keyboard.isKeyDown(OIS.KC_RIGHT):
self.desiredHeading = self.turnRight(self.desiredHeading, dtime)
if self.keyboard.isKeyDown(OIS.KC_UP):
self.desiredSpeed = self.speedUp(self.desiredSpeed, self.ent.maxSpeed)
if self.keyboard.isKeyDown(OIS.KC_DOWN):
self.desiredSpeed = self.slowDown(self.desiredSpeed, self.ent.maxSpeed)
if self.timer.check(dtime):
v = vector3(self.ent.avoidanceSize.x/2.0 * self.desiredSpeed, 0, 0)
sv = mathlib.yawwedVector(v, self.ent.yaw)
offset = mathlib.yawwedVector(v, self.desiredHeading)
self.engine.debugDrawSystem.drawRay(self.ddContext, self.ent.pos, offset, color = colors.BLUE)