def updateControls(self, td): if inputs.getFirePress(): self.anim_state = ANIM_SHOOT if self.facing == LEFT: self.obj_mgr.create("PlayerLaser", None, self.x - 47, self.y + 6, direction=self.facing) self.sprite.play("shoot_l") else: self.obj_mgr.create("PlayerLaser", None, self.x + 47, self.y + 6, direction=self.facing) self.sprite.play("shoot_r") if self.solidcollider.on_ground: self.physics.applyForce(inputs.getHorizontal() * self.run_accel * td, 0) if inputs.getJumpPress(): self.physics.jump(self.jump_speed) self.jump_timer = self.max_jump_timer+td if inputs.getInteractPress(): for obj in self.collider.iter_collide(self.obj_mgr.interactive): if obj.call("interact", self) == True: break else: if inputs.getHorizontal() < 0.0 and self.physics.vx > -self.max_air_speed or inputs.getHorizontal() > 0.0 and self.physics.vx < self.max_air_speed: self.physics.applyForce(inputs.getHorizontal() * self.air_accel * td, 0) self.jump_timer -= td if inputs.getJump() and self.jump_timer >= 0.0: self.physics.applyForce(0, self.jump_thrust * td)
def update(self, td): if self.mapcollide.on_ground: self.physics.applyForce(inputs.getHorizontal() * 0.004 * td, 0) if self.running == False: if inputs.getHorizontal() < -0.01: self.running = True self.dir = 0 self.sprite.play("run_l") if inputs.getHorizontal() > 0.01: self.running = True self.dir = 1 self.sprite.play("run_r") else: if abs(inputs.getHorizontal()) < 0.01: self.running = False if self.dir == 0: self.sprite.play("stand_l") else: self.sprite.play("stand_r") if inputs.getJumpPress(): self.physics.jump(-0.45) self.running = False self.sprite.updateAnim(td) self.physics.update(td)
def update(self, td): """Update the UI""" v = inputs.getVerticalPress() if v < -0.01: # Go to previous interactive widget self.selected = (self.selected - 1) % len(self.widgets) while not self.widgets[self.selected].interactive: self.selected = (self.selected - 1) % len(self.widgets) if v > 0.01: # Go to next interactive widget self.selected = (self.selected + 1) % len(self.widgets) while not self.widgets[self.selected].interactive: self.selected = (self.selected + 1) % len(self.widgets) # If the player presses a button, interact with the current widget if inputs.getFirePress() or inputs.getJumpPress() or inputs.getPausePress(): self.widgets[self.selected].interact() # Update widgets for widget in self.widgets: widget.update(td)
def updateControls(self, td): if inputs.getFirePress(): self.anim_state = ANIM_SHOOT if self.facing == LEFT: self.obj_mgr.create("PlayerLaser", None, self.x - 10, self.y + 4, direction=self.facing) self.sprite.play("shoot_l") else: self.obj_mgr.create("PlayerLaser", None, self.x + 10, self.y + 4, direction=self.facing) self.sprite.play("shoot_r") if self.mapcollide.on_ground: self.physics.applyForce(inputs.getHorizontal() * self.run_accel * td, 0) if inputs.getJumpPress(): self.physics.jump(self.jump_speed) self.jump_timer = self.max_jump_timer+td else: if inputs.getHorizontal() < 0.0 and self.physics.vx > -self.max_air_speed or inputs.getHorizontal() > 0.0 and self.physics.vx < self.max_air_speed: self.physics.applyForce(inputs.getHorizontal() * self.air_accel * td, 0) self.jump_timer -= td if inputs.getJump() and self.jump_timer >= 0.0: self.physics.applyForce(0, self.jump_thrust * td)