def move(self, up, down, left, right, button1, button2): if up and down: up = down = False if left and right: left = right = False direction = get_direction(up, down, left, right) moving = self.directions & (1 << direction) != 0 if not any((up, down, left, right)) or self.bouncing or not moving: self.set_speed( self.speed - (self.deceleration * self.player.multiplier)) direction = self.lastDirection else: self.set_speed(min(self.maxSpeed, self.speed + (self.acceleration * self.player.multiplier))) self.lastDirection = direction if direction == None: return self.set_direction(direction) if not self.stopped: x_speed = self.x_speed y_speed = self.y_speed if self.bouncing: x_speed = -x_speed y_speed = -y_speed move = self.get_move() collidedX, collidedY = self.move_object(x_speed * move, y_speed * move) if (collidedX or collidedY) and not self.bouncing: self.set_speed(0) if self.stopped and self.bouncing: self.bouncing = False
def move(self, up, down, left, right, button1, button2): if up and down: up = down = False if left and right: left = right = False direction = get_direction(up, down, left, right) moving = self.directions & (1 << direction) != 0 if not any((up, down, left, right)) or self.bouncing or not moving: self.set_speed(self.speed - (self.deceleration * self.player.multiplier)) direction = self.lastDirection else: self.set_speed( min(self.maxSpeed, self.speed + (self.acceleration * self.player.multiplier))) self.lastDirection = direction if direction == None: return self.set_direction(direction) if not self.stopped: x_speed = self.x_speed y_speed = self.y_speed if self.bouncing: x_speed = -x_speed y_speed = -y_speed move = self.get_move() collidedX, collidedY = self.move_object(x_speed * move, y_speed * move) if (collidedX or collidedY) and not self.bouncing: self.set_speed(0) if self.stopped and self.bouncing: self.bouncing = False
def move(self, up, down, left, right, button1, button2): self.handle_collisions() parent = self.parent if self.firstMove: if self.test_below(10): while 1: if self.test_below(1): break parent.set_position(parent.x, parent.y + 1) self.standing = True self.firstMove = False climbing = self.climbing if left and right: right = False if up and down: down = False if any((left, right)) or (climbing and (up or down)): self.set_speed( min(self.maxSpeed, self.speed + self.acceleration * self.player.multiplier)) if climbing: direction = self.lastDirection = get_direction( up, down, left, right) else: direction = self.lastDirection = get_direction( False, False, left, right) else: self.set_speed(self.speed - self.deceleration * self.player.multiplier) if self.direction != self.lastDirection: direction = self.lastDirection = self.direction else: direction = self.lastDirection self.set_direction(direction) objectPlayer = parent.objectPlayer y2 = parent.y2 x = parent.x ladder_at = parent.layer.ladder_at ySpeed = self.y_speed if (climbing and not ladder_at(x, y2 - 1) and not ladder_at(parent.x, y2 - 4)): if ySpeed < 0 and ladder_at(x, y2): ySpeed = 0 else: self.climbing = climbing = False self.set_fall() elif (not climbing and self.gravity >= 0 and (up or down or not self.standing)): value = 0 if up: value = -4 elif down: value = 4 if ladder_at(x, y2 + value): self.climbing = climbing = True self.gravity = 0 self.set_climb() move = self.get_move() platformUnder = False if climbing: addY = ySpeed * move else: self.gravity = min( 250, self.gravity + self.gravityAcceleration * self.player.multiplier) self.firstMove = True if self.gravity >= 0 and self.standing and self.test_below(10): platformUnder = True addY = 0 else: addY = self.get_pixels(self.gravity) * self.player.multiplier self.firstMove = False self.checkingPlatform = True collidedX, collidedY = self.move_object(self.x_speed * move, addY) if self.lastInstance is True: self.lastInstance = None collidedX = False collidedY = True self.checkingPlatform = False if collidedX: self.set_speed(0) if platformUnder: self.firstMove = True for _ in xrange(10): if self.test_below(1): break parent.set_position(parent.x, parent.y + 1) else: parent.set_position(parent.x, parent.y - 10) platformUnder = False self.firstMove = False if not platformUnder: self.standing = not self.climbing and self.gravity >= 0 and collidedY if self.standing: self.gravity = 0 if down and not self.crouching: self.crouching = True self.set_crouch() elif not down and self.crouching: self.crouching = False self.set_uncrouch() elif not self.crouching: self.set_walk() elif not self.climbing and self.gravity > 0: self.set_fall() if not self.crouching and (self.standing or self.climbing) and self.is_down_index(4): self.climbing = False self.gravity = -self.jumpStrength self.set_jump()