'This function is called when Mario is in a walking state
It changes the frame, checks for holding down the run button,
checks for a jump, then adjusts the state if necessary'

def walking(self, keys, fire_group):

    self.check_to_allow_jump(keys)
    self.check_to_allow_fireball(keys)
    if (self.frame_index == 0):
        self.frame_index += 1
        self.walking_timer = self.current_time
    elif ((self.current_time - self.walking_timer) > self.calculate_animation_speed()):
        if (self.frame_index < 3):
            self.frame_index += 1
        else:
            self.frame_index = 1
        self.walking_timer = self.current_time
    if keys[tools.keybinding['action']]:
        self.max_x_vel = c.MAX_RUN_SPEED
        self.x_accel = c.RUN_ACCEL
        if (self.fire and self.allow_fireball):
            self.shoot_fireball(fire_group)
    else:
        self.max_x_vel = c.MAX_WALK_SPEED
        self.x_accel = c.WALK_ACCEL
    if keys[tools.keybinding['jump']]:
        if self.allow_jump:
            if self.big:
                setup.SFX['big_jump'].play()
            else:
                setup.SFX['small_jump'].play()
            self.state = c.JUMP
            if ((self.x_vel > 4.5) or (self.x_vel < (-4.5))):
                self.y_vel = (c.JUMP_VEL - 0.5)
            else:
                self.y_vel = c.JUMP_VEL
    if keys[tools.keybinding['left']]:
        self.get_out_of_crouch()
        self.facing_right = False
        if (self.x_vel > 0):
            self.frame_index = 5
            self.x_accel = c.SMALL_TURNAROUND
        else:
            self.x_accel = c.WALK_ACCEL
        if (self.x_vel > (self.max_x_vel * (-1))):
            self.x_vel -= self.x_accel
            if (self.x_vel > (-0.5)):
                self.x_vel = (-0.5)
        elif (self.x_vel < (self.max_x_vel * (-1))):
            self.x_vel += self.x_accel
    elif keys[tools.keybinding['right']]:
        self.get_out_of_crouch()
        self.facing_right = True
        if (self.x_vel < 0):
            self.frame_index = 5
            self.x_accel = c.SMALL_TURNAROUND
        else:
            self.x_accel = c.WALK_ACCEL
        if (self.x_vel < self.max_x_vel):
            self.x_vel += self.x_accel
            if (self.x_vel < 0.5):
                self.x_vel = 0.5
        elif (self.x_vel > self.max_x_vel):
            self.x_vel -= self.x_accel
    elif self.facing_right:
        if (self.x_vel > 0):
            self.x_vel -= self.x_accel
        else:
            self.x_vel = 0
            self.state = c.STAND
    elif (self.x_vel < 0):
        self.x_vel += self.x_accel
    else:
        self.x_vel = 0
        self.state = c.STAND
