def update(self, data, common_data, dt): speed = 0.3 # if doing something that can't be interrupted then countdown to end of it if self.coolDown(data, dt): pass else: if data.health <= 0: self.setState(data, common_data, eStates.dead) return self.setState(data, common_data, eStates.stationary) if rand_num(10) == 0: # self.setState(data, common_data, eStates.stationary) data.vel = Vec3(0, 0, 0) data.cooldown = rand_num(5) / 8.0 + 0.3 else: # chase hero if data.target_cool <= 0: data.target = Vec3(rand_num(600), rand_num(200), rand_num(200)) data.target_cool = rand_num(20) else: data.target_cool -= 1 if (data.target.x < common_data.pos.x): # self.setState(data, common_data, eStates.runLeft) data.vel = Vec3(-speed, 0, 0) data.facing = eDirections.left else: # self.setState(data, common_data, eStates.runRight) data.vel = Vec3(speed, 0, 0) data.facing = eDirections.right if (data.target.z < common_data.pos.z): data.vel.z = -speed else: data.vel.z = speed if common_data.pos.distSq( Vec3(data.target.x, data.target.y, common_data.pos.z)) < 800: data.vel.y = 0 # drop on target elif (common_data.pos.z < 80 + rand_num(200)) and (data.vel.z < 3): data.vel.y += 2 + rand_num(5) # otherwise flap self.setState(data, common_data, eStates.stationary, force_new_state=True) data.cooldown = 0.2 if common_data.pos.y > 0: px_controller.friction(data.vel, 0.01) else: px_controller.friction(data.vel, 0.1) px_controller.basic_gravity(data.vel) px_controller.basic_physics(common_data.pos, data.vel) restrictToArena(common_data.pos, data.vel)
def update(self, data, common_data, dt): speed = 0.3 # if doing something that can't be interrupted then countdown to end of it if self.coolDown(data, dt): pass else: if data.health <= 0: self.setState(data, common_data, px_entity.eStates.dead) return self.setState(data, common_data, px_entity.eStates.stationary) if rand_num(10)==0: # self.setState(data, common_data, eStates.stationary) data.vel = Vec3(0,0,0) data.cooldown = rand_num(10)/8.0+0.3 else: # chase hero target = common_data.game.requestTarget(common_data.pos) if(target.x<common_data.pos.x): # self.setState(data, common_data, eStates.runLeft) data.vel = Vec3(-speed, 0, 0) data.facing = px_entity.eDirections.left else: # self.setState(data, common_data, eStates.runRight) data.vel = Vec3(speed, 0, 0) data.facing = px_entity.eDirections.right if(target.z<common_data.pos.z): data.vel.z = -speed else: data.vel.z = speed if common_data.pos.distSq(Vec3(target.x,target.y,common_data.pos.y))<800: data.vel.y = 0 # drop on target elif (common_data.pos.z<80) and (data.vel.z<3): data.vel.y += 2 # otherwise flap # common_data.entity.graphics.startAnim(data = common_data.entity.graphics_data) self.setState(data, common_data, px_entity.eStates.stationary, force_new_state=True) common_data.entity.sounds.playEvent(data, common_data, eEvents.flap) data.cooldown = 0.2 if common_data.pos.y>0: px_controller.friction(data.vel, 0.01) else: px_controller.friction(data.vel, 0.1) px_controller.basic_gravity(data.vel) px_controller.basic_physics(common_data.pos, data.vel) background.restrictToArena(common_data.pos, data.vel)
def update(self, data, common_data, dt): speed = 0.3 # if doing something that can't be interrupted then countdown to end of it if self.coolDown(data, dt): pass else: if data.health <= 0: self.setState(data, common_data, eStates.dead) return self.setState(data, common_data, eStates.stationary) if rand_num(10) == 0: # self.setState(data, common_data, eStates.stationary) data.vel = Vec3(0, 0, 0) data.cooldown = rand_num(5) / 10.0 + 0.1 else: # chase hero target = common_data.game.requestTarget(common_data.pos) if (target.x < common_data.pos.x): # self.setState(data, common_data, eStates.runLeft) data.vel = Vec3(-speed, 0, 0) data.facing = eDirections.left else: # self.setState(data, common_data, eStates.runRight) data.vel = Vec3(speed, 0, 0) data.facing = eDirections.right if (target.y < common_data.pos.y): data.vel.y = -speed else: data.vel.y = speed if common_data.pos.distSq( Vec3(target.x, target.y, common_data.pos.z)) < 800: data.vel.z = 0 # drop on target elif (common_data.pos.z < 80) and (data.vel.z < 3): data.vel.z += 2 # otherwise flap common_data.entity.graphics.startAnim( data=common_data.entity.graphics_data) data.cooldown = 0.2 if common_data.pos.z > 0: friction(data.vel, 0.01) else: friction(data.vel, 0.1) basic_gravity(data.vel) basic_physics(common_data.pos, data.vel) restrictToArena(common_data.pos, data.vel)
def update(self, data, common_data, dt): if data.game_pad.actions[eActions.left]: self.updateState(data, common_data, DuckStates.swimLeft) data.faceleft = True data.vel.x = -DuckController.speed elif data.game_pad.actions[eActions.right]: self.updateState(data, common_data, DuckStates.swimRight) data.faceleft = False data.vel.x = DuckController.speed if data.game_pad.actions[eActions.up]: data.vel.z = DuckController.speed elif data.game_pad.actions[eActions.down]: data.vel.z = -DuckController.speed basic_physics(common_data.pos, data.vel) friction(data.vel)
def update(self, data, common_data, dt): speed = 0.3 # if doing something that can't be interrupted then countdown to end of it if self.coolDown(data, dt): pass else: if data.health <= 0: self.setState(data, common_data, eStates.dead) return if rand_num(10) == 0: self.setState(data, common_data, eStates.stationary) data.vel = Vec3(0, 0, 0) data.cooldown = rand_num(1) + 2 else: # chase hero target = common_data.game.requestTarget(common_data.pos) if (target.x < common_data.pos.x): self.setState(data, common_data, eStates.runLeft) data.vel = Vec3(-speed, 0, 0) data.facing = eDirections.left else: self.setState(data, common_data, eStates.runRight) data.vel = Vec3(speed, 0, 0) data.facing = eDirections.right if (target.y < common_data.pos.y): data.vel.y = -speed else: data.vel.y = speed data.cooldown = 0.5 basic_physics(common_data.pos, data.vel) restrictToArena(common_data.pos, data.vel) friction(data.vel)
def update(self, data, common_data, dt): fire_cool = 1.4 if self.coolDown(data, dt): if data.fired and (common_data.state not in [ px_entity.eStates.fallLeft, px_entity.eStates.fallRight, px_entity.eStates.dead ]): if data.cooldown < 0.9: self.shoot(data, common_data, data.facingleft) data.fired = False else: if data.health <= 0: self.setState(data, common_data, px_entity.eStates.dead) return # fire at hero if in range target = common_data.game.requestTarget(common_data.pos) data.facingleft = (target.x < common_data.pos.x) if abs(target.x - common_data.pos.x) < 200 and abs( target.z - common_data.pos.z) < 20: self.setState( data, common_data, px_entity.eStates.attackSmallLeft if data.facingleft else px_entity.eStates.attackSmallRight) data.fired = True data.cooldown = fire_cool else: self.setState( data, common_data, px_entity.eStates.standLeft if data.facingleft else px_entity.eStates.standRight) data.cooldown = rand_num(1) + 2 px_controller.friction(data.vel) px_controller.basic_gravity(data.vel) px_controller.basic_physics(common_data.pos, data.vel) background.restrictToArena(common_data.pos, data.vel)
def update(self, data, common_data, dt): data.facing = eDirections.left if data.vel.x < 0 else eDirections.right if common_data.state == eStates.fallLeft or common_data.state == eStates.fallRight: if not self.coolDown(data, dt): self.setState(data, common_data, eStates.dead) px_controller.friction(data.vel, 0.1) elif common_data.pos.y > 0: px_controller.friction(data.vel, 0.01) else: self.setState( data, common_data, eStates.fallLeft if data.facing == eDirections.left else eStates.fallRight) data.cooldown = 1 px_controller.friction(data.vel, 0.1) px_controller.basic_gravity(data.vel) px_controller.basic_physics(common_data.pos, data.vel) background.restrictToArena(common_data.pos, data.vel)