Skip to content

Instantly share code, notes, and snippets.

@akirayu101
Last active August 29, 2015 14:15
Show Gist options
  • Save akirayu101/8a838e566338e3ee92e4 to your computer and use it in GitHub Desktop.
Save akirayu101/8a838e566338e3ee92e4 to your computer and use it in GitHub Desktop.
## 空state,不产生任何的效果
class State(object):
def __init__(self):
pass
def enter(self, entity, param_table, state_maintain, global_maintain):
pass
def update(self, entity, param_table, state_maintain, global_maintain):
pass
def leave(self, entity, param_table, state_maintain, global_maintain):
state_maintain.clear()
def run(self, entity, param_table, state_maintain, global_maintain):
if state_maintain.get('init'):
# 已经跑过一次咯
self.update(entity, param_table, state_maintain, global_maintain)
else:
self.enter(entity, param_table, state_maintain, global_maintain)
state_maintain['init'] = True
def stop(self, entity, param_table, state_maintain, global_maintain):
self.leave(entity, param_table, state_maintain, global_maintain)
class Accelerate_State(State):
def enter(self, entity, param_table, state_maintain, global_maintain):
state_maintain['orig_speed'] = entity.speed
entity.speed += param_table['speed']
def level(self, entity, param_table, state_maintain, global_maintain):
entity.speed = state_maintain['orig_speed']
state_maintain.clear()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment